Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] String equal when compared, processed differently via //



On Sep 21, 10:57am, Sebastian Gniazdowski wrote:
} Subject: [BUG] String equal when compared, processed differently via //
}
} # hash     \1 message  \2 repo info \3 date     \4 author
} # match[1]    match[2]    match[3]     match[4]    match[5]
} gitout=( "${gitout[@]//(#b)([^$'\1']#)$'\1'([^$'\2']#)$'\2'([^$'\3']#)$'\3'([^$'\4']#)$'\4'(*)/${CMDR_GREEN}${match[1]}${CMDR_GREEN_E}
} ${(q-)match[2]}} >${match[3]}<
} ${CMDR_MAGENTA}${(q-)match[4]}${CMDR_MAGENTA_E} ${match[5]}" )
} 
} On input, there is:
} 
} 15f1acd^AUpdated README.md^B (HEAD -> master, origin/master)^C4 days
} ago^DSebastian Gniazdowski
} 
} On output, there should be:
} 
} ^C15f1acd^Y 'Updated README.md' > (HEAD -> master, origin/master)<
} ^E'4 days ago'^Y Sebastian Gniazdowski
} 
} THE THING IS: output string gets truncated after ^B in the input
} string.

If I replace your single gitout=( ... ) assignment with this loop --

integer i
for ((i=$#gitout; i ; i--)) {
    gitout[i]="${gitout[i]//(#b)([^$'\1']#)$'\1'([^$'\2']#)$'\2'([^$'\3']#)$'\3'([^$'\4']#)$'\4'(*)(#B)/${match[1]} ${(q-)match[2]}} >${match[3]}< ${(q-)match[4]} ${match[5]}"
}

-- then I get the output you expect (at least, on a zsh git tree).

I suspect it is because you are referencing $match[3] through $match[5]
outside the closing brace of the ${...//.../...} expression.  If I move
the 2nd closing brace from after ${(q-)match[2]} to place it after
${match[5]} instead, then to the best of my understanding I also get
the output you expect.

I looked at all the subsequent "minimal" examples from your follow-up
email and all of them have the 2nd closing brace after $match[2], so
they would all have suffered from this same problem.

That (I:2:) changes anything is mostly coincidental.

-- 
Barton E. Schaefer



Messages sorted by: Reverse Date, Date, Thread, Author