Hacker News new | past | comments | ask | show | jobs | submit login

Can you also add the working directory in which each command was run?



You could deduce the working directory from the sequence of commands in your history file, so the working directory is implicitly contained in the history file.

I don't remember an option to save the working directory explicitly. But zsh has a number of history related commands, which can be used to execute shell functions before and after each command. So you could use these to write your own special history file, even one per directory if need. Example:

   zshaddhistory () { echo "$PWD  -- $1" >> $MY_HISTFILE }
This shell function defined here will run when the command has been read but just before it will be executed. The argument $1 contains the command line to be executed.


> You could deduce the working directory from the sequence of commands in your history file, so the working directory is implicitly contained in the history file.

I didn't think of that, but I don't think it's always possible. E.g. suppose you run "source somefile", and somefile contains a cd command.

Unfortunately I'm using bash mostly, so I'm afraid the suggestion you gave for zsh doesn't work for me.

By the way, another thing I'm interested in is how people manage their history files over multiple machines.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: