short cwd in bash prompt

This commit is contained in:
Daniel Flanagan 2016-03-03 13:09:37 -06:00
parent c2c0b63a5e
commit 87fa984e25

View file

@ -59,6 +59,14 @@ COLOR_RESET='\[\e[0m\]'
PROMPT_SUCCESS_COLOR='\[\e[0;34m\]'
PROMPT_FAILURE_COLOR='\[\e[0;31m\]'
DIR_COLOR='\[\e[0;33m\]'
sps() {
name="$PWD"
[[ "$name" =~ ^"$HOME"(/|$) ]] && name="~${name#$HOME}"
curdir=$(echo "$PWD" | sed -r 's|.*/(.+)$|\1|g')
name=$(echo "$name" | sed -r 's|/(..)[^/]*|/\1|g' | sed -r 's|(.*/)(.+)$|\1|g')
[[ "$name" == "~" ]] && curdir=""
echo "$name$curdir"
}
prompt_command_func()
{
RET=$?
@ -67,7 +75,7 @@ prompt_command_func()
else
STATUS_COLOR=$PROMPT_FAILURE_COLOR
fi;
PS1="$STATUS_COLOR\u@\h$COLOR_RESET $DIR_COLOR\w$COLOR_RESET "
PS1="$STATUS_COLOR\u@\h$COLOR_RESET $DIR_COLOR$(eval "sps")$COLOR_RESET "
}
export PROMPT_COMMAND="prompt_command_func"