Created
March 18, 2014 08:19
-
-
Save amirnissim/9615690 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # source | |
| https://www.facebook.com/notes/%D7%93%D7%96%D7%90%D6%B7%D7%A0%D7%90%D6%B7%D7%98%D7%94%D7%A2%D7%9F-%D7%9E%D7%99%D7%99/aachen-style-local-history-or-never-forget-what-you-did-ever-again/10152290882464430 | |
| This comes from Carmen Heger and Sasa Hasan, by way of Aachen, where Arne Mauser was the apparent originator. Please feel free to share this but cite them (not me, unless you want to cite this specific note). If you want to skip to the instructions they're at the bottom. | |
| The idea is a .history file is created in every directory you work in with the list of all the commands you typed (except for a few that match a list of boring stuff like ls). | |
| This is if you want to save yourself the trouble of cut-and-pasting into a README in each directory. I still do that, actually, but this functions as a readme of last resort. It's also great for seeing what steps others have done if you're trying to debug their inability to reproduce your results. | |
| example: | |
| [jonmay@Jonathan-Mays-MacBook-Pro demo]$ echo "README: this is a demonstration" | |
| [jonmay@Jonathan-Mays-MacBook-Pro demo]$ time | |
| [jonmay@Jonathan-Mays-MacBook-Pro demo]$ whoami | |
| [jonmay@Jonathan-Mays-MacBook-Pro demo]$ mkdir foo | |
| [jonmay@Jonathan-Mays-MacBook-Pro demo]$ cd foo | |
| [jonmay@Jonathan-Mays-MacBook-Pro foo]$ echo "README: this is where i'm going to do my secret work" | |
| [jonmay@Jonathan-Mays-MacBook-Pro foo]$ for i in `seq 1 10`; do echo $i $((i/2)); done | sed s'/0/h/g' > blarg | |
| [jonmay@Jonathan-Mays-MacBook-Pro foo]$ cd .. | |
| [jonmay@Jonathan-Mays-MacBook-Pro demo]$ cat .history | |
| 2014-01-16.17-39-12.Jonathan-Mays-MacBook-Pro.local echo "README: this is a demonstration" | |
| 2014-01-16.17-39-16.Jonathan-Mays-MacBook-Pro.local time | |
| 2014-01-16.17-39-20.Jonathan-Mays-MacBook-Pro.local whoami | |
| 2014-01-16.17-39-26.Jonathan-Mays-MacBook-Pro.local mkdir foo | |
| [jonmay@Jonathan-Mays-MacBook-Pro demo]$ cat foo/.history | |
| 2014-01-16.17-39-43.Jonathan-Mays-MacBook-Pro.local echo "README: this is where i'm going to do my secret work" | |
| 2014-01-16.17-40-41.Jonathan-Mays-MacBook-Pro.local for i in `seq 1 10`; do echo $i $((i/2)); done | sed s'/0/h/g' > blarg | |
| Instructions: Put this in your bashrc/bash_profile (i'm never clear on which one, even after reading this http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html) | |
| # awesome aachen history stuff | |
| # what not to report on | |
| alias useHistory='grep -v "^ls$\|^ll$\|^l$\|^dir$\|^cd \|^h$\|^gh$\|^h \|^bg$\|^fg$\|^qsm$\|^quser$\|^cStat\|^note \|^mutt\|^std " | wc -l' | |
| # convenience cmd for searching: h blah => anything matching blah in current local history | |
| alias h='cat .history | grep --binary-file=text ' | |
| # the meat | |
| function myLocalHistory() | |
| { | |
| # if you've got permission | |
| if [ `ls -ld "$PWD" | awk '{print $3}'` == "$USER" ] ; then | |
| # steal the last line from history | |
| HISTORYLINE=`history | tail -1 | sed 's:^ *[0-9]* *::g'` | |
| # filter through the alias above. append the date and computer name and add it to the local history | |
| if [ `echo $HISTORYLINE | useHistory` == 1 ] ; then | |
| (((date +%F.%H-%M-%S.;uname -n) | tr -d '\n' ; echo " $HISTORYLINE") >>.history) 2>/dev/null | |
| fi | |
| fi | |
| } | |
| # always run it | |
| export PROMPT_COMMAND="myLocalHistory" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment