here-here is like history
but it saves the time you ran a command and the directory you were in when you ran it.
Running here
tells you all the commands you ran in this directory even if you were on a different server.
I commonly wonder how I made a file (and maybe why). Sometimes I try looking in my history (using the history
command).
This makes that easier by clearing out some of the noise.
If you want to use this, be my guest but, as much as I can, I deny all liability if this does any damage.
This seems to work on Mac OSX and Ubuntu using bash
and zsh
.
- Copy
save_history
andhere
somewhere in yourPATH
(e.g.~/.local/bin
) - Make them executable (e.g.
chmod u+x ~/.local/bin/here ~/.local/bin/save_history
) - Do one of the following:
- If you use bash (you probably do if you're not sure), run
echo 'PROMPT_COMMAND="history | tail -1 | save_history $OLDPWD"' >> ~/.bashrc
- If you use zsh, run
echo 'precmd() { history | tail -1 | save_history $OLDPWD }' >> ~/.zshrc
- If you use bash (you probably do if you're not sure), run
- Restart you terminal (e.g. close the window and open another one)
History logs are stored in ~/.here-history
with a new file per host (i.e. server) and day. Each line contains:
- The time you ran the command
- The server (or laptop) you ran the command on
- The terminal you ran the command in (if you have multiple windows open)
- The directory you ran the command in
- The git commit reference at the time (if the directory is a git repo, otherwise
-
) - The command you wrote
You can download all the history from different servers into one place reasonably safely because the files include a hash of the server hostname. You can then analyse the logs to work out roughtly what version of the code you were running when you made your great discovery and where you were running it at the time.
I wrote this 4 years ago, stopped using it when I changed job and have just resurrected it. I have no idea where I got the idea or the basis of the code from.
That said, I worked with some really smart people at the Sanger Institute at the time so I suspect Andrew Page, Simon Harris (Simon has disclaimed all responsibility) or
Martin Hunt were involved somehow because this looks like their level of geekiness. Then again, maybe not.
If you want to make this better then please do. Please let me know if you have any suggestions for how it can be improved. I'd like it to remain compatible with OSX and Ubuntu and Bash and ZSH as a minimum.
Here are some of the improvements I like the sound of but don't have time to implement:
- Show when you ran the command
- Show commands in subdirectories
- Sometimes it gets confused and tells you that you ran the last command more times than you did
- Be more efficient (I'm surprised this works and there are reports
history | tail -1
gets slow when you have a lot of history) - Collect history from other servers automagically