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,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}"
# 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