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

Ooh, I didn't know about `mp3splt`! This is super helpful, thanks for posting it.

> It's something I strongly recommend: store off-used CLI calls in your notes/personal wiki.

All of my bash commands from any terminal get piped into a separate, unified history file, copying some setup I read about in a blog a long time ago. It's an easy, dumb setup that just works. I've been using it for years without any performance problems, and if I ever get any, I can just archive the current text file and start over with a fresh one.

Having access to past commands is really handy and has saved my butt multiple times.

  log_bash_persistent_history()
  {
      [[
          $(history 1) =~ ^\ *[0-9]+\ +([^\ ]+\ [^\ ]+)\ +(.*)$
      ]]
      local date_part="${BASH_REMATCH[1]}"
      local command_part="${BASH_REMATCH[2]}"
      if [ "$command_part" != "$PERSISTENT_HISTORY_LAST" ]
      then
          echo $date_part "|" "$command_part" >> ~/.persistent_history
          export PERSISTENT_HISTORY_LAST="$command_part"
      fi
  }

  # Stuff to do on PROMPT_COMMAND
  run_on_prompt_command()
  {
      log_bash_persistent_history
  }

  PROMPT_COMMAND="run_on_prompt_command"
  HISTTIMEFORMAT="%d/%m/%y %T "
  alias phgrep='cat ~/.persistent_history|grep --color'
  alias hgrep='history|grep --color'



Thanks for this. This solves my tmux / history problem. Commands from one open terminal were not available in the history command for the other terminal, if I had two terminals open.


Too tired to try it and port if necessary yet, but I'd like to ask: does it work on ZSH?


I've never used ZSH, so I don't know.

My instinct says that if you'd run into any problems, it would be with this line:

  PROMPT_COMMAND="run_on_prompt_command"
Maybe ZSH has a different API? Again though, I've always just used bash, so you'd have to try it and see.




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

Search: