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