I have a series of commands like
$ touch path/to/file.cc
$ less path/to/file.cc
...
and in the second command I'd like to automatically insert the path used in the previous command. Is there a way to do this in the shell? I use zsh, but would be interested in answers for bash or other shells.
What if the most recent command has two filepaths in it? Is there a good way to pick one? And what if there are commands between the current command and the most recently used command that contains a valid filepath?