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

not mine (i stole it from someone else) but very useful bash prompt_func to store your entire bash history forever:

8<-----------------------------

  function prompt_func {
    CMDNUM=`history 1 | awk '{print $1}'`
    LAST_CMD=`history 1 | cut -f 3- -d ' '`

    if [ x$LAST_CMDNUM = xwho_knows ]; then
      LAST_CMDNUM=$CMDNUM
    fi

    if [ x$CMDNUM != x$LAST_CMDNUM ]; then
      FULL_CMD_LOG="$HOME/full-history/$(date "+%Y-%m-%d").log"
      echo "$(date '+%H:%M:%S') `munge_pwd` $LAST_CMD" >> $FULL_CMD_LOG
      LAST_CMDNUM=$CMDNUM
    fi
  }
  export PROMPT_COMMAND=prompt_func
  export LAST_CMDNUM=who_knows

  function fh() {
    grep -r --color=NEVER ${*} ~/full-history |
    sed 's/[^ ]* //' |
    sed 's/ \[[^]]\*\]/$/'
  }
8<-----------------------------

`munge_pwd` is another script that does various substitutions on the prompt (specific to how my work directories are laid out) but mostly you can just substitute `pwd` if you don't care about deduplicating stuff like multiple checkouts of the same project.




Not a script, but https://github.com/ellie/atuin does something similar


thanks! i've even searched for something like this in the past and come up blank.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: