git for-each-ref with a coloured format string

后端 未结 2 2057
情深已故
情深已故 2021-02-14 02:54

I\'m using git for-each-ref as a git alias to display a branch name and the subject of the last commit on that branch. That said, it\'s hard to tell where the branc

2条回答
  •  深忆病人
    2021-02-14 03:50

    Git 1.9/2.0 (Q1 2014) will introduce color formatting for git for-each-ref.
    See commit fddb74c from Ramkumar Ramachandra (artagnon):

    for-each-ref: introduce %(color:...) for color

    Enhance 'git for-each-ref' with color formatting options.
    You can now use the following format in for-each-ref:

    %(color:green)%(refname:short)%(color:reset)
    

    where color names are described in color.branch.*.


    With Git 2.15 (Q4 2017), you will be able to turn those colors on or off.

    See commit 0c88bf5 (03 Oct 2017) by Jeff King (peff).
    (Merged 04 Oct 2017)

    provide --color option for all ref-filter users

    When ref-filter learned about want_color() in 11b087a (ref-filter: consult want_color() before emitting colors, 2017-07-13), it became useful to be able to turn colors off and on for specific commands. For git-branch, you can do so with --color/--no-color.

    But for git-for-each-ref and git-tag, the other users of ref-filter, you have no option except to tweak the "color.ui" config setting. Let's give both of these commands the usual color command-line options.

    This is a bit more obvious as a method for overriding the config. And it also prepares us for the behavior of "always" changing (so that we are still left with a way of forcing color when our output goes to a non-terminal).

提交回复
热议问题