mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
50 lines
1.1 KiB
Bash
50 lines
1.1 KiB
Bash
__truncate_left() {
|
|
local str="$1"
|
|
local maxlen="$2"
|
|
local trunc_symbol="$3"
|
|
local sep_symbol="$4"
|
|
|
|
# get minimum length to not truncate a long name
|
|
if [ -n "$sep_symbol" ]
|
|
then
|
|
local component=${1##*$sep_symbol}
|
|
maxlen=$(( ( maxlen < ${#component} ) ? ${#component} : maxlen ))
|
|
fi
|
|
|
|
# truncation point
|
|
local offset=$(( ${#str} - maxlen ))
|
|
|
|
if [ ${offset} -gt "0" ]
|
|
then
|
|
#truncation is needed
|
|
str=${str:$offset:$maxlen} #truncate
|
|
str=${trunc_symbol}/${str#*/} #add symbol
|
|
fi
|
|
echo "$str"
|
|
}
|
|
|
|
__truncate_dir() {
|
|
dir=${1/#$HOME/\~} #gain some place with '~'
|
|
__truncate_left "$dir" 25 '…' '/'
|
|
}
|
|
|
|
__tpwd() {
|
|
__truncate_dir "$PWD"
|
|
}
|
|
|
|
__set_bash_ps1() {
|
|
|
|
# load color vars
|
|
source "$DOTFILES_BASH_DIR/ansi_colors"
|
|
|
|
# colorized:
|
|
PS1=" ${B}[${UC}\u@\h ${G}\$(__tpwd)${B}]${UC}\\$ ${NONE}"
|
|
# without colors:
|
|
#PS1="${TITLEBAR}[\u@\h \${NEW_PWD}]\\$ "
|
|
# extra backslash in front of \$ to make bash colorize the prompt
|
|
}
|
|
|
|
__set_bash_ps1
|
|
unset __set_bash_ps1
|
|
|
|
# vim: ft=sh
|