Add wish_append. Change plugins to use it

This commit is contained in:
Ceda EI 2019-02-16 13:30:42 +05:30
parent 50070fe6c7
commit 0a6695dbce
5 changed files with 30 additions and 27 deletions

View File

@ -12,15 +12,5 @@ function wish_dummy_set_colors() {
}
function wish_dummy_main() {
if [[ $fg -eq -1 ]]; then
local fg="\[\033[0;5;0m\]"
else
local fg="\[\033[38;5;${WISH_DUMMY_FG}m\]"
fi
if [[ $bg -eq -1 ]]; then
local bg="\[\033[0;5;0m\]"
else
local bg="\[\033[48;5;${WISH_DUMMY_BG}m\]"
fi
PS1="$PS1$bg${fg}dummy"
wish_append $WISH_DUMMY_BG $WISH_DUMMY_FG dummy
}

View File

@ -7,9 +7,10 @@ function wish_newline_end() {
}
function wish_newline_set_colors() {
return
WISH_NEWLINE_BG=-1
WISH_NEWLINE_FG=-1
}
function wish_newline_main() {
PS1="$PS1\n"
wish_append -1 -1 "\n"
}

View File

@ -12,15 +12,5 @@ function wish_path_set_colors() {
}
function wish_path_main() {
if [[ $fg -eq -1 ]]; then
local fg="\[\033[0;5;0m\]"
else
local fg="\[\033[38;5;${WISH_PATH_FG}m\]"
fi
if [[ $bg -eq -1 ]]; then
local bg="\[\033[0;5;0m\]"
else
local bg="\[\033[48;5;${WISH_PATH_BG}m\]"
fi
PS1="$PS1$fg${bg} \w "
wish_append $WISH_PATH_BG $WISH_PATH_FG " \w "
}

View File

@ -1,2 +1,3 @@
WISH_DEFAULT_BG=-1
WISH_DEFAULT_FG=-1
WISH_POWERLINE=0

27
wish.sh
View File

@ -25,6 +25,28 @@ function wish_init() {
done
}
# Usage: wish_append bg fg text
function wish_append() {
local bg_code=$1
local fg_code=$2
local text=$3
if [[ $fg_code -eq -1 ]]; then
local fg="\[\033[0;5;0m\]"
else
local fg="\[\033[38;5;${fg_code}m\]"
fi
if [[ $bg_code -eq -1 ]]; then
local bg="\[\033[0;5;0m\]"
else
local bg="\[\033[48;5;${bg_code}m\]"
fi
if [[ $fg_code -eq -1 ]]; then
PS1="$PS1$fg${bg}$text"
else
PS1="$PS1$bg${fg}$text"
fi
}
function wish_main() {
local prev=$?
@ -42,14 +64,13 @@ function wish_main() {
tr '[:lower:]' '[:upper:]')_BG)
local bg=$(eval echo \$WISH_$(echo $next_plugin |
tr '[:lower:]' '[:upper:]')_BG)
PS1="$PS1\[\033[38;5;${fg}m\]\[\033[48;5;${bg}m\]"
wish_append $bg $fg
fi
else
local plugin=${WISH_PLUGINS[$i]}
local fg=$(eval echo \$WISH_$(echo $plugin |
tr '[:lower:]' '[:upper:]')_BG)
PS1="$PS1\[\033[0;5;0m\]"
PS1="$PS1\[\033[38;5;${fg}m\]"
wish_append -1 $fg
fi
fi
fi