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

Re: Prepend/append to the members of a list



On Oct 30,  6:09pm, Jörg Sommer wrote:
}
} % ls !ls*:(s/^/dir/)
} 
} But it does not work, because the s/// expression doesn't know ^.

Even if history substitution did understand beginning-of-word, that
still wouldn't work.  You'd at the least need :gs and some character
other than slash as the separator.

Usually in this situation I would do something like

% (cd dir; !ls )

Nikolai's suggestion can be tweaked to not require rcexpandparam:

% a=( !ls:* ); ls dir/$^a

Or this:

% ls dir/${^$(echo !{ls:*:q})}

} Or another example:
} 
} % cp dir/*.[1-9](:t:s+^+/usr/share/man/man?/+:s/$/.gz/) .

There you're in a bit of a pickle because you're using history modifiers
on a glob pattern, which is even more limited.  I believe the closest
you'd get without pain [#] is:

% cp /usr/share/man/man?/${^$(echo dir/*.[1-9](:t)}.gz .

which isn't that much uglier than what you constructed.

Of course, if you do this specific thing often you can do

% function mangz { reply=(/usr/share/man/man?/$REPLY:t.gz) }
% cp dir/*.[1-9](+mangz) .

[#] Pain is safely quoting special characters in the file name:

% cp /usr/share/man/man?/${^$(echo dir/*.[1-9](:te.'reply=${(q)REPLY}'.))}.gz .

-- 



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