您可以告诉 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))))
Or a one-liner abomination:
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))))'