# requires the following utilities: # git # GNU coreutils (for realpath) # BSD basename prompt_command() { local retval=$? local branch=""; local clean=""; local workingDir=""; local numcolor="\[\e[0;33m\]" local red="\[\e[0;31m\]" local sepcolor="\[\e[1;30m\]" local yellow="\[\e[0;33m\]" local brightyellow="\[\e[1;33m\]" local brightblue="\[\e[1;34m\]" local default="\[\e[0m\]" local green="\[\e[0;32m\]" if [[ $retval != 0 ]]; then numcolor="\[\e[1;41;33m\]" fi # If we're in a git repo if git branch &>/dev/null; then local repoDir=`git rev-parse --show-toplevel` branch="$green$(git branch 2>/dev/null | grep \* | cut -d ' ' -f 2-)" clean=$(git status | grep clean) # if [ -z "$clean" ]; then clean="${red}✗"; else clean=""; fi if [ -z "$clean" ]; then clean="${red}++"; else clean=""; fi workingDir="$(basename ${repoDir})/" workingDir+=`realpath "--relative-to=${repoDir}" "$(pwd)"` else workingDir=`pwd` fi PS1="$numcolor\!$red \u$sepcolor@${brightblue}\h${default}:${branch}${clean} " # Add a linebreak if the branchname + working dir will make the line # overly long # echo "Branch and working dir length is $(expr ${#branch} + ${#workingDir})" # echo "COLUMNS is $COLUMNS. COLUMNS / 3 is $(expr $COLUMNS / 3)" if (( $(expr ${#branch} + ${#workingDir}) > $(expr $COLUMNS / 3) )); then PS1="\r\n${PS1}\r\n" fi PS1+="$default$workingDir" # If the working dir is itself too long, put it on it's own line and put # the prompt below it. if (( ${#workingDir} > $(expr $COLUMNS / 3) )); then PS1+="\r\n"; fi PS1+="$green\$${default} " # PS1="$numcolor\!$red \u$sepcolor@${brightblue}\h${default}:${branch}${clean} $default\w$green\$${default} " } PROMPT_COMMAND=prompt_command eval "$(thefuck --alias fixit)" set -o vi source ~/.bash_aliases