From 919b102a43f101e157d8323b91a5b64908022a1e Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Wed, 25 Dec 2019 20:22:49 +0530 Subject: [PATCH] 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 }