如何根据Mercurial分支的名称为其着色?
我想通过颜色来区分功能/阶段/发布分支。我有一个分支命名约定 有没有办法根据一些基于regexp的规则给如何根据Mercurial分支的名称为其着色?,mercurial,branch,mercurial-extension,Mercurial,Branch,Mercurial Extension,我想通过颜色来区分功能/阶段/发布分支。我有一个分支命名约定 有没有办法根据一些基于regexp的规则给hg branchs的输出中的分支名称上色 除了编写自定义脚本并为其创建别名之外,还有更好的方法吗 顺便说一下,在上有一个问题和一个很好的答案默认情况下,Mercurial的标准颜色扩展只允许基于分支状态进行着色。例如: [extensions] color= [color] branches.active = none branches.closed = black bold branche
hg branchs
的输出中的分支名称上色
除了编写自定义脚本并为其创建别名之外,还有更好的方法吗
顺便说一下,在上有一个问题和一个很好的答案默认情况下,Mercurial的标准颜色扩展只允许基于分支状态进行着色。例如:
[extensions]
color=
[color]
branches.active = none
branches.closed = black bold
branches.current = green
branches.inactive = none
(摘自hg帮助颜色)
为了基于正则表达式指定颜色,您需要一个脚本和一个别名(为了方便起见)。下面是Ruby,因为Ruby的case语句使通过正则表达式进行选择变得相当容易
class String
def colorize(code) "\033[#{code}m#{self}\033[0m" end
def colorize_bold(code) "\033[#{code};1m#{self}\033[0m" end
def black() colorize(30) end
def red() colorize(31) end
def green() colorize(32) end
def yellow() colorize(33) end
def blue() colorize(34) end
def magenta() colorize(35) end
def cyan() colorize(36) end
def white() colorize(37) end
def gray() colorize_bold(30) end
def bold_red() colorize_bold(31) end
def bold_green() colorize_bold(32) end
def bold_yellow() colorize_bold(33) end
def bold_blue() colorize_bold(34) end
def bold_magenta() colorize_bold(35) end
def bold_cyan() colorize_bold(36) end
def bold_white() colorize_bold(37) end
end
for line in ARGF do
case line
when /^foo/
print line.bold_magenta
when /^bar/
print line.yellow
else
print line.gray
end
end
如果已经安装了colorize
gem,也可以使用它
然后,您可以将其作为别名添加到.hgrc
。例如,如果上述脚本位于/path/to/color branchs.rb
,请执行以下操作:
[alias]
colorbranches = !$HG branches $@ | ruby /path/to/color-branches.rb
默认情况下,Mercurial的标准颜色扩展只允许基于分支状态进行着色。例如:
[extensions]
color=
[color]
branches.active = none
branches.closed = black bold
branches.current = green
branches.inactive = none
(摘自hg帮助颜色)
为了基于正则表达式指定颜色,您需要一个脚本和一个别名(为了方便起见)。下面是Ruby,因为Ruby的case语句使通过正则表达式进行选择变得相当容易
class String
def colorize(code) "\033[#{code}m#{self}\033[0m" end
def colorize_bold(code) "\033[#{code};1m#{self}\033[0m" end
def black() colorize(30) end
def red() colorize(31) end
def green() colorize(32) end
def yellow() colorize(33) end
def blue() colorize(34) end
def magenta() colorize(35) end
def cyan() colorize(36) end
def white() colorize(37) end
def gray() colorize_bold(30) end
def bold_red() colorize_bold(31) end
def bold_green() colorize_bold(32) end
def bold_yellow() colorize_bold(33) end
def bold_blue() colorize_bold(34) end
def bold_magenta() colorize_bold(35) end
def bold_cyan() colorize_bold(36) end
def bold_white() colorize_bold(37) end
end
for line in ARGF do
case line
when /^foo/
print line.bold_magenta
when /^bar/
print line.yellow
else
print line.gray
end
end
如果已经安装了colorize
gem,也可以使用它
然后,您可以将其作为别名添加到.hgrc
。例如,如果上述脚本位于/path/to/color branchs.rb
,请执行以下操作:
[alias]
colorbranches = !$HG branches $@ | ruby /path/to/color-branches.rb