Bash's broken history is what finally got me to switch to Zsh. The history behavior you want is: 1. each line of history is appended incrementally, but 2. each shell session only has access to its own history unless you specifically reload the history into your session. Every combination of history commands in bash didn't do the right thing[1], but Zsh's works as desired. [1] eg. putting 'history -a' in PROMPT_COMMAN…
Better Bash History (2012)
31–40 of 85 posts
Re: Better Bash History (2012)
#32I do: 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…
Every developer should do this.
Re: Better Bash History (2012)
#33Earlier quoted context omitted.
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
Fish does this by default (and much more as well).
Specifically, I'm not sure what "this" is that fish does, as I described interaction of multiple pieces of software and I don't think fish includes a terminal multiplexer?
Re: Better Bash History (2012)
#34I 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…
Like, for example, would it handle this properly?
$ (cd /source;tar -cf - .) | (cd /dest;tar -xf -)
Re: Better Bash History (2012)
#35I 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 keep an infinite log by appending a timestamp to the beginning of the lines written to my history file, then merging this into a growing log with an hourly cronjob that runs sort -n | uniq on the file and the new version of the shell history. This way the shell history file is just a buffer. It doesn't get too big to cause corruption or other issues with reverse search on the command line. I just grep my way through the big history file to figure out what I was doing and when.
Re: Better Bash History (2012)
#36Re: Better Bash History (2012)
#37Earlier quoted context omitted.
Fish does this by default (and much more as well).
Could you elaborate? I can read docs, but it's not clear to me what correspondences you have in mind. Specifically, I'm not sure what "this" is that fish does, as I described interaction of multiple pieces of software and I don't think fish includes a terminal multiplexer?
Re: Better Bash History (2012)
#38You can implement some or all of the tips in this HN post, it'll make fzf results better.
Re: Better Bash History (2012)
#39Earlier quoted context omitted.
Could you elaborate? I can read docs, but it's not clear to me what correspondences you have in mind. Specifically, I'm not sure what "this" is that fish does, as I described interaction of multiple pieces of software and I don't think fish includes a terminal multiplexer?
autocompletion in fish takes into account the directory where you are at, so it will autocomplete commands ran in the same directory before other commands.
Re: Better Bash History (2012)
#40 shopt -s histappend is the default already I believe.
shopt -s cmdhist is also the default now.
HISTSIZE=-1 will be unlimited, which is fine for today's computers.