beatific: fix prompt path shortening
This commit is contained in:
parent
bf5170c67f
commit
652d8d0805
|
@ -1,19 +1,24 @@
|
|||
# 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}"
|
||||
else
|
||||
echo $PWD
|
||||
fi
|
||||
}
|
||||
# Shorten path dir names
|
||||
# Shorten $HOME to ~ in PWD and shorten other path dir names to one letter
|
||||
_pwd() {
|
||||
DIR=$(_pwd_home)
|
||||
[ "$DIR" != "/" ] && [ "$DIR" != "~" ] && printf '%s/' $(dirname "$DIR" | tr / '\n' | cut -c-1)
|
||||
printf "$(basename "$DIR")"
|
||||
if [[ "$PWD" =~ ^"$HOME"($) ]]; then
|
||||
printf "~"
|
||||
elif [[ "$PWD" = "/" ]]; then
|
||||
printf "/"
|
||||
else
|
||||
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
|
||||
}
|
||||
_DIR='$(_pwd)'
|
||||
# Color codes
|
||||
|
|
Loading…
Reference in New Issue