From c3fbe4f699182256915351a754955741232d6b9d Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 15 Dec 2019 21:46:52 +0530 Subject: [PATCH 01/13] [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). --- wish.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/wish.sh b/wish.sh index e2c435c..e590fe7 100644 --- a/wish.sh +++ b/wish.sh @@ -4,7 +4,7 @@ function wish_init() { # Source all plugins local plugin local path - for plugin in ${WISH_PLUGINS[@]}; do + for plugin in ${WISH_PLUGINS[@]} ${WISH_RIGHT_PLUGINS[@]}; do for path in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do source "$path/wish/plugins/$plugin.sh" &> /dev/null && break done @@ -30,7 +30,7 @@ function wish_init() { done # Call plugins to set colors - for plugin in ${WISH_PLUGINS[@]}; do + for plugin in ${WISH_PLUGINS[@]} ${WISH_RIGHT_PLUGINS[@]}; do eval wish_$(echo $plugin)_set_colors $prev done } @@ -75,24 +75,48 @@ function wish_append() { local fg=$(color_to_escape_code 3 $fg_code) local bg=$(color_to_escape_code 4 $bg_code) + if [[ $WISH_STATE == 1 ]]; then + WISH_RPL=$((WISH_RPL + ${#text})) + fi if [[ $fg_code == -1 ]]; then - PS1="$PS1$fg${bg}$text" + case $WISH_STATE in + 0) + WISH_LEFT_PS1="$WISH_LEFT_PS1$fg${bg}$text" + ;; + 1) + WISH_RIGHT_PS1="$WISH_RIGHT_PS1$fg${bg}$text" + ;; + esac else - PS1="$PS1$bg${fg}$text" + case $WISH_STATE in + 0) + WISH_LEFT_PS1="$WISH_LEFT_PS1$bg$fg$text" + ;; + 1) + WISH_RIGHT_PS1="$WISH_RIGHT_PS1$bg$fg$text" + ;; + esac fi } function wish_main() { local prev=$? + # Set local IFS to avoid being affected by shell's IFS + local IFS=$' \n' PS1="" + WISH_LEFT_PS1="" + WISH_RIGHT_PS1="" 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 wish_${WISH_PLUGINS[i]}_main $prev if [[ -v WISH_POWERLINE ]] && [[ $WISH_POWERLINE != 0 ]]; then @@ -112,11 +136,27 @@ function wish_main() { fi fi fi - - if [[ $i -eq $((${#WISH_PLUGINS[@]} - 1)) ]]; then - PS1="$PS1\[\033[0;5;0m\]" - fi done + # Generate Right prompt. + WISH_STATE=1 + WISH_RPL=0 + for i in $(seq 0 $((${#WISH_RIGHT_PLUGINS[@]} - 1))); do + if [[ -v WISH_POWERLINE && WISH_POWERLINE != 0 ]]; then + if [[ $i == 0 ]]; then + local plugin=${WISH_RIGHT_PLUGINS[$i]} + local fg_name="WISH_${plugin^^}_BG" + wish_append -1 ${!fg_name}  + else + 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 + wish_${WISH_RIGHT_PLUGINS[$i]}_main $prev + done + PS1=$PS1"\[\e7\e[$(($COLUMNS - $WISH_RPL + 1))G$WISH_RIGHT_PS1\e8\]$WISH_LEFT_PS1\[\033[0;5;0m\]" } wish_init From eb7f3a6aa39bb02987f96892b43ff40ba5fe4446 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 15 Dec 2019 22:00:37 +0530 Subject: [PATCH 02/13] Update rgb_gradient to support right prompt. --- themes/rgb_gradient.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/themes/rgb_gradient.sh b/themes/rgb_gradient.sh index cb54307..e926894 100644 --- a/themes/rgb_gradient.sh +++ b/themes/rgb_gradient.sh @@ -13,3 +13,17 @@ for i in ${WISH_PLUGINS[@]}; do j=0 fi done + +j=0 +for i in ${WISH_RIGHT_PLUGINS[@]}; do + [[ $i == "newline" ]] && j=0 && continue + eval WISH_${i^^}_BG=${gradient[$((${#WISH_RIGHT_PLUGINS[@]} - $j - 1))]} + x=WISH_${i^^}_BG + echo WISH_${i^^}_BG: ${!x} ${#gradient[@]} - ${#WISH_RIGHT_PLUGINS[@]} - $j + eval WISH_${i^^}_FG=${fg_gradient[$((${#WISH_RIGHT_PLUGINS[@]} - $j - 1))]} + echo WISH_${i^^}_FG: $WISH_${i^^}_FG + ((j++)) + if [[ $j -eq ${#gradient[@]} ]]; then + j=0 + fi +done From b389774a5062342aaee11588e1754005c8268789 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 15 Dec 2019 22:01:29 +0530 Subject: [PATCH 03/13] Update plugins to new specification for wish_append --- plugins/hostname.sh | 2 +- plugins/path.sh | 4 ++-- plugins/username.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/hostname.sh b/plugins/hostname.sh index 5e4ced3..c1ccea6 100644 --- a/plugins/hostname.sh +++ b/plugins/hostname.sh @@ -12,5 +12,5 @@ function wish_hostname_set_colors() { } function wish_hostname_main() { - wish_append $WISH_HOSTNAME_BG $WISH_HOSTNAME_FG " \h " + wish_append $WISH_HOSTNAME_BG $WISH_HOSTNAME_FG " $HOSTNAME " } diff --git a/plugins/path.sh b/plugins/path.sh index 8e3329d..cce71ca 100644 --- a/plugins/path.sh +++ b/plugins/path.sh @@ -14,9 +14,9 @@ function wish_path_set_colors() { function wish_path_main() { if [[ -w $PWD ]]; then - local path=" \w " + local path=" ${PWD/$HOME/\~} " else - local path=" \w$WISH_PATH_NO_WRITE_SUFFIX " + local path=" ${PWD/$HOME/\~}$WISH_PATH_NO_WRITE_SUFFIX " fi wish_append $WISH_PATH_BG $WISH_PATH_FG "$path" } diff --git a/plugins/username.sh b/plugins/username.sh index 617410a..fa0e65b 100644 --- a/plugins/username.sh +++ b/plugins/username.sh @@ -12,5 +12,5 @@ function wish_username_set_colors() { } function wish_username_main() { - wish_append $WISH_USERNAME_BG $WISH_USERNAME_FG " \u " + wish_append $WISH_USERNAME_BG $WISH_USERNAME_FG " $USER " } From f8254ba89a5172e9d0f0876af6a7b1b9d3450268 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 22 Dec 2019 18:45:07 +0530 Subject: [PATCH 04/13] Add checks for adding powerline to right prompt --- wish.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/wish.sh b/wish.sh index e590fe7..8fff68a 100644 --- a/wish.sh +++ b/wish.sh @@ -141,17 +141,19 @@ function wish_main() { WISH_STATE=1 WISH_RPL=0 for i in $(seq 0 $((${#WISH_RIGHT_PLUGINS[@]} - 1))); do - if [[ -v WISH_POWERLINE && WISH_POWERLINE != 0 ]]; then - if [[ $i == 0 ]]; then - local plugin=${WISH_RIGHT_PLUGINS[$i]} - local fg_name="WISH_${plugin^^}_BG" - wish_append -1 ${!fg_name}  - else - 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}  + 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 From 5828900a92c933c861c5b5b1794ee2f213bb0cbb Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 24 Dec 2019 19:52:15 +0530 Subject: [PATCH 05/13] [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. --- wish.sh | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/wish.sh b/wish.sh index 8fff68a..a3e5795 100644 --- a/wish.sh +++ b/wish.sh @@ -1,5 +1,14 @@ #!/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() { # Source all plugins local plugin @@ -60,6 +69,21 @@ function color_to_escape_code() { 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" + if [[ $text == "\n" ]]; then + ((WISH_RPLINE++)) + WISH_RIGHT_PS1=("${WISH_RIGHT_PS1[@]}" "") + WISH_RPL=(${WISH_RPL[@]} 0) + else + WISH_RIGHT_PS1[$WISH_RPLINE]="${WISH_RIGHT_PS1[$WISH_RPLINE]}$colors$text" + WISH_RPL[$WISH_RPLINE]=$((${WISH_RPL[$WISH_RPLINE]} + ${#text})) + fi +} + # Usage: wish_append bg fg text # # Parameters: @@ -75,16 +99,13 @@ function wish_append() { local fg=$(color_to_escape_code 3 $fg_code) local bg=$(color_to_escape_code 4 $bg_code) - if [[ $WISH_STATE == 1 ]]; then - WISH_RPL=$((WISH_RPL + ${#text})) - fi if [[ $fg_code == -1 ]]; then case $WISH_STATE in 0) WISH_LEFT_PS1="$WISH_LEFT_PS1$fg${bg}$text" ;; 1) - WISH_RIGHT_PS1="$WISH_RIGHT_PS1$fg${bg}$text" + wish_append_right "$fg$bg" "$text" ;; esac else @@ -93,7 +114,7 @@ function wish_append() { WISH_LEFT_PS1="$WISH_LEFT_PS1$bg$fg$text" ;; 1) - WISH_RIGHT_PS1="$WISH_RIGHT_PS1$bg$fg$text" + wish_append_right "$bg$fg" "$text" ;; esac fi @@ -106,7 +127,9 @@ function wish_main() { local IFS=$' \n' PS1="" WISH_LEFT_PS1="" - WISH_RIGHT_PS1="" + WISH_RIGHT_PS1=("") + WISH_RPL=(0) + WISH_RPLINE=0 local i # Set newline if [[ $WISH_AUTONEWLINE != 0 ]]; then @@ -139,7 +162,6 @@ function wish_main() { done # Generate Right prompt. WISH_STATE=1 - WISH_RPL=0 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 @@ -158,7 +180,11 @@ function wish_main() { fi wish_${WISH_RIGHT_PLUGINS[$i]}_main $prev done - PS1=$PS1"\[\e7\e[$(($COLUMNS - $WISH_RPL + 1))G$WISH_RIGHT_PS1\e8\]$WISH_LEFT_PS1\[\033[0;5;0m\]" + # 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 From 3f156fdd35c83e8db356f86561285384b837e607 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 24 Dec 2019 20:21:42 +0530 Subject: [PATCH 06/13] [Feature] Calculate left prompt lengths. Added wish_append_left. --- wish.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/wish.sh b/wish.sh index a3e5795..6727aec 100644 --- a/wish.sh +++ b/wish.sh @@ -68,6 +68,19 @@ function color_to_escape_code() { 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" + if [[ $text == "\n" ]]; then + ((WISH_LPLINE++)) + WISH_LPL=(${WISH_LPL[@]} 0) + else + WISH_LPL[$WISH_LPLINE]=$((${WISH_LPL[$WISH_LPLINE]} + ${#text})) + fi + WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text" +} # INTERNAL USE ONLY! Do not use this in plugins. # Usage: wish_append_right escape_codes text @@ -102,7 +115,7 @@ function wish_append() { if [[ $fg_code == -1 ]]; then case $WISH_STATE in 0) - WISH_LEFT_PS1="$WISH_LEFT_PS1$fg${bg}$text" + wish_append_left "$fg$bg" "$text" ;; 1) wish_append_right "$fg$bg" "$text" @@ -111,7 +124,7 @@ function wish_append() { else case $WISH_STATE in 0) - WISH_LEFT_PS1="$WISH_LEFT_PS1$bg$fg$text" + wish_append_left "$bg$fg" "$text" ;; 1) wish_append_right "$bg$fg" "$text" @@ -128,8 +141,10 @@ function wish_main() { PS1="" WISH_LEFT_PS1="" WISH_RIGHT_PS1=("") + WISH_LPL=(0) WISH_RPL=(0) WISH_RPLINE=0 + WISH_LPLINE=0 local i # Set newline if [[ $WISH_AUTONEWLINE != 0 ]]; then From 97fe2dbcc6eca904747cf222245562fa156fe3d2 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 24 Dec 2019 20:49:52 +0530 Subject: [PATCH 07/13] [Feature] Do not add text to PS1 if it is too wide. --- wish.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wish.sh b/wish.sh index 6727aec..de68731 100644 --- a/wish.sh +++ b/wish.sh @@ -76,10 +76,13 @@ function wish_append_left() { if [[ $text == "\n" ]]; then ((WISH_LPLINE++)) WISH_LPL=(${WISH_LPL[@]} 0) + WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text" else - WISH_LPL[$WISH_LPLINE]=$((${WISH_LPL[$WISH_LPLINE]} + ${#text})) + if [[ $((${WISH_LPL[$WISH_LPLINE]} + ${#text})) -lt $COLUMNS ]]; then + WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text" + WISH_LPL[$WISH_LPLINE]=$((${WISH_LPL[$WISH_LPLINE]} + ${#text})) + fi fi - WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text" } # INTERNAL USE ONLY! Do not use this in plugins. @@ -91,7 +94,7 @@ function wish_append_right() { ((WISH_RPLINE++)) WISH_RIGHT_PS1=("${WISH_RIGHT_PS1[@]}" "") WISH_RPL=(${WISH_RPL[@]} 0) - else + elif [[ $((${WISH_LPL[$WISH_RPLINE]} + ${WISH_RPL[$WISH_RPLINE]} + ${#text})) -lt $COLUMNS ]]; then WISH_RIGHT_PS1[$WISH_RPLINE]="${WISH_RIGHT_PS1[$WISH_RPLINE]}$colors$text" WISH_RPL[$WISH_RPLINE]=$((${WISH_RPL[$WISH_RPLINE]} + ${#text})) fi From 136567e08ec0228ffedcce77bb2aded7bb53211b Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 24 Dec 2019 22:46:52 +0530 Subject: [PATCH 08/13] [Feature] Add wish_remaining_chars. wish_remaining_chars is to be used only in main functions of bodies --- wish.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wish.sh b/wish.sh index de68731..c0b6f93 100644 --- a/wish.sh +++ b/wish.sh @@ -100,6 +100,7 @@ function wish_append_right() { fi } +# Public API # Usage: wish_append bg fg text # # Parameters: @@ -136,6 +137,18 @@ function wish_append() { 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() { local prev=$? From 919b102a43f101e157d8323b91a5b64908022a1e Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Wed, 25 Dec 2019 20:22:49 +0530 Subject: [PATCH 09/13] Perform prompt expansion on strings before computing their length. This reallows usage of PS1 escape sequences (\u, \w, \W, \h, etc) in plugins. --- wish.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wish.sh b/wish.sh index c0b6f93..8be88b3 100644 --- a/wish.sh +++ b/wish.sh @@ -73,14 +73,15 @@ function color_to_escape_code() { 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]} + ${#text})) -lt $COLUMNS ]]; then + 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]} + ${#text})) + WISH_LPL[$WISH_LPLINE]=$((${WISH_LPL[$WISH_LPLINE]} + ${#prompt_text})) fi fi } @@ -90,13 +91,14 @@ function wish_append_left() { 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]} + ${#text})) -lt $COLUMNS ]]; then + 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]} + ${#text})) + WISH_RPL[$WISH_RPLINE]=$((${WISH_RPL[$WISH_RPLINE]} + ${#prompt_text})) fi } From 30ebb302b8e01e8f9791b2595e8c98f74bca1c70 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Wed, 25 Dec 2019 20:25:20 +0530 Subject: [PATCH 10/13] Revert "Update plugins to new specification for wish_append" This reverts commit b389774a5062342aaee11588e1754005c8268789. Since PS1 escape codes are allowed once more, this commit is no longer needed. --- plugins/hostname.sh | 2 +- plugins/path.sh | 4 ++-- plugins/username.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/hostname.sh b/plugins/hostname.sh index c1ccea6..5e4ced3 100644 --- a/plugins/hostname.sh +++ b/plugins/hostname.sh @@ -12,5 +12,5 @@ function wish_hostname_set_colors() { } function wish_hostname_main() { - wish_append $WISH_HOSTNAME_BG $WISH_HOSTNAME_FG " $HOSTNAME " + wish_append $WISH_HOSTNAME_BG $WISH_HOSTNAME_FG " \h " } diff --git a/plugins/path.sh b/plugins/path.sh index cce71ca..8e3329d 100644 --- a/plugins/path.sh +++ b/plugins/path.sh @@ -14,9 +14,9 @@ function wish_path_set_colors() { function wish_path_main() { if [[ -w $PWD ]]; then - local path=" ${PWD/$HOME/\~} " + local path=" \w " else - local path=" ${PWD/$HOME/\~}$WISH_PATH_NO_WRITE_SUFFIX " + local path=" \w$WISH_PATH_NO_WRITE_SUFFIX " fi wish_append $WISH_PATH_BG $WISH_PATH_FG "$path" } diff --git a/plugins/username.sh b/plugins/username.sh index fa0e65b..617410a 100644 --- a/plugins/username.sh +++ b/plugins/username.sh @@ -12,5 +12,5 @@ function wish_username_set_colors() { } function wish_username_main() { - wish_append $WISH_USERNAME_BG $WISH_USERNAME_FG " $USER " + wish_append $WISH_USERNAME_BG $WISH_USERNAME_FG " \u " } From fe18fd52db09642b939fccecbbf0f8898a75abbc Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 29 Dec 2019 20:26:47 +0530 Subject: [PATCH 11/13] 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. --- plugins/path_powerline.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/plugins/path_powerline.sh b/plugins/path_powerline.sh index 0198577..bd4430b 100644 --- a/plugins/path_powerline.sh +++ b/plugins/path_powerline.sh @@ -10,10 +10,45 @@ 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 " From b1fe80cef305550c6fc2186a77562fe4ae6b9ff4 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 29 Dec 2019 21:27:56 +0530 Subject: [PATCH 12/13] Updated rgb_gradient for better assigning in right prompt --- themes/rgb_gradient.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/themes/rgb_gradient.sh b/themes/rgb_gradient.sh index e926894..ffadde2 100644 --- a/themes/rgb_gradient.sh +++ b/themes/rgb_gradient.sh @@ -5,7 +5,7 @@ local gradient=(ffff5f 7ad767 66b097 5e7388 534d61 3a3338 121212) local fg_gradient=(000000 000000 000000 000000 000000 ffffff ffffff) local j=0 for i in ${WISH_PLUGINS[@]}; do - [[ $i == "newline" ]] && j=0 && continue + [[ $i =~ newline$ ]] && j=0 && continue eval WISH_${i^^}_BG=${gradient[$j]} eval WISH_${i^^}_FG=${fg_gradient[$j]} ((j++)) @@ -15,13 +15,11 @@ for i in ${WISH_PLUGINS[@]}; do done j=0 -for i in ${WISH_RIGHT_PLUGINS[@]}; do - [[ $i == "newline" ]] && j=0 && continue - eval WISH_${i^^}_BG=${gradient[$((${#WISH_RIGHT_PLUGINS[@]} - $j - 1))]} - x=WISH_${i^^}_BG - echo WISH_${i^^}_BG: ${!x} ${#gradient[@]} - ${#WISH_RIGHT_PLUGINS[@]} - $j - eval WISH_${i^^}_FG=${fg_gradient[$((${#WISH_RIGHT_PLUGINS[@]} - $j - 1))]} - echo WISH_${i^^}_FG: $WISH_${i^^}_FG +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 From 343e394d407d1e0bfe1ca14e8ae301e792223873 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Sun, 29 Dec 2019 21:32:03 +0530 Subject: [PATCH 13/13] Update support for right prompt in themes. --- themes/gradient.sh | 14 +++++++++++++- themes/lowfi-neon.sh | 14 +++++++++++++- themes/plain.sh | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/themes/gradient.sh b/themes/gradient.sh index b6d9e67..14dea7b 100644 --- a/themes/gradient.sh +++ b/themes/gradient.sh @@ -5,7 +5,19 @@ 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 + [[ $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++)) diff --git a/themes/lowfi-neon.sh b/themes/lowfi-neon.sh index 5041ea0..a6aabd6 100644 --- a/themes/lowfi-neon.sh +++ b/themes/lowfi-neon.sh @@ -5,7 +5,19 @@ 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 + [[ $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++)) diff --git a/themes/plain.sh b/themes/plain.sh index e89e2d1..ffef741 100644 --- a/themes/plain.sh +++ b/themes/plain.sh @@ -1,7 +1,7 @@ WISH_DEFAULT_BG=-1 WISH_DEFAULT_FG=-1 WISH_POWERLINE=0 -for i in ${WISH_PLUGINS[@]}; do +for i in ${WISH_PLUGINS[@]} ${WISH_RIGHT_PLUGINS[@]}; do eval WISH_${i^^}_BG=-1 eval WISH_${i^^}_FG=-1 done