I set up my bash config to store history separately for each working directory (ie separate history files that I store under a $HOME/.bash_history_d directory) – so as I cd into a project directory, the history is populated with the commands that I've run within that directory . I find this super-helpful to remind me of the context for projects – cd in, then up-arrow to whatever that command is I usually run to launc…
Better Bash History (2012)
21–30 of 85 posts
Re: Better Bash History (2012)
#22export HISTFILE="${HOME}/.bash_history.$(hostname)"
Re: Better Bash History (2012)
#23I set up my bash config to store history separately for each working directory (ie separate history files that I store under a $HOME/.bash_history_d directory) – so as I cd into a project directory, the history is populated with the commands that I've run within that directory . I find this super-helpful to remind me of the context for projects – cd in, then up-arrow to whatever that command is I usually run to launc…
Thus, all of the `cd` commands that get written to my history use absolute paths and are re-usable no matter where I am.
It would be cool if this sort of functionality were generalizable to all commands where you type a relative path, not just `cd`.
https://github.com/dasl-/settings/blob/3143bbfe23bd75c3e35c7...
Re: Better Bash History (2012)
#24Using PROMPT_COMMAND to log every command in a separate timestamped log file. This allows you to use a much better format than bash history has to be in.
Easily readable to see what you've been doing and extremly efficient to grep for.
Has been discussed on HN before: https://news.ycombinator.com/item?id=11806553
Re: Better Bash History (2012)
#25I set up my bash config to store history separately for each working directory (ie separate history files that I store under a $HOME/.bash_history_d directory) – so as I cd into a project directory, the history is populated with the commands that I've run within that directory . I find this super-helpful to remind me of the context for projects – cd in, then up-arrow to whatever that command is I usually run to launc…
I use zsh, and I have a thing in my profile that skips writing any `cd` command to history. Instead, it will rewrite the command using the absolute path of the directory I `cd`'d into and write that to history. Thus, all of the `cd` commands that get written to my history use absolute paths and are re-usable no matter where I am. It would be cool if this sort of functionality were generalizable to all commands where…
Re: Better Bash History (2012)
#26I set up my bash config to store history separately for each working directory (ie separate history files that I store under a $HOME/.bash_history_d directory) – so as I cd into a project directory, the history is populated with the commands that I've run within that directory . I find this super-helpful to remind me of the context for projects – cd in, then up-arrow to whatever that command is I usually run to launc…
I use zsh, and I have a thing in my profile that skips writing any `cd` command to history. Instead, it will rewrite the command using the absolute path of the directory I `cd`'d into and write that to history. Thus, all of the `cd` commands that get written to my history use absolute paths and are re-usable no matter where I am. It would be cool if this sort of functionality were generalizable to all commands where…
This isn't specific to `cd` commands either. It's useful if you are `rsync`ing different directories to different places, or checkout different `git` branches, etc.
Re: Better Bash History (2012)
#27I set up my bash config to store history separately for each working directory (ie separate history files that I store under a $HOME/.bash_history_d directory) – so as I cd into a project directory, the history is populated with the commands that I've run within that directory . I find this super-helpful to remind me of the context for projects – cd in, then up-arrow to whatever that command is I usually run to launc…
I do something similar, but instead of current directory I have a notion of context that is carried by an environment variable set in a GNU screen process (and therefore inherited by its children) which drives logic in my .bashrc. https://github.com/dlthomas/config-files
Re: Better Bash History (2012)
#28I set up my bash config to store history separately for each working directory (ie separate history files that I store under a $HOME/.bash_history_d directory) – so as I cd into a project directory, the history is populated with the commands that I've run within that directory . I find this super-helpful to remind me of the context for projects – cd in, then up-arrow to whatever that command is I usually run to launc…
My particular configuration is at https://github.com/YenTheFirst/dotfiles/blob/master/.bash_cd...
90% of the time, the bash history is super relevant to the current context. A small amount of the time, I remember that I issued a command, but not in which directory - in these cases, I can just search the history directory, and get both the context of what the command was, and also where I was when I originally issued it.
Re: Better Bash History (2012)
#29 promptFunc() {
# right before prompting for the
# next command, save the previous
# command in a file.
echo "$(date +%Y-%m-%d--%H-%M-%S) \
$(hostname) $PWD $(history 1)" \
>> ~/.full_history
}
PROMPT_COMMAND=promptFunc
This is in addition to standard bash history, and is much more reliable. Being able to see not only what command I ran but what directory I was in and when I ran it is very useful.(I wrote about this here: https://www.jefftk.com/p/you-should-be-logging-shell-history)
Re: Better Bash History (2012)
#30The unique thing is that I use a [python script (in my dotfiles)][1] to clean the history in a more advanced way than is possible with HISTIGNORE.
The script removes duplicates, leaving the most recent copy and removes lines matching several regexes.
[1]: https://github.com/naggie/dotfiles/blob/master/scripts/clean... [2]: https://github.com/naggie/dotfiles/blob/master/home/.bashrc#...