Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

history should be customizable by the end user (HN thread summary) #320

andychu opened this issue May 31, 2019 · 3 comments


Copy link

commented May 31, 2019

This is a summary of Better Bash History discussion on HN

@emdash There is lots of interesting feedback here about history, including someone putting their history in an sqlite DB! Bash is crufty yet it's pretty amazing what people manage to hack on to it!

Some takeaways:

  • Implement $PROMPT_COMMAND because lot of people are using it!
  • Run fzf, lots of people are using it and like it.

Things people are doing:

  • per-directory history (how do you do this?) -- 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.
export PROMPT_COMMAND="history -a; check_cd; ${PROMPT_COMMAND:-:}"
  • I integrated all of these history options in my project Sensible Bash [1], an attempt at saner Bash defaults
  • I made an ebook [2] out of a series which appeared on this blog, titled “Unix as IDE”.
  • Because this comes up every so often, I'll post this link again: I wrote a little widget that stores your bash history in a sqlite db.
    • Before doing this, the only way I had to remember which commands/flags are needed to run something was to write it down in all kinds of notes files, personal wikis and so on. It was cumbersome, unorganized and time-consuming to reuse. With the .persistent_history file automatically populated by Bash from any terminal I'm typing into, and being kept in a Git repository for safekeeping, I have quick access to any command I ever ran.
  • FZF makes something you do hundreds of times a day (history and file opening on zsh, bash, fish, whatever) indisputably better.
  • I use zsh, and I have a thing in my profile ... that will rewrite the command using the absolute path of the directory I cd'd into. Thus, all of the cd commands that get written to my history use absolute paths and are re-usable no matter where I am


  • Bash's broken history is what finally got me to switch to Zsh.

Other interesting quotes, not about history:

  • 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.
  • 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 -- this is similar to the way I work

@andychu andychu changed the title history should be customizable by the end user history should be customizable by the end user (HN thread summary) May 31, 2019

This was referenced May 31, 2019


This comment has been minimized.

Copy link

commented May 31, 2019

Good resources, I will look at FZF. I had not heard of it.


This comment has been minimized.

Copy link
Contributor Author

commented May 31, 2019

OK thanks!

The thread helped clarify what I'd want in Oil for history:

Basically it should be a structured text file. Coincidentally I wrote this the other day because @drwilly is working on xargs, which also needs structured data:

The point is that you probably want history in SQL for two reasons:

  • Because you want to query history without parsing text (usually done incorrectly). That can be done with the simple TSV2 proposal. Oil will parse that so you don't have to, but you can also grep the file if you want.
  • For concurrency. I don't think this is a problem for append only files (although admittedly I wonder how HISTCONTROL=erasedups is implemented).

I think what'ss weird about bash history is this:

  • history is kept in a buffer in memory in each instance
  • on exit, the whole thing is appended to a file.

That's why it's so weird between "sessions"! At least I think so.

This thread also points to the benefit of having a real programming language in shell. Instead of a PROMPT_COMMAND string to evaluate, we could have a hook:

func whenCommandFinished(command_string, evaluated_argv, timestamp, status, elapsed_time, ...) {
  # do something yourself with history, like put it in a sqlite database, or upload it to your own server, etc.

This comment has been minimized.

Copy link

commented May 31, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.