powerline-shell icon indicating copy to clipboard operation
powerline-shell copied to clipboard

Shorten git branch name display

Open le91688 opened this issue 6 years ago • 2 comments

Any straightforward way to concat the git branch name? Maybe just display the branch #?

le91688 avatar Nov 12 '18 14:11 le91688

this would be great, to show shorter names of the branches...

jgato avatar Oct 10 '19 15:10 jgato

Sure. You can edit the .../powerline_shell/segments/git.py file directly or make a custom segment that alters the build_stats() function. Edit the code so that it looks like the following. The first addition changes "master" to "M". The second addition truncates the branch name to a set length.

    if branch_info:
        stats.ahead = branch_info["ahead"]
        stats.behind = branch_info["behind"]
        branch = branch_info['local']
        # Shortens master branch to M.
        if branch == "master":     
             branch = "M"
    else:
        branch = _get_git_detached_branch()
    
    # Truncate branch name
    branch_name_max_length = 8
    if branch:
        if len(branch) > branch_name_max_length :
            branch = branch[:branch_name_max_length]

shervinsahba avatar Oct 29 '19 02:10 shervinsahba