News for hackers. Stuff that matters.
Re:Save your local shell history to log files by mystickphoenix on Saturday April 08, 2023 @09:55AM (#35493133)
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