1
1
Fork 0

beatific: fix prompt path shortening

This commit is contained in:
Tim Van Baak 2024-04-16 15:39:26 +00:00
parent bf5170c67f
commit 652d8d0805
1 changed files with 16 additions and 11 deletions

View File

@ -1,20 +1,25 @@
# Set the title bar to user@host: pwd # Set the title bar to user@host: pwd
_TITLE_BAR="\u@\h: \w" _TITLE_BAR="\u@\h: \w"
_SET_TITLE_BAR="\[\e]0;$_TITLE_BAR\a\]" _SET_TITLE_BAR="\[\e]0;$_TITLE_BAR\a\]"
# Shorten $HOME to ~ in PWD # Shorten $HOME to ~ in PWD and shorten other path dir names to one letter
_pwd_home () { _pwd() {
if [[ "$PWD" =~ ^"$HOME"(/|$) ]]; then if [[ "$PWD" =~ ^"$HOME"($) ]]; then
echo "~${PWD#$HOME}" printf "~"
elif [[ "$PWD" = "/" ]]; then
printf "/"
else 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 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)' _DIR='$(_pwd)'
# Color codes # Color codes
_GREEN="\[\033[32;1m\]" _GREEN="\[\033[32;1m\]"