mirror of
				https://gitlab.com/ceda_ei/wish
				synced 2025-11-02 23:50:04 +01:00 
			
		
		
		
	Perform prompt expansion on strings before computing their length.
This reallows usage of PS1 escape sequences (\u, \w, \W, \h, etc) in plugins.
This commit is contained in:
		
							
								
								
									
										10
									
								
								wish.sh
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								wish.sh
									
									
									
									
									
								
							@@ -73,14 +73,15 @@ function color_to_escape_code() {
 | 
				
			|||||||
function wish_append_left() {
 | 
					function wish_append_left() {
 | 
				
			||||||
	local text="$2"
 | 
						local text="$2"
 | 
				
			||||||
	local colors="$1"
 | 
						local colors="$1"
 | 
				
			||||||
 | 
						local prompt_text="${text@P}"
 | 
				
			||||||
	if [[ $text == "\n" ]]; then
 | 
						if [[ $text == "\n" ]]; then
 | 
				
			||||||
		((WISH_LPLINE++))
 | 
							((WISH_LPLINE++))
 | 
				
			||||||
		WISH_LPL=(${WISH_LPL[@]} 0)
 | 
							WISH_LPL=(${WISH_LPL[@]} 0)
 | 
				
			||||||
		WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text"
 | 
							WISH_LEFT_PS1="$WISH_LEFT_PS1$colors$text"
 | 
				
			||||||
	else
 | 
						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_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
 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -90,13 +91,14 @@ function wish_append_left() {
 | 
				
			|||||||
function wish_append_right() {
 | 
					function wish_append_right() {
 | 
				
			||||||
	local text="$2"
 | 
						local text="$2"
 | 
				
			||||||
	local colors="$1"
 | 
						local colors="$1"
 | 
				
			||||||
 | 
						local prompt_text="${text@P}"
 | 
				
			||||||
	if [[ $text == "\n" ]]; then
 | 
						if [[ $text == "\n" ]]; then
 | 
				
			||||||
		((WISH_RPLINE++))
 | 
							((WISH_RPLINE++))
 | 
				
			||||||
		WISH_RIGHT_PS1=("${WISH_RIGHT_PS1[@]}" "")
 | 
							WISH_RIGHT_PS1=("${WISH_RIGHT_PS1[@]}" "")
 | 
				
			||||||
		WISH_RPL=(${WISH_RPL[@]} 0)
 | 
							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_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
 | 
						fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user