powerline-shell
powerline-shell copied to clipboard
Shorten git branch name display
Any straightforward way to concat the git branch name? Maybe just display the branch #?
this would be great, to show shorter names of the branches...
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]