@@ -686,13 +686,14 @@ _agkozak_async_init() {
686686# #####################################################################
687687
688688# ###########################################################
689- # Strip color codes from a prompt string
689+ # Strip color codes from a prompt string and put the result
690+ # on the editing buffer stack
690691#
691692# Arguments:
692- # $1 The prompt string
693+ # $1 Name of prompt string variable (PROMPT or RPROMPT)
693694# ###########################################################
694695_agkozak_strip_colors () {
695- local prompt=$1
696+ local prompt=${(P)1} newprompt
696697 local open_braces
697698
698699 while [[ -n $prompt ]]; do
@@ -710,11 +711,13 @@ _agkozak_strip_colors() {
710711 ;;
711712 %f* |%k* ) prompt=${prompt#% [fk]} ;;
712713 * )
713- print -n -- " ${prompt: 0: 1} "
714+ newprompt+= " ${prompt: 0: 1} "
714715 prompt=${prompt# ?}
715716 ;;
716717 esac
717718 done
719+
720+ print -nz -- " ${(qq)newprompt} "
718721}
719722
720723# ###########################################################
@@ -828,15 +831,19 @@ _agkozak_precmd() {
828831 typeset -g AGKOZAK_CURRENT_CUSTOM_PROMPT=${AGKOZAK_CUSTOM_PROMPT}
829832 PROMPT=${AGKOZAK_CUSTOM_PROMPT}
830833 if ! _agkozak_has_colors; then
831- PROMPT=$( _agkozak_strip_colors " ${PROMPT} " )
834+ _agkozak_strip_colors ' PROMPT'
835+ read -rz PROMPT
836+ PROMPT=${(Q)PROMPT}
832837 fi
833838 fi
834839
835840 if [[ ${AGKOZAK_CUSTOM_RPROMPT} != " ${AGKOZAK_CURRENT_CUSTOM_RPROMPT} " ]]; then
836841 typeset -g AGKOZAK_CURRENT_CUSTOM_RPROMPT=${AGKOZAK_CUSTOM_RPROMPT}
837842 RPROMPT=${AGKOZAK_CUSTOM_RPROMPT}
838843 if ! _agkozak_has_colors; then
839- RPROMPT=$( _agkozak_strip_colors " ${RPROMPT} " )
844+ _agkozak_strip_colors ' RPROMPT'
845+ read -rz RPROMPT
846+ RPROMPT=${(Q)RPROMPT}
840847 fi
841848 fi
842849}
@@ -894,8 +901,12 @@ _agkozak_prompt_string () {
894901 fi
895902
896903 if ! _agkozak_has_colors; then
897- PROMPT=$( _agkozak_strip_colors " $PROMPT " )
898- RPROMPT=$( _agkozak_strip_colors " $RPROMPT " )
904+ _agkozak_strip_colors ' PROMPT'
905+ read -rz PROMPT
906+ PROMPT=${(Q)PROMPT}
907+ _agkozak_strip_colors ' RPROMPT'
908+ read -rz RPROMPT
909+ RPROMPT=${(Q)RPROMPT}
899910 fi
900911}
901912
0 commit comments