diff --git a/modules/bashrc b/modules/bashrc index 45c58c7..a1cabc0 100644 --- a/modules/bashrc +++ b/modules/bashrc @@ -1,20 +1,25 @@ # Set the title bar to user@host: pwd _TITLE_BAR="\u@\h: \w" _SET_TITLE_BAR="\[\e]0;$_TITLE_BAR\a\]" -# Shorten $HOME to ~ in PWD -_pwd_home () { - if [[ "$PWD" =~ ^"$HOME"(/|$) ]]; then - echo "~${PWD#$HOME}" +# Shorten $HOME to ~ in PWD and shorten other path dir names to one letter +_pwd() { + if [[ "$PWD" =~ ^"$HOME"($) ]]; then + printf "~" + elif [[ "$PWD" = "/" ]]; then + printf "/" else - echo $PWD + if [[ "$PWD" =~ ^"$HOME"/ ]]; then + printf "~" + DIR="${PWD#$HOME}" + else + DIR="$PWD" + fi + for path_elem in $(dirname "$DIR" | tr / '\n' | grep . | cut -c-1); do + printf '/%s' $path_elem + done + printf "/$(basename "$DIR")" fi } -# Shorten path dir names -_pwd () { - DIR=$(_pwd_home) - [ "$DIR" != "/" ] && [ "$DIR" != "~" ] && printf '%s/' $(dirname "$DIR" | tr / '\n' | cut -c-1) - printf "$(basename "$DIR")" -} _DIR='$(_pwd)' # Color codes _GREEN="\[\033[32;1m\]"