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

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



Hello,
I get an output from git log. It has $'\1' (Ctrl-A), $'\2' (Ctrl-B),
etc. embedded.

Here is how I process the output:

# 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. Output is:

^C15f1acd^Y 'Updated README.md'


While it should be:

^C15f1acd^Y 'Updated README.md' > (HEAD -> master, origin/master)<
^E'4 days ago'^Y Sebastian Gniazdowski

I.E. (HEAD -> master, ...) is something that stops output. However, if
I assign identical input to an array "a" - BY HAND:

a=( "15f1acd"$'\1'"Updated README.md"$'\2'" (HEAD -> master,
origin/master)"$'\3'"4 days ago"$'\4'"Sebastian Gniazdowski" )

and then copy from Git output:

a[2]="${gitout[1]}"

and even compare:

[ "$a[1]" = "$a[2]" ] && echo equal >> /tmp/reply || echo "not equal"
>> /tmp/reply

I get:
- "equal" – compare shows strings are equal
- output:

^C15f1acd^Y 'Updated README.md'
^C15f1acd^Y 'Updated README.md' > (HEAD -> master, origin/master)<
^E'4 days ago'^Y Sebastian Gniazdowski

I.E. Identical input is once interrupted before the "( HEAD -> master,
... )", once processed correctly.


PS. The git command is:

gitcmd=( git -C "${ZCMDR[current_project]}" log --max-count=3
--pretty=format:'%h%x01%s%x02%d%x03%cr%x04%an' --abbrev-commit )
gitout=( "${(@f)"$( "${gitcmd[@]}" )"}" )

Best regards,
Sebastian Gniazdowski



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