-
-
Save nicwolff/2925803 to your computer and use it in GitHub Desktop.
# 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" |
Good working solution, Thanks for it!
Just two remarks:
- created file needs to have proper rights (chmod 755), otherwise it will not work
- for colors I find easier to use aliases. see https://www.cs.umd.edu/~srhuang/teaching/code_snippets/prompt_color.tcsh.html
so this is my version so far:
echo "colors"
set red="%{\033[1;31m%}"
set green="%{\033[0;32m%}"
set yellow="%{\033[1;33m%}"
set blue="%{\033[1;34m%}"
set magenta="%{\033[1;35m%}"
set cyan="%{\033[1;36m%}"
set white="%{\033[0;37m%}"
set end="%{\033[0m%}" # This is needed at the end...
setenv GIT_BRANCH_CMD "sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* (.*)/(\1) /'"
set prompt="${green}%n@%m:${yellow}%~${cyan} $GIT_BRANCH_CMD
%B\n${white}%#%b${end}"
echo "cleaning"
unset red green yellow blue magenta cyan yellow white end
Its much cleaner if you use git branch --show-current
, no need for the parsing, this will also work with multiple git worktrees.
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.
LOVE this!
I modify it like this, with lots of colors and a simplified sed:
setenv GIT_BRANCH_CMD "sh -c 'git rev-parse --abbrev-ref HEAD 2> /dev/null' | sed -e 's/(.*)/(\1) /'"
set prompt="%{\033[34m%}%n@%B%m%b %B%{\033[31m%}%~%b %{\033[36m%}
$GIT_BRANCH_CMD
%{\033[39m%}%h ) "