Skip to content

Instantly share code, notes, and snippets.

@nickp60
Last active June 14, 2018 14:35
Show Gist options
  • Save nickp60/9cb57e64019dc0edc8a037078dbf098b to your computer and use it in GitHub Desktop.
Save nickp60/9cb57e64019dc0edc8a037078dbf098b to your computer and use it in GitHub Desktop.
kptrk: KeeP TRacK of your shell comamnds
# The purpose of this script it to make working from the terminal a bit more reprodicible.
# It is very simple
# A boolean value (KPTRK_ON) is set to true when kptrk is invoked, and the current directory is recorded.
# when kptrk is invoked again, logging is turned off.
# it is built on top of https://github.com/rcaloras/bash-preexec
# Installation
# - install bash-pre-exec, see instructions here https://github.com/rcaloras/bash-preexec, or, in short:
# -- Pull down our file from GitHub and write it to our home directory as a hidden file.
# curl https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh -o ~/.bash-preexec.sh
# -- Source our file at the end of our bash profile (e.g. ~/.bashrc, ~/.profile, or ~/.bash_profile)
# echo '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> ~/.bashrc
# - Then, add the function below to the bottom of your bash profile, and then source it.
# usage:
# - calling kptrk toggles on and off.
# Features
# - any command used while kptrk is on is logged with the date and time to a
# file in your working directory called kptrk_README
# - because the working direcory is set when you invoke kptrk, you are free to move
# anywhere: your commands will keep logging to the same readme file
# exiting
# just call kptrk again; you should se a message that informs you kptrk is disabled
kptrk(){
source ~/.bash-preexec.sh
if [ "$KPTRK_ON" = true ]
then
echo "KeePTRacK is disabled" ;
preexec() { echo "" ; }
precmd() { echo "" ; }
export KPTRK_ON=false
export KPTRK_DIR=0
else
export KPTRK_DIR=`pwd`
echo "KeePTRacK is enabled!"
preexec() { echo "`date`\t$1 ">> $KPTRK_DIR/kptrk_README ; }
precmd() { echo "kptrk is on" ; }
export KPTRK_ON=true
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment