1
0
mirror of https://gitlab.com/ceda_ei/wish synced 2025-10-23 09:50:04 +02:00

25 Commits

Author SHA1 Message Date
343e394d40 Update support for right prompt in themes. 2019-12-29 21:32:03 +05:30
b1fe80cef3 Updated rgb_gradient for better assigning in right prompt 2019-12-29 21:27:56 +05:30
fe18fd52db Add WISH_PATH_POWERLINE_MAX_PERC to limit path length.
WISH_PATH_POWERLINE_MAX_PERC tries to ensure that the path stays below
the specified percentage of the remaining characters. The path is
shortened by replacing each dir with its initial until it becomes short
enough. The last part is never shortened.
2019-12-29 20:26:47 +05:30
30ebb302b8 Revert "Update plugins to new specification for wish_append"
This reverts commit b389774a50.
Since PS1 escape codes are allowed once more, this commit is no longer
needed.
2019-12-25 20:25:20 +05:30
919b102a43 Perform prompt expansion on strings before computing their length.
This reallows usage of PS1 escape sequences (\u, \w, \W, \h, etc) in plugins.
2019-12-25 20:22:49 +05:30
136567e08e [Feature] Add wish_remaining_chars.
wish_remaining_chars is to be used only in main functions of bodies
2019-12-24 22:46:52 +05:30
97fe2dbcc6 [Feature] Do not add text to PS1 if it is too wide. 2019-12-24 20:49:52 +05:30
3f156fdd35 [Feature] Calculate left prompt lengths.
Added wish_append_left.
2019-12-24 20:21:42 +05:30
5828900a92 [Feature] Add multiline support for right prompt
WISH_RPL (i.e. Right Prompt Lengths), WISH_RIGHT_PS1 are now arrays.
WISH_RPLINE tracks the current line. wish_append_right is called by
wish_append to add to WISH_RIGHT_PS1. If wish_append is called with \n
as text, WISH_RPLINE is incremented. (Current limitation: \n can't be
part of any other string passed to wish_append). Right prompt is now printed
using wish_print_right_prompt which iterates over WISH_RPL and
WISH_RIGHT_PS1. Right prompt size is also calculated in
wish_append_right now.
2019-12-24 19:52:15 +05:30
f8254ba89a Add checks for adding powerline to right prompt 2019-12-22 18:45:07 +05:30
b389774a50 Update plugins to new specification for wish_append 2019-12-15 22:01:29 +05:30
eb7f3a6aa3 Update rgb_gradient to support right prompt. 2019-12-15 22:00:37 +05:30
c3fbe4f699 [Feature] Add support for right prompt.
Set WISH_RIGHT_PLUGINS to be displayed on right.
wish_append is stateful now. Appends to WISH_RIGHT_PS1 or WISH_LEFT_PS1
based on WISH_STATE. wish_append also calculates the length of right
prompt. This has the downside that right prompt can't include any text
that expands on PS1. Therefore, a limitation needs to be applied on
plugins to only append text that won't be expanded in PS1. (i.e. no \u,
\h, \w, \W, etc).
2019-12-15 21:46:52 +05:30
079533b686 Add path_powerline 2019-10-12 22:36:47 +05:30
4bed328fa2 Replace tr with parameter expansion. 2019-09-06 22:24:35 +05:30
886ec3bfaf Refactor wish_append.
Use parameter splitting instead of splitting into array via grep. Speeds
the prompt upto 2x in some cases.
2019-09-06 20:35:29 +05:30
ffe7975dfa Add error handling to battery. 2019-09-06 19:39:45 +05:30
ab5df51c2a Set plain as fallback theme if theme not found. Better variable names. 2019-09-06 19:39:37 +05:30
2c6c83b826 Replace eval with variable indirection. 2019-09-06 18:05:12 +05:30
d9e86e4421 Add theme lowfi-neon 2019-07-18 17:16:19 +05:30
78253e1939 Add WISH_AUTONEWLINE. Adds a newline is the output doesn't end with \n 2019-06-10 16:48:40 +05:30
31ec315ffd Use git if it exists in install script 2019-05-15 13:25:33 +05:30
f1b966c5e0 Add EXIT_CODE_SMILEY_HIDE_ON_PASS 2019-03-29 02:26:12 +05:30
02c535506d Update install.sh 2019-03-08 12:49:16 +05:30
05cf509fd7 Add gradient theme 2019-03-02 12:38:54 +05:30
10 changed files with 330 additions and 71 deletions

View File

@@ -1,10 +1,16 @@
#!/usr/bin/env bash #!/usr/bin/env bash
curl https://gitlab.com/ceda_ei/wish/-/archive/master/wish-master.tar -o /tmp/wish.tar if hash git; then
cd /tmp/ git clone https://gitlab.com/ceda_ei/wish.git $HOME/.config/wish.git
tar xf wish.tar else
mv wish-master/ wish/ curl https://gitlab.com/ceda_ei/wish/-/archive/master/wish-master.tar -o /tmp/wish.tar
mv wish/ $HOME/.config/ mkdir $HOME/.config 2> /dev/null
cd /tmp/
tar xf wish.tar
mv wish-master/ wish/
mv wish/ $HOME/.config/
fi
cat >> ~/.bashrc <<EOF cat >> ~/.bashrc <<EOF
# Wish # Wish
@@ -13,4 +19,3 @@ WISH_PLUGINS=(exit_code_smiley bg_jobs date path newline vcs)
WISH_THEME=plain WISH_THEME=plain
source ~/.config/wish/wish.sh source ~/.config/wish/wish.sh
EOF EOF

View File

@@ -16,12 +16,17 @@ function wish_battery_set_colors() {
function wish_battery_main() { function wish_battery_main() {
local path=/sys/class/power_supply/$WISH_BATTERY_ID local path=/sys/class/power_supply/$WISH_BATTERY_ID
local battery=$(($(cat $path/charge_now) * 100 / $(cat $path/charge_full)))% local battery
if [[ -f $path/charge_now ]]; then
battery=$(($(cat $path/charge_now) * 100 / $(cat $path/charge_full)))%
if [[ $(cat $path/status) == "Charging" ]] || if [[ $(cat $path/status) == "Charging" ]] ||
[[ $(cat $path/status) == "Full" ]]; then [[ $(cat $path/status) == "Full" ]]; then
battery="$WISH_BATTERY_CHARGING $battery" battery="$WISH_BATTERY_CHARGING $battery"
else else
battery="$WISH_BATTERY_DISCHARGING $battery" battery="$WISH_BATTERY_DISCHARGING $battery"
fi fi
else
battery="$WISH_BATTERY_ID not found"
fi
wish_append $WISH_BATTERY_BG $WISH_BATTERY_FG " $battery " wish_append $WISH_BATTERY_BG $WISH_BATTERY_FG " $battery "
} }

View File

@@ -11,11 +11,14 @@ function wish_exit_code_smiley_set_colors() {
WISH_EXIT_CODE_SMILEY_BG=${WISH_EXIT_CODE_SMILEY_BG:-$WISH_DEFAULT_BG} WISH_EXIT_CODE_SMILEY_BG=${WISH_EXIT_CODE_SMILEY_BG:-$WISH_DEFAULT_BG}
WISH_EXIT_CODE_SMILEY_PASS=${WISH_EXIT_CODE_SMILEY_PASS:- :) } WISH_EXIT_CODE_SMILEY_PASS=${WISH_EXIT_CODE_SMILEY_PASS:- :) }
WISH_EXIT_CODE_SMILEY_FAIL=${WISH_EXIT_CODE_SMILEY_FAIL:- :( } WISH_EXIT_CODE_SMILEY_FAIL=${WISH_EXIT_CODE_SMILEY_FAIL:- :( }
WISH_EXIT_CODE_SMILEY_HIDE_ON_PASS=${WISH_EXIT_CODE_SMILEY_HIDE_ON_PASS:-0}
} }
function wish_exit_code_smiley_main() { function wish_exit_code_smiley_main() {
if [[ $1 == 0 ]]; then if [[ $1 == 0 ]]; then
if [[ $WISH_EXIT_CODE_SMILEY_HIDE_ON_PASS == 0 ]]; then
wish_append $WISH_EXIT_CODE_SMILEY_BG $WISH_EXIT_CODE_SMILEY_FG "$WISH_EXIT_CODE_SMILEY_PASS" wish_append $WISH_EXIT_CODE_SMILEY_BG $WISH_EXIT_CODE_SMILEY_FG "$WISH_EXIT_CODE_SMILEY_PASS"
fi
else else
wish_append $WISH_EXIT_CODE_SMILEY_BG $WISH_EXIT_CODE_SMILEY_FG "$WISH_EXIT_CODE_SMILEY_FAIL" wish_append $WISH_EXIT_CODE_SMILEY_BG $WISH_EXIT_CODE_SMILEY_FG "$WISH_EXIT_CODE_SMILEY_FAIL"
fi fi

59
plugins/path_powerline.sh Normal file
View File

@@ -0,0 +1,59 @@
function wish_path_powerline_start() {
return 0
}
function wish_path_powerline_end() {
return 0
}
function wish_path_powerline_set_colors() {
WISH_PATH_POWERLINE_FG=${WISH_PATH_POWERLINE_FG:-$WISH_DEFAULT_FG}
WISH_PATH_POWERLINE_BG=${WISH_PATH_POWERLINE_BG:-$WISH_DEFAULT_BG}
WISH_PATH_POWERLINE_NO_WRITE_SUFFIX=${WISH_PATH_POWERLINE_NO_WRITE_SUFFIX:-}
WISH_PATH_POWERLINE_MAX_PERC=${WISH_PATH_POWERLINE_MAX_PERC:-0}
}
function wish_path_lensum() {
sum=0
for i in $*; do
sum=$(($sum + ${#i}))
done
echo $sum
}
function wish_path_powerline_shrink() {
local IFS='/'
local path=( $1 )
local max=$2
for ((i=0; i <$((${#path[@]} - 1)); i++)); do
path[$i]=${path[$i]:0:1}
if [[ $(wish_path_lensum ${path[@]}) -lt $max ]]; then
local short_path=""
for i in ${path[@]}; do
short_path+="$i/"
done
echo "${short_path%/}"
return
fi
done
local short_path=""
for i in ${path[@]}; do
short_path+="$i/"
done
echo "${short_path%/}"
}
function wish_path_powerline_main() {
local path="${PWD/#$HOME/\~}"
if [[ $WISH_PATH_POWERLINE_MAX_PERC -ne 0 && ${#path} -ge $WISH_PATH_POWERLINE_MAX_LEN ]] ; then
local max=$(($WISH_PATH_POWERLINE_MAX_PERC * $(wish_remaining_chars) / 100))
local path=$(wish_path_powerline_shrink "$path" "$max")
fi
local path="${path//\//  }"
if [[ -w $PWD ]]; then
local path=" $path "
else
local path=" $path$WISH_PATH_POWERLINE_NO_WRITE_SUFFIX "
fi
wish_append $WISH_PATH_POWERLINE_BG $WISH_PATH_POWERLINE_FG "$path"
}

View File

@@ -15,7 +15,7 @@ function wish_vcs_set_colors() {
} }
function wish_vcs_main() { function wish_vcs_main() {
local op=$(git diff --numstat HEAD 2> /dev/null || echo -1) local op=$(git diff --numstat 2> /dev/null || echo -1)
if [[ $op != "-1" ]]; then if [[ $op != "-1" ]]; then
local git local git
git="$git $WISH_VCS_GIT_SYMBOL " git="$git $WISH_VCS_GIT_SYMBOL "

27
themes/gradient.sh Normal file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
local i
local gradient=(226 118 37 66 60 237 233)
local fg_gradient=(16 16 16 16 16 15 15)
local j=0
for i in ${WISH_PLUGINS[@]}; do
[[ $i =~ newline$ ]] && j=0 && continue
eval WISH_${i^^}_BG=${gradient[$j]}
eval WISH_${i^^}_FG=${fg_gradient[$j]}
((j++))
if [[ $j -eq ${#gradient[@]} ]]; then
j=0
fi
done
j=0
for ((idx=$((${#WISH_RIGHT_PLUGINS[@]} - 1)); idx >= 0; idx--)); do
i=${WISH_RIGHT_PLUGINS[$idx]}
[[ $i =~ newline$ ]] && j=0 && continue
eval WISH_${i^^}_BG=${gradient[$j]}
eval WISH_${i^^}_FG=${fg_gradient[$j]}
((j++))
if [[ $j -eq ${#gradient[@]} ]]; then
j=0
fi
done

27
themes/lowfi-neon.sh Normal file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
WISH_POWERLINE=0
local i
local gradient=(e7c547 c0e551 82e35a 62e177 6bdfb3 73d4dd 7aa6da)
local j=0
for i in ${WISH_PLUGINS[@]}; do
[[ $i =~ newline$ ]] && j=0 && continue
eval WISH_${i^^}_BG=-1
eval WISH_${i^^}_FG=${gradient[$j]}
((j++))
if [[ $j -eq ${#gradient[@]} ]]; then
j=0
fi
done
j=0
for ((idx=$((${#WISH_RIGHT_PLUGINS[@]} - 1)); idx >= 0; idx--)); do
i=${WISH_RIGHT_PLUGINS[$idx]}
[[ $i =~ newline$ ]] && j=0 && continue
eval WISH_${i^^}_BG=-1
eval WISH_${i^^}_FG=${gradient[$j]}
((j++))
if [[ $j -eq ${#gradient[@]} ]]; then
j=0
fi
done

View File

@@ -1,7 +1,7 @@
WISH_DEFAULT_BG=-1 WISH_DEFAULT_BG=-1
WISH_DEFAULT_FG=-1 WISH_DEFAULT_FG=-1
WISH_POWERLINE=0 WISH_POWERLINE=0
for i in ${WISH_PLUGINS[@]}; do for i in ${WISH_PLUGINS[@]} ${WISH_RIGHT_PLUGINS[@]}; do
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_BG=-1 eval WISH_${i^^}_BG=-1
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_FG=-1 eval WISH_${i^^}_FG=-1
done done

View File

@@ -3,12 +3,23 @@
local i local i
local gradient=(ffff5f 7ad767 66b097 5e7388 534d61 3a3338 121212) local gradient=(ffff5f 7ad767 66b097 5e7388 534d61 3a3338 121212)
local fg_gradient=(000000 000000 000000 000000 000000 ffffff ffffff) local fg_gradient=(000000 000000 000000 000000 000000 ffffff ffffff)
# local gradient=(888888 999999)
local j=0 local j=0
for i in ${WISH_PLUGINS[@]}; do for i in ${WISH_PLUGINS[@]}; do
[[ $i == "newline" ]] && j=0 && continue [[ $i =~ newline$ ]] && j=0 && continue
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_BG=${gradient[$j]} eval WISH_${i^^}_BG=${gradient[$j]}
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_FG=${fg_gradient[$j]} eval WISH_${i^^}_FG=${fg_gradient[$j]}
((j++))
if [[ $j -eq ${#gradient[@]} ]]; then
j=0
fi
done
j=0
for ((idx=$((${#WISH_RIGHT_PLUGINS[@]} - 1)); idx >= 0; idx--)); do
i=${WISH_RIGHT_PLUGINS[$idx]}
[[ $i =~ newline$ ]] && j=0 && continue
eval WISH_${i^^}_BG=${gradient[$j]}
eval WISH_${i^^}_FG=${fg_gradient[$j]}
((j++)) ((j++))
if [[ $j -eq ${#gradient[@]} ]]; then if [[ $j -eq ${#gradient[@]} ]]; then
j=0 j=0

224
wish.sh
View File

@@ -1,74 +1,178 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# INTERNAL USE ONLY! Do not use this in plugins.
function wish_print_right_prompt() {
local idx=0
for i in ${WISH_RPL[@]}; do
echo "\e[$(($COLUMNS - $i + 1))G${WISH_RIGHT_PS1[$idx]}"
((idx++))
done
}
function wish_init() { function wish_init() {
# Source all plugins # Source all plugins
local i local plugin
local j local path
for i in ${WISH_PLUGINS[@]}; do for plugin in ${WISH_PLUGINS[@]} ${WISH_RIGHT_PLUGINS[@]}; do
for j in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do for path in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
source "$j/wish/plugins/$i.sh" &> /dev/null && break source "$path/wish/plugins/$plugin.sh" &> /dev/null && break
done done
[[ $? -ne 0 ]] && echo "Plugin $i not found." >&2 [[ $? -ne 0 ]] && echo "Plugin $i not found." >&2
done done
# Source theme # Source theme
WISH_THEME=${WISH_THEME:-plain} WISH_THEME=${WISH_THEME:-plain}
for i in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do while :; do
source "$i/wish/themes/$WISH_THEME.sh" &> /dev/null && break for theme in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
source "$theme/wish/themes/$WISH_THEME.sh" &> /dev/null && break
done
if [[ $? -eq 0 ]]; then
break
else
echo "Theme $WISH_THEME not found. Using theme plain." >&2
if [[ $WISH_THEME == "plain" ]]; then
break
else
WISH_THEME=plain
fi
fi
done done
[[ $? -ne 0 ]] && echo "Theme $WISH_THEME not found." >&2
# Call plugins to set colors # Call plugins to set colors
for i in ${WISH_PLUGINS[@]}; do for plugin in ${WISH_PLUGINS[@]} ${WISH_RIGHT_PLUGINS[@]}; do
eval wish_$(echo $i)_set_colors $prev eval wish_$(echo $plugin)_set_colors $prev
done done
} }
# Usage: color_to_escape_code [3|4] color
#
# Parameters:
# - [3|4]: Use 3 if escape code is for foreground, 4 for background
# - color: -1 to reset, 0-255 for terminal color codes. 6 digit hexadecimal
# value for true color.
#
# Return value: Prints escape code that sets the fg/bg as requested.
function color_to_escape_code() {
local choice=$1
local color=$2
if [[ $color == -1 ]]; then
echo "\[\033[0;5;0m\]"
else
if [[ ${#fg_code} -eq 6 ]]; then
local r=$(( 16#${color:0:2} ))
local g=$(( 16#${color:2:2} ))
local b=$(( 16#${color:4:2} ))
echo "\[\033[${choice}8;2;$r;$g;${b}m\]"
else
echo "\[\033[${choice}8;5;${fg_code}m\]"
fi
fi
}
# INTERNAL USE ONLY! Do not use this in plugins.
# Usage: wish_append_left escape_codes text
function wish_append_left() {
local text="$2"
local colors="$1"
local prompt_text="${text@P}"
if [[ $text == "\n" ]]; then
((WISH_LPLINE++))
WISH_LPL=(${WISH_LPL[@]} 0)
WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text"
else
if [[ $((${WISH_LPL[$WISH_LPLINE]} + ${#prompt_text})) -lt $COLUMNS ]]; then
WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text"
WISH_LPL[$WISH_LPLINE]=$((${WISH_LPL[$WISH_LPLINE]} + ${#prompt_text}))
fi
fi
}
# INTERNAL USE ONLY! Do not use this in plugins.
# Usage: wish_append_right escape_codes text
function wish_append_right() {
local text="$2"
local colors="$1"
local prompt_text="${text@P}"
if [[ $text == "\n" ]]; then
((WISH_RPLINE++))
WISH_RIGHT_PS1=("${WISH_RIGHT_PS1[@]}" "")
WISH_RPL=(${WISH_RPL[@]} 0)
elif [[ $((${WISH_LPL[$WISH_RPLINE]} + ${WISH_RPL[$WISH_RPLINE]} + ${#prompt_text})) -lt $COLUMNS ]]; then
WISH_RIGHT_PS1[$WISH_RPLINE]="${WISH_RIGHT_PS1[$WISH_RPLINE]}$colors$text"
WISH_RPL[$WISH_RPLINE]=$((${WISH_RPL[$WISH_RPLINE]} + ${#prompt_text}))
fi
}
# Public API
# Usage: wish_append bg fg text # Usage: wish_append bg fg text
#
# Parameters:
# - fg, bg: -1 to reset, 0-255 for terminal color codes. 6 digit hexadecimal
# value for true color.
# - text: Text of the plugin
#
# Return value: None
function wish_append() { function wish_append() {
local bg_code=$1 local bg_code=$1
local fg_code=$2 local fg_code=$2
local text=$3 local text=$3
if [[ $fg_code == -1 ]]; then local fg=$(color_to_escape_code 3 $fg_code)
local fg=$(tput sgr0) local bg=$(color_to_escape_code 4 $bg_code)
else
if [[ ${#fg_code} -eq 6 ]]; then
local color=($(echo $fg_code | grep -o .))
local r=$(( 16#${color[0]}${color[1]} ))
local g=$(( 16#${color[2]}${color[3]} ))
local b=$(( 16#${color[4]}${color[5]} ))
local fg="\[\033[38;2;$r;$g;${b}m\]"
else
local fg=$(tput setaf $fg_code)
fi
fi
if [[ $bg_code == -1 ]]; then
local bg=$(tput sgr0)
else
if [[ ${#bg_code} -eq 6 ]]; then
local color=($(echo $bg_code | grep -o .))
local r=$(( 16#${color[0]}${color[1]} ))
local g=$(( 16#${color[2]}${color[3]} ))
local b=$(( 16#${color[4]}${color[5]} ))
local bg="\[\033[48;2;$r;$g;${b}m\]"
else
local bg=$(tput setab $bg_code)
fi
fi
if [[ $fg_code == -1 ]]; then if [[ $fg_code == -1 ]]; then
PS1="$PS1$fg${bg}$text" case $WISH_STATE in
0)
wish_append_left "$fg$bg" "$text"
;;
1)
wish_append_right "$fg$bg" "$text"
;;
esac
else else
PS1="$PS1$bg${fg}$text" case $WISH_STATE in
0)
wish_append_left "$bg$fg" "$text"
;;
1)
wish_append_right "$bg$fg" "$text"
;;
esac
fi fi
} }
# Public API
# Usage: wish_remaining_chars
# Parameters: None
# Return Value: Capture stdout to get the remaining characters available in the
# line.
wish_remaining_chars() {
if [[ $WISH_STATE -eq 0 ]]; then
echo "$(( $COLUMNS - ${WISH_LPL[$WISH_LPLINE]} ))"
else
echo "$(( $COLUMNS - ${WISH_LPL[$WISH_RPLINE]} - ${WISH_RPL[$WISH_RPLINE]} ))"
fi
}
function wish_main() { function wish_main() {
local prev=$? local prev=$?
# Set local IFS to avoid being affected by shell's IFS
local IFS=$' \n'
PS1="" PS1=""
WISH_LEFT_PS1=""
WISH_RIGHT_PS1=("")
WISH_LPL=(0)
WISH_RPL=(0)
WISH_RPLINE=0
WISH_LPLINE=0
local i local i
# Set newline
if [[ $WISH_AUTONEWLINE != 0 ]]; then
echo -ne "\033[6n" ; read -s -d ';'; read -s -d R WISH_CURSOR_POSITION
if [[ $WISH_CURSOR_POSITION != "1" ]]; then
PS1="\n"
fi
fi
# Generate left prompt.
WISH_STATE=0 # 0 = left prompt, 1 = right prompt
for i in $(seq 0 $((${#WISH_PLUGINS[@]} - 1))); do for i in $(seq 0 $((${#WISH_PLUGINS[@]} - 1))); do
wish_${WISH_PLUGINS[i]}_main $prev wish_${WISH_PLUGINS[i]}_main $prev
if [[ -v WISH_POWERLINE ]] && [[ $WISH_POWERLINE != 0 ]]; then if [[ -v WISH_POWERLINE ]] && [[ $WISH_POWERLINE != 0 ]]; then
@@ -77,25 +181,43 @@ function wish_main() {
if wish_${WISH_PLUGINS[$(($i + 1))]}_start $prev; then if wish_${WISH_PLUGINS[$(($i + 1))]}_start $prev; then
local plugin=${WISH_PLUGINS[$i]} local plugin=${WISH_PLUGINS[$i]}
local next_plugin=${WISH_PLUGINS[$(($i+1))]} local next_plugin=${WISH_PLUGINS[$(($i+1))]}
local fg=$(eval echo \$WISH_$(echo $plugin | local fg_name="WISH_${plugin^^}_BG"
tr '[:lower:]' '[:upper:]')_BG) local bg_name="WISH_${next_plugin^^}_BG"
local bg=$(eval echo \$WISH_$(echo $next_plugin | wish_append ${!bg_name} ${!fg_name}
tr '[:lower:]' '[:upper:]')_BG)
wish_append $bg $fg
fi fi
else else
local plugin=${WISH_PLUGINS[$i]} local plugin=${WISH_PLUGINS[$i]}
local fg=$(eval echo \$WISH_$(echo $plugin | local fg_name="WISH_${plugin^^}_BG"
tr '[:lower:]' '[:upper:]')_BG) wish_append -1 ${!fg_name}
wish_append -1 $fg
fi fi
fi fi
fi fi
if [[ $i -eq $((${#WISH_PLUGINS[@]} - 1)) ]]; then
PS1="$PS1\[\033[0;5;0m\]"
fi
done done
# Generate Right prompt.
WISH_STATE=1
for i in $(seq 0 $((${#WISH_RIGHT_PLUGINS[@]} - 1))); do
if [[ -v WISH_POWERLINE ]] && [[ $WISH_POWERLINE != 0 ]]; then
if wish_${WISH_RIGHT_PLUGINS[$i]}_end $prev; then
if [[ $i == 0 ]]; then
local plugin=${WISH_RIGHT_PLUGINS[$i]}
local fg_name="WISH_${plugin^^}_BG"
wish_append -1 ${!fg_name}
elif wish_${WISH_RIGHT_PLUGINS[$(($i - 1))]}_start $prev; then
local plugin=${WISH_RIGHT_PLUGINS[$i]}
local prev_plugin=${WISH_RIGHT_PLUGINS[$(($i-1))]}
local fg_name="WISH_${plugin^^}_BG"
local bg_name="WISH_${prev_plugin^^}_BG"
wish_append ${!bg_name} ${!fg_name}
fi
fi
fi
wish_${WISH_RIGHT_PLUGINS[$i]}_main $prev
done
# Save cursor position, print right prompt, restore cursor position,
# print left prompt, reset terminal
PS1=$PS1"\[\e7"
PS1="$PS1$(wish_print_right_prompt)"
PS1="$PS1\e8\]$WISH_LEFT_PS1\[\033[0;5;0m\]"
} }
wish_init wish_init