shell: refactoring _patch