Browse Source

updated shellcheck

master
wiebel 2 years ago
parent
commit
804b8546a6
  1. 46
      featuredPS1.sh

46
featuredPS1.sh

@ -2,12 +2,12 @@
## (c) by wiebel (wiebel42@gmail.com) ## (c) by wiebel (wiebel42@gmail.com)
# Function to display the returncode of the previous command if not zero # Function to display the returncode of the previous command if not zero
source /usr/share/git/git-prompt.sh source "/usr/share/git/git-prompt.sh"
ps1_return() { ps1_return() {
if [ "$1" != "0" ]; then if [ "$1" != "0" ]; then
echo -e "$1 " echo -e "$1 "
fi fi
return $1 return "$1"
} }
# Generating the not symlinked part of the Working directory # Generating the not symlinked part of the Working directory
@ -37,7 +37,7 @@ if [ -z "${PWD/${HOME}*}" ]; then
dir=${dir/${HOME}/\~} dir=${dir/${HOME}/\~}
else else
athome=false athome=false
while [ "$PWD" != "/" ]; do while [ "$PWD" != "/" ] && [ "$PWD" != "//" ]; do
# if readlink "$PWD" >/dev/null # if readlink "$PWD" >/dev/null
if [ -L "$PWD" ]; then if [ -L "$PWD" ]; then
sym=true sym=true
@ -53,16 +53,18 @@ fi
if [ ${#dir_komp} -gt "30" ]; then if [ ${#dir_komp} -gt "30" ]; then
if [ $sym ]; then if [ $sym ]; then
if $athome; then if $athome; then
# shellcheck disable=SC2088
dir="~/$(cut -d/ -f2 <<< $dir)/..." dir="~/$(cut -d/ -f2 <<< $dir)/..."
else else
dir="/$(cut -d/ -f2 <<< $dir)/..." dir="/$(cut -d/ -f2 <<< $dir)/..."
fi fi
else else
dir=$(sed -e 's:\(/[^/]*/\).*\(/[^/]\):\1...\2:' <<< $dir) dir="$(sed -e 's:\(/[^/]*/\).*\(/[^/]\):\1...\2:' <<< ${dir})"
# dir="${dir/\(\/[^/]*\/\).*\(\/[^/]\)/\1...\2}"
# dir=${dir/${HOME}/\~} # dir=${dir/${HOME}/\~}
fi fi
fi fi
echo -e $dir echo -e "${dir}"
return $ret return $ret
} }
@ -71,9 +73,9 @@ ps1_pre_color(){
ret=$? ret=$?
#if grep -q $HOME <<<$PWD #if grep -q $HOME <<<$PWD
if [ -z "${PWD/${HOME}*}" ]; then if [ -z "${PWD/${HOME}*}" ]; then
echo -e $HOME_COLOR echo -e "${HOME_COLOR}"
else else
echo -e $ROOT_COLOR echo -e "${ROOT_COLOR}"
fi fi
return $ret return $ret
} }
@ -91,17 +93,17 @@ if [ -z "${PWD/${HOME}*}" ]; then
d_color=$HOME_SYM d_color=$HOME_SYM
fi fi
# Check if we really are where we ought to be (if there is a symlink in the path) # Check if we really are where we ought to be (if there is a symlink in the path)
while [ "$PWD" != "/" ]; do while [ "$PWD" != "/" ] && [ "$PWD" != "//" ]; do
# if readlink "$PWD" >/dev/null # if readlink "$PWD" >/dev/null
if [ -L "$PWD" ]; then if [ -L "$PWD" ]; then
# There is a symlink so now show me you're true color # There is a symlink so now show me you're true color
new_path=$(readlink "$PWD") new_path=$(readlink "$PWD")
cd ../;cd $new_path cd ../ || return 2
# if grep -q ^$HOME <<< $PWD cd "$new_path" || return 2
if [ -z ${PWD/${HOME}*} ]; then if [ -z "${PWD/${HOME}*}" ]; then
d_color=$HOME_SYM d_color=${HOME_SYM}
else else
d_color=$ROOT_SYM d_color=${ROOT_SYM}
fi fi
else else
cd .. cd ..
@ -126,11 +128,11 @@ fi
if [ "$d" = "$PWD" ]; then if [ "$d" = "$PWD" ]; then
dir="" dir=""
elif grep -q "\.\.\.$" <<<"$d"; then elif grep -q "\.\.\.$" <<<"$d"; then
dir=$(sed -e "s:.*\(/[!/]*\):\1:" <<< $PWD) dir="$(sed -e "s:.*\(/[!/]*\):\1:" <<< $PWD)"
elif grep -q "\/\.\.\.\/" <<< "$d"; then elif grep -q "\/\.\.\.\/" <<< "$d"; then
dir="" dir=""
else else
dir=$(sed -e "s/^$(sed -e "s:/:\\\/:g" <<<"$d")//" <<< $PWD) dir="$(sed -e "s/^$(sed -e "s:/:\\\/:g" <<<"$d")//" <<< $PWD)"
fi fi
echo -e "$dir" echo -e "$dir"
@ -158,10 +160,9 @@ fi
return $ret return $ret
} }
#DIR_P='$(ps1_pre)'
# Now to the root or not to root question (slightly modificated from the original profile) # Now to the root or not to root question (slightly modificated from the original profile)
# i've not yet came to it to set all colors to variable so feel free to adjust ;) # i've not yet came to it to set all colors to variable so feel free to adjust ;)
if [ `/usr/bin/whoami` = 'root' ]; then if [ "$(/usr/bin/whoami)" = "root" ]; then
# Do not set PS1 for dumb terminals # Do not set PS1 for dumb terminals
if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ]; then if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ]; then
# like always no username for root for he is red # like always no username for root for he is red
@ -169,10 +170,13 @@ if [ `/usr/bin/whoami` = 'root' ]; then
PS1U='' PS1U=''
PS1H='\[\033[01;31m\]\h' PS1H='\[\033[01;31m\]\h'
# here we enlight if root does own it or not # here we enlight if root does own it or not
# shellcheck disable=SC2016
PS1P='\[$(ps1_own)\]\$ \[\033[0m\]' PS1P='\[$(ps1_own)\]\$ \[\033[0m\]'
# patch up the returncode # patch up the returncode
# shellcheck disable=SC2016
PS1ret='\[\033[01;31m\]$(ps1_return $?)' PS1ret='\[\033[01;31m\]$(ps1_return $?)'
#and now for the pwd stuff #and now for the pwd stuff
# shellcheck disable=SC2016
PS1dir='\[$(ps1_pre_color)\]$(ps1_pre)\[$(ps1_dir_color)\]$(ps1_dir $(ps1_pre))' PS1dir='\[$(ps1_pre_color)\]$(ps1_pre)\[$(ps1_dir_color)\]$(ps1_dir $(ps1_pre))'
# I found no other solution than embracing the colors right here 'cause # I found no other solution than embracing the colors right here 'cause
# echo -e "\[...\]" doesn't work for any reason. # echo -e "\[...\]" doesn't work for any reason.
@ -187,13 +191,18 @@ else
PS1pre='\A ' PS1pre='\A '
PS1U='\[\033[01;33m\]\u' PS1U='\[\033[01;33m\]\u'
# Not to forget to enlight the @ to show if we are owner # Not to forget to enlight the @ to show if we are owner
# shellcheck disable=SC2016
PS1H='\[$(ps1_own)\]@\[\033[00;32m\]\h' PS1H='\[$(ps1_own)\]@\[\033[00;32m\]\h'
# and enlight the $ if we are to write # and enlight the $ if we are to write
# shellcheck disable=SC2016
PS1P='\[$(ps1_write)\]\$ \[\033[0m\]' PS1P='\[$(ps1_write)\]\$ \[\033[0m\]'
# shellcheck disable=SC2016
PS1ret='\[\033[01;31m\]$(ps1_return $?)' PS1ret='\[\033[01;31m\]$(ps1_return $?)'
# shellcheck disable=SC2016
PS1dir='\[$(ps1_pre_color)\]$(ps1_pre)\[$(ps1_dir_color)\]$(ps1_dir $(ps1_pre))' PS1dir='\[$(ps1_pre_color)\]$(ps1_pre)\[$(ps1_dir_color)\]$(ps1_dir $(ps1_pre))'
# shellcheck disable=SC2016
PS1git='$(__git_ps1 " (%s)")' PS1git='$(__git_ps1 " (%s)")'
export PS1="${PS1pre}${PS1U}${PS1H} ${PS1dir}${ON_COLOR}${PS1git} ${PS1ret}${PS1P}" export PS1="${PS1pre}${PS1U}${PS1H} ${PS1dir}\[${ON_COLOR}\]${PS1git} ${PS1ret}${PS1P}"
fi fi
fi fi
@ -201,7 +210,6 @@ ROOT_COLOR="\033[01;34m" # blue
HOME_COLOR="\033[01;33m" # yellow HOME_COLOR="\033[01;33m" # yellow
ROOT_SYM="\033[00;36m" ROOT_SYM="\033[00;36m"
HOME_SYM="\033[00;33m" HOME_SYM="\033[00;33m"
SYM_COLOR="\033[00;36m" # cyan SYM_COLOR="\033[00;36m" # cyan
ON_COLOR="\033[01;97m" # white ON_COLOR="\033[01;97m" # white
OFF_COLOR="\033[01;37m" # grey OFF_COLOR="\033[01;37m" # grey

Loading…
Cancel
Save