Skip to content

Latest commit

 

History

27 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

omz-git-branch

Oh-My-Zsh plugin that shortens the current branch name in your prompt. It replaces oh-my-zsh's git_prompt_info, so any theme calling that function picks it up with no theme edit. Aimed at branch names carrying a team prefix and a ticket id, where the prefix is noise and the id must survive.

Example

With prefix-regex set to [^-]*- and suffix-length set to 8:

abc-custom-feature-xyz-12345678       -->  custom-fe...12345678
user123/repo-9876/fix-bug-in-feature  -->  9876/fix-...-feature
feature/add-billing-webhooks          -->  billing-webhooks
main                                  -->  main

Install

sh -c "$(curl -fsSL https://raw.githubusercontent.com/cpwillis/omz-git-branch/main/install.sh)"

The script clones into ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/omz-git-branch and inserts omz-git-branch into the plugins=(...) list in ~/.zshrc. By hand:

git clone https://github.com/cpwillis/omz-git-branch.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/omz-git-branch

then add omz-git-branch to plugins=(...) yourself. Either way, restart the shell.

Update

omz update does not touch custom plugins, so pull it:

git -C ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/omz-git-branch pull && exec zsh

Without exec zsh the old function stays defined until you open a new terminal.

Config

Settings are git config keys under oh-my-zsh., so the usual scopes apply: set them --global, override per repo. Trimming runs only when the name exceeds max-branch-length, in this order: prefix-regex, prefix-length, then truncation that keeps suffix-length characters from the end. A suffix-length above max-branch-length - 3 leaves the result a character or two over the limit.

Key Default Effect
max-branch-length 20 Trim above this; the result is this long, ... included.
prefix-regex unset First match removed. POSIX BRE via sed: lazy quantifiers (.*?) silently match nothing.
prefix-length 0 Removes n leading characters. Applied after prefix-regex.
suffix-length 0 Keeps n trailing characters.
hide-status unset 1 suppresses the branch display entirely.
git config --global oh-my-zsh.prefix-regex '[^-]*-'
git config --global oh-my-zsh.suffix-length 8

Development

zsh test.zsh

Builds a throwaway repo and ignores your own git config, so it is safe to run anywhere. git_prompt_info runs on every prompt: prefer zsh parameter expansion over shelling out to cut, expr or sed, the subprocesses dominate the cost.

About

A concise Git branch display plugin for Oh-My-Zsh.

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages