I have been working to make my own git-bash prompt. However, when loading up my prompt (set in ~/.bashrc), and after every subsequent command, it takes just a bit more than a half of a second so my input sometimes isn't registered/"spill over" when typing mutliple commands quickly. Obligatory pardon the code; I just want it all down and there before I clean up stupid ways of doing things. This is part of the function that shows the prompt, promptFunc: (git branch and #commits ahead/behind, the code doesn't really matter, just if it is the reason why it takes a while to load; if you find a better way to show this with just the numbers and up/down arrows, let me know, I am a bash noob).
local branch=`git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3-`
if [ $branch ]; then
status=`git status -sb`
read ahead behind <<<${status//[^0-9]/ }
if [ ! -z "$ahead" ] && [ -z "$behind" ] && [[ $status == *"behind"* ]]; then
behind="$ahead"
ahead=""
fi
if [ ! -z "$ahead" ]; then ahead="↑$ahead"; fi
if [ ! -z "$behind" ]; then behind="↓$behind"; fi
git_branch="\[\033[1;36m\]git:(\[\033[0;35m\]$branch$ahead$behind\[\033[1;36m\])"
fi
The function is called, and PS1 is set to *stuff*"$git_branch"
to access the output of this excerpt; then, export PROMPT_COMMAND="promptFunc"
. If my prompt is simply not reappearing because of the "complexity", excuse the noob mistake.
As a precaution, the same is used to show virtualenv and executed in promptFunc
:
if [ ! -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
VIRT_ENV_TXT=""
if [ "$VIRTUAL_ENV" != "" ]; then
VIRT_ENV_TXT="`basename \"$VIRTUAL_ENV\"`"
elif [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
VIRT_ENV_TXT="[`basename \`dirname \"$VIRTUAL_ENV\"\``]"
fi
fi
if [ "${VIRT_ENV_TXT}" != "" ]; then
venv="\[\033[1;36m\]""virtualenv:(\[\033[0;35m\]"${VIRT_ENV_TXT}"\[\033[1;36m\]) "
fi
Any advice on how to speed things up or do things easier would be appreciated; will add clarification if needed.
Explicit PS1 Declaration; $ruby
is the rvm:
PS1='\[\033]0;$TITLEPREFIX$PWD\007\]\n\[\033[33m\]\w\n\[\033[32m\]\u\[\033[38;5;253m\]@\[\033[1;34m\]9570'
PS1="$PS1$ruby$venv$git_branch\[\033[0m\]""\n""$ "