我试着调整一下
当我在命令行输入git status时,我得到一个需要解析的文件列表,如下所示:
# Unmerged paths: # # (use "git reset HEAD..." to unstage) # (use "git add ..." to mark resolution) # # both modified: apache2/templates/default/apache2.conf.erb # both modified: bootstrap/attributes/default.rb # both modified: iptables/metadata.rb # both modified: kickstart/templates/default/ks.cfg.erb # both modified: openssl/metadata.json # both modified: postfix/metadata.json # both modified: postfix/templates/default/main.cf.erb
有没有一种简单的方法可以将这个文件路径列表传递到文本编辑器中,因此您可以一次编辑它们?
我可以通过简单地通过grep管道来达到这个目的:
[17:37]:git status | grep "both modified" # both modified: apache2/templates/default/apache2.conf.erb # both modified: bootstrap/attributes/default.rb # both modified: iptables/metadata.rb # both modified: kickstart/templates/default/ks.cfg.erb # both modified: openssl/metadata.json # both modified: postfix/metadata.json # both modified: postfix/templates/default/main.cf.erb
但是我不确定如何使用shell命令返回它,或者是否最简单的方法是放入ruby或python,通过正则表达式传递每一行,以过滤掉# both modified:
.
我想要的最终结果是这样的:
vim #{space_separated_list_of_files}
你们这样做怎么样?
这是我在gitconfig中的一对别名,取自git wiki:
edit-unmerged = \ "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; vim `f`" add-unmerged = \ "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"
应该做你想要的!