我想的git status --short --branch
輸出進行排序,以便:如何對速記git狀態的輸出進行排序?
- 文件中的指標在底部
- 文件出現修改工作樹,但不是在指數出現上面
- 頂部未修改的更改
如果這需要通過管道連接到某些其他命令來對輸出中的行進行排序,那麼最好保留由Git配置的輸出顏色。
是否有一些聰明的別名,我可以創建這將爲我做這個?注意我在Windows上使用Git(如果有的話)。
我想的git status --short --branch
輸出進行排序,以便:如何對速記git狀態的輸出進行排序?
如果這需要通過管道連接到某些其他命令來對輸出中的行進行排序,那麼最好保留由Git配置的輸出顏色。
是否有一些聰明的別名,我可以創建這將爲我做這個?注意我在Windows上使用Git(如果有的話)。
你可以告訴git生成顏色代碼,但要按自定義順序排序,你必須編寫腳本。這裏是一個簡短的Python的例子,你可以管從git -c color.ui=always status --short --branch
:
#!/bin/env python
import sys, re
# custom sorting order defined here:
order = { 'A ' : 1, ' M' : 3, '??' : 2, '##' : 0 }
ansi_re = re.compile(r'\x1b[^m]*m')
print ''.join(sorted(
sys.stdin.readlines(),
cmp=lambda x,y: cmp(
order.get(ansi_re.sub('', x)[0:2],0),
order.get(ansi_re.sub('', y)[0:2],0))))
或者一個班輪憎惡
git -c color.ui=always status --short --branch | python -c 'import sys, re; \
order = {"A ":1," M":3,"??":2,"##":0}; ansi_re = re.compile(r"\x1b[^m]*m");\
print "".join(sorted(sys.stdin.readlines(),cmp=lambda x,y: \
cmp(order.get(ansi_re.sub("", x)[0:2],0), order.get(ansi_re.sub("", y)[0:2],0))))'
簡短說明。
- Python腳本讀取標準輸入,這是git的狀態的着色列表輸出,以及剝離ANSI顏色代碼後,前兩個狀態字符相對於比較到自定義優先用於在定義的每個狀態字典。
的ANSI顏色代碼的清除是基於:在How can I remove the ANSI escape sequences from a string in python
而不同的狀態代碼的完整列表可在git status幫助頁面中找到。
tail -r
可以用來扭轉git status
輸出,但不會保留色,顯然on Linux there is no -r
option, so you have to use tac
instead:
git status --short --branch | tail -r
有問題我與其他反向招數,所以它可能是值得也檢查其他選項(以獲取顏色輸出)。