(Old news, but in case someone lands here looking for it, how I did it)
OP seems to be looking for syntax !#[X][-Y] zsh
where X and Y are the indices for shell words in the story event for the current row
It is assumed that X and Y refer to the beginning or end of the line - respectively - when lowering
(keep in mind that the end of the line in this context is actually a call event !#[X][-Y] per line)
this gives us the following options:
in a direct answer to an example:
mkdir tmp && cd !
or, taking another step:
alias mktmpd='mkdir -p tmp /tmp/${PWD:t}; cd ${(@)${~:-${=^:-!#2-3}(N/)}[1]}; pwd; ls'
the path /tmp/${PWD:t} will also be created and act as an alternative to cd if for any reason ./tmp cannot be created (which could fail)
this assumes the user can mkdir in /tmp and wants some useless paths to be generated (and left untouched) when ./tmp perfectly used and actually selected
there is a potential problem when /tmp/${PWD:t} already exists and its contents are not connected or broken, therefore pwd; ls pwd; ls
aliasing helps with cases such as somecommand; mktmpd somecommand; mktmpd , where usually #! 2-3 will no longer refer to the corresponding parameters tmp /tmp/${PWD:t}
Note, however, that I strongly do not advocate this use case as particularly useful (or even its suitability as an example, actually), but I wanted to point out the peculiarity of the alias, since I had not yet seen its mention elsewhere)
source share