Hacker News new | past | comments | ask | show | jobs | submit login
Save your local shell history to log files (justinjoyce.dev)
4 points by justinjoyce on April 7, 2023 | hide | past | favorite | 1 comment



Are there any shell-agnostic ways of doing this? I tend to bounce between zsh, fish, although fish has been sticking lately so a fish version of this would be amazing.

nevermind, managed to get this working for fish, just add it to the end of your ~/.config/fish/config.fish file :)

  # log every command
  function cmd_log --on-event fish_preexec
    if test (id -u) -ne 0 # if we're already sudo, don't log
      echo $(date "+%Y-%m-%d.%H:%M:%S"): $(pwd): $argv >> ~/.logs/cmd-history-$(date "+%Y-%m-%d").log
    end
  end
And, since I keep editing this comment... blog post about it with all credit to OP and OP's inspiration

https://bryan-lott.github.io/log-all-commands/




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

Search: