2020-01-01 20:19:35 -06:00
|
|
|
# requires the following utilities:
|
|
|
|
# git
|
|
|
|
# GNU coreutils (for realpath)
|
|
|
|
# BSD basename
|
|
|
|
|
2016-01-19 15:10:51 -06:00
|
|
|
prompt_command() {
|
2020-01-01 20:19:35 -06:00
|
|
|
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\]"
|
2016-01-19 15:10:51 -06:00
|
|
|
|
|
|
|
if [[ $retval != 0 ]]; then
|
|
|
|
numcolor="\[\e[1;41;33m\]"
|
|
|
|
fi
|
|
|
|
|
2020-01-01 20:19:35 -06:00
|
|
|
# If we're in a git repo
|
2016-01-19 15:10:51 -06:00
|
|
|
if git branch &>/dev/null; then
|
2020-01-01 20:19:35 -06:00
|
|
|
|
|
|
|
local repoDir=`git rev-parse --show-toplevel`
|
2016-01-19 15:24:54 -06:00
|
|
|
branch="$green$(git branch 2>/dev/null | grep \* | cut -d ' ' -f 2-)"
|
2016-01-19 15:10:51 -06:00
|
|
|
clean=$(git status | grep clean)
|
2020-01-01 20:19:35 -06:00
|
|
|
# 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"
|
2016-01-19 15:10:51 -06:00
|
|
|
fi
|
|
|
|
|
2020-01-01 20:19:35 -06:00
|
|
|
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
|
2016-01-19 15:10:51 -06:00
|
|
|
|
2020-01-01 20:19:35 -06:00
|
|
|
PS1+="$green\$${default} "
|
|
|
|
|
|
|
|
# PS1="$numcolor\!$red \u$sepcolor@${brightblue}\h${default}:${branch}${clean} $default\w$green\$${default} "
|
2016-01-19 15:10:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
PROMPT_COMMAND=prompt_command
|
|
|
|
|
|
|
|
eval "$(thefuck --alias fixit)"
|
|
|
|
set -o vi
|
2020-01-01 20:19:35 -06:00
|
|
|
|
|
|
|
source ~/.bash_aliases
|