From 97fe2dbcc6eca904747cf222245562fa156fe3d2 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 24 Dec 2019 20:49:52 +0530 Subject: [PATCH] [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