From 0a6695dbcea8626bf73ce4ec05ed2a0fa611bdaa Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sat, 16 Feb 2019 13:30:42 +0530 Subject: [PATCH] Add wish_append. Change plugins to use it --- plugins/dummy.sh | 12 +----------- plugins/newline.sh | 5 +++-- plugins/path.sh | 12 +----------- themes/plain.sh | 1 + wish.sh | 27 ++++++++++++++++++++++++--- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/plugins/dummy.sh b/plugins/dummy.sh index eee0c93..e0e3f84 100644 --- a/plugins/dummy.sh +++ b/plugins/dummy.sh @@ -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 } diff --git a/plugins/newline.sh b/plugins/newline.sh index 1245940..cf03f07 100644 --- a/plugins/newline.sh +++ b/plugins/newline.sh @@ -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" } diff --git a/plugins/path.sh b/plugins/path.sh index af0c558..94f8cab 100644 --- a/plugins/path.sh +++ b/plugins/path.sh @@ -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 " } diff --git a/themes/plain.sh b/themes/plain.sh index bb4fac1..429230a 100644 --- a/themes/plain.sh +++ b/themes/plain.sh @@ -1,2 +1,3 @@ WISH_DEFAULT_BG=-1 WISH_DEFAULT_FG=-1 +WISH_POWERLINE=0 diff --git a/wish.sh b/wish.sh index a3c6fb8..dacef95 100644 --- a/wish.sh +++ b/wish.sh @@ -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