Skip to content

Instantly share code, notes, and snippets.

@nicwolff
Created June 13, 2012 19:00
Show Gist options
  • Save nicwolff/2925803 to your computer and use it in GitHub Desktop.
Save nicwolff/2925803 to your computer and use it in GitHub Desktop.
'tcsh' Git prompt to show current branch
# in ~/bin/gitprompt.csh:
setenv GIT_BRANCH_CMD "sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'"
set prompt="%m:%~ `$GIT_BRANCH_CMD`%B%#%b "
# and then in ~/.cshrc:
alias precmd "source ~/bin/gitprompt.csh"
@jonassvedas
Copy link

jonassvedas commented Feb 24, 2020

Its much cleaner if you use git branch --show-current, no need for the parsing, this will also work with multiple git worktrees.

@dapimentel
Copy link

Its much cleaner if you use git branch --show-current, no need for the parsing, this will also work with multiple git worktrees.

Be aware that git branch --show-current only works for git version 2.22 or later. This may be useful to know in some slow-moving corporate environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment