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

Re: Vared with newlines between array elements

Good tip.  I use:

# Use newlines to separate array elements in vared
alias vared='IFS="
" vared'


Peter Stephenson wrote:

> I just realised this trivial function is the answer to all my problems
> with editing path and similar array variables with vared --- it puts
> each element on a new line, so it's much easier to manipulate elements
> separately.
> To get filename completion to work properly, it should only require
> backslashes before newlines and not other whitespace, nor anything else.
> In other words, you get `/e/Program\ Files' from completion, but you
> need `/e/Program Files' because vared preserves the backslash.
> This could be fixed up if vared always stripped backslashes, which is
> more symmetric since it always doubles existing backslashes (i.e. if you
> had `/e/Program\ Files' to begin with it would have been quoted as
> `/e/Program\\ Files' for editing.  However, the function is buried
> inside the shell array splitting functions, so it's not entirely trivial
> to fix without knock-on effects.
> # Use vared with array elements joined by newlines.
> # This makes reordering or removal of elements much simpler.
> #
> # With this function whitespace other than newlines in array elements
> # should not be quoted by a backslash; this needs special completion
> # handling (not currently provided).
> local IFS='
> '
> vared "$@"
> # End

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