Declined History: show in which directory a command has been typed.

May 20, 2009
I would like to see in the history also the directory in which I was working when I typed a command.
For example, now in the history log I can find that I typed a command such as "erase filename".
But it was in the test directory and so I removed just a test file, or it was in a very important directory?

Thank You very much and regards

Rodolfo Giovanninetti

Charles Dye

Super Moderator
Staff member
May 20, 2008
Albuquerque, NM
And what would you see when you recalled a command with up-arrow?
Just the command.

I don't see any reason why the history mechanism couldn't save the current directory along with each command. I think it would eat memory, though. Users are able to delete history entries, so it wouldn't be as simple as just having a null "ditto" entry for commands where the CWD hasn't changed.
May 20, 2008
Syracuse, NY, USA
I don't remember ever wanting to know the CWD when a command from the past was executed. And I don't want see that every time I open the history popup. It's easy enough to save that info (see below) but I'd expect to have to do a little work to see it. You can ...

Make a history log.

and use
alias pre_exec `echo CWD: %_cwd >> h:\4NTLogs\history.log`
You can always go back and see where you were when you did something.

v:\> tail h:\4NTLogs\history.log
CWD: V:\
cdd g:\tc24
CWD: G:\tc24
cdd c:\
CWD: C:\
CWD: V:\
echo foo
CWD: V:\
tail h:\4NTLogs\history.log
May 20, 2008
Syracuse, NY, USA
And if you really wanted it in the history recall, you could use something like one of these.

alias pre_exec `history /a CWD: %_cwd`

alias pre_exec `if "%_cwd" != "%cwdlast" (history /a CWD: %_cwd & set cwdlast=%_cwd)`