I would like to be able to view my command history and know the context from which I issued the various commands - in other words, "in which directory have I been?" There are several ways to achieve this, but all of them (which I can think of) will require manipulating the zsh history to add (for example) a commented line with the result of $ (pwd). (I could create functions called cd, pushd and popd, etc., Or I could use the zsh preexec () function and possibly its period () function to add a comment line no more than every X seconds, just before I issue a command, or maybe there in some other way.)
The problem is that I do not want to directly manipulate the history file and bypass the shell history mechanism, but I cannot figure out a way (for example, using the fc command) to add something to the history without actually typing it on the command line. How can i do this?
source
share