__set-title () { local title local path=$(git root 2> /dev/null) if [ ${path} ] then title=$(basename ${path}) else title="${USER}:${PWD/~/\~}" fi echo -ne "\033]2;${title}\007" } __start-nonprinting () { if [ ${BUILDING_PS1} ] then echo -en '\[' fi } __end-nonprinting () { if [ ${BUILDING_PS1} ] then echo -en '\]' fi } __fontify () { local -A codes codes[red]='31' codes[green]='32' codes[blue]='34' codes[white]='37' codes[bold]='1' codes[dim]='2' codes[clear]='0' local text=$1 shift # We need to add \[ \] around CSI sequences so that Bash can tell which # characters are non-printing. output=$(__start-nonprinting) output+='\033[' local attributes=($@) for ((i=0; i<$#; i++)) do a=${attributes[${i}]} output+=${codes[${a}]} if ((i<$#-1)) then output+=';' else output+='m' fi done output+=$(__end-nonprinting) output+="${text}" output+=$(__start-nonprinting) output+='\033[0m' output+=$(__end-nonprinting) echo -en "${output}" } __set-prompt () { BUILDING_PS1=t local last_status=$1 PS1='' if [ ${last_status} -ne 0 ] then PS1+=$(__fontify "${last_status} " bold red) fi PS1+=$(__fontify '\u' green) PS1+=$(__fontify : bold white) PS1+=$(__fontify '\w' bold blue) PS1+=$(__fontify "$(__git_ps1 '(%s)')" red) PS1+=$(__fontify '\$' bold white) PS1+=' ' BUILDING_PS1= } __draw-rule () { rule='' for ((i=0; i