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

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



On Sep 21, 12:37pm, Sebastian Gniazdowski wrote:
}
} Ah no it doesn't help, it simply doesn't match at all and repeat output ...

I suspect we've mis-communicated somehow.

I made up the little test script appended at the end of this message.
It copies you gitcmd from workers/39403 but modified a little to put
markers around the five bits of output [1|one][2|two][3|three]...

Then it applies first your all-in-one substitution from workers/39403
(with double close brace after $match[2]) my suggested all-in-one
(with double close brace after $match[5]) from workers/39404 and my
for-loop (pattern tweaked to more closely match 39403, before I was
using the pattern from minimal4.zsh that you sent earlier).

What specifically is wrong ("doesn't match at all") with the latter two?

--- 8< -- snip -- 8< ---
#!/usr/bin/env zsh

emulate -LR zsh
setopt extendedglob

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

CMDR_GREEN='{G>'
CMDR_GREEN_E='<G}'
CMDR_MAGENTA='{M>'
CMDR_MAGENTA_E='<M}'

print -rl -- INPUT: "${gitout[@]}" ""

sebastian_out=(
"${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]}" )

print -rl -- +++++++++++++
print -rl -- workers/39403: "${sebastian_out[@]}"

bart_out=(
"${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]}}" )

print -rl -- +++++++++++++
print -rl -- workers/39404: "${bart_out[@]}"

integer i
for ((i=$#gitout; i ; i--)) {
  gitout[i]="${gitout[i]//(#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]}}"
}

print -rl -- +++++++++++++
print -rl -- for-loop: "${gitout[@]}"
--- 8< -- snip -- 8< ---



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