Skip to content

Instantly share code, notes, and snippets.

@rhythmize
Last active July 26, 2024 15:43
Show Gist options
  • Save rhythmize/2e64046068512293bcfca929ff6fd740 to your computer and use it in GitHub Desktop.
Save rhythmize/2e64046068512293bcfca929ff6fd740 to your computer and use it in GitHub Desktop.
Linux bash tricks

Shorten cwd in bash and show git branch, if cwd is git repo

parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

PS1='\[\033[01;34m\]\W\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment