Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: associative array questions
On 2022-12-13 15:06, Bart Schaefer wrote:
It would work for the case where the array you want to rewrite is
Either you're not actually showing us what you're doing, or you're not
doing what you're telling us you are.
At the risk of making an ass of myself ... I'm quite at a loss, it
damned well did work. Tested 50 times, saved. Restored the backup and
... it doesn't work. Dunno, one of those glitches in the matrix. In
the wrong directory? Somehow created a real 'list'? It damned well
worked. But somehow ... I've been known to make edits in the wrong file
so what I'm editing and what I'm running ain't the same. I'm quite at a
loss. Anyway the good news is that you are not mistaken -- which would
be a serious difficulty. I consume enough of you guy's time, I can't
stand it when I'm totally wasting it barking up the wrong tree. My
apologies. Anyway it is working again ... this time with 'set -A' which
seems preferable besides it's expected to work. God knows. Here's the
whole function:
n_search ()
{
local list=$1 # Name of file buffer, no dollar sign idiot!!
# Begin a search.
if [[ ! "$SEARCHBUF" && ! "$prev_buffer" ]]; then
msg="Begin case insensitive search ... "
# There is no search, but there was in previous loop. i.e. we are
searching, but we have backspaced the search to 'all' so re-enter search
mode with virgin list:
elif [[ ! "$SEARCHBUF" && "$prev_buffer" ]]; then
prev_buffer=
msg="No search, keep trying or UP to return to the list ... "
# We are actively searching. Compute new list as each keystroke
filters more narrowly. ENTER or up/dn arrows end search. Note, buffer
can be preloaded when '$1' is given to nn_init(). But see 'c()' as an
example of the argument to the function NOT being wanted as an initial
search since that removes various heading lines.
elif [[ "$SEARCHBUF" && "$SEARCHBUF" != "$prev_buffer" ]]; then
prev_buffer="$SEARCHBUF"
# Lines below:
# 1) First remove lines starting with colon, they are messages.
# 2) Next do the filtering: Note that the search is not
incremental even tho it looks like it is -- the search is always in the
virgin list, else backspacing would require each previous search result
to be saved separately:
# 3) Now colorize the search string green. '#b': backreferences
active, '#i': case-insensitive.
###
# WORKS: (Tx Roman and Bart)
set -A $list "${(@MP)list:#^:*}"
set -A $list "${(@MP)list:#(#i)*$SEARCHBUF*}"
set -A $list
"${(@MP)list//(#bi)($SEARCHBUF)/$Color${match[1]}$nrm}"
msg="Filtering with: $SEARCHBUF"
fi
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author