-
-
Save mrhaw/ceb7d666f6a8018a2416 to your computer and use it in GitHub Desktop.
Michael Hoffman's crazy bash_history backer upper on git
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
1 - Create a *private* GitHub/Bitbucket or similar git repo. Here I assume the repo is: | |
https://github.com/calkan/bash_history.git | |
2 - Create .history directory and initialize it for the repo: | |
mkdir $HOME/.history | |
cd $HOME/.history | |
git init | |
touch README.md | |
git add README.md | |
git commit -m "first commit" | |
git remote add origin https://github.com/calkan/bash_history.git | |
git push -u origin master | |
3 - Make it password-free (no need to worry, still others can't reach it unless they have access to your .history) | |
chmod 700 $HOME/.history | |
git config credential.helper store | |
git push -u origin master | |
4 - Add the following lines to your $HOME/.bashrc - Michael's crazy BASH trick: | |
HOSTNAME="$(hostname)" HOSTNAME_SHORT="${HOSTNAME%%.*}" | |
mkdir -p ${HOME}/.history/$(date -u +%Y/%m) | |
HISTFILE="${HOME}/.history/$(date -u +%Y/%m/%d.%H.%M.%S)_${HOSTNAME_SHORT}_$$" | |
5 - Activate your new environment variables: | |
source $HOME/.bashrc | |
6 - Add the following lines to your $HOME/.bash_logout | |
# write history file | |
history -a | |
# pull it, just in case if you logged out of another session, git will complain: | |
git --git-dir $HOME/.history/.git/ --work-tree $HOME/.history/ pull | |
# add HISTFILE | |
git --git-dir $HOME/.history/.git/ --work-tree $HOME/.history/ add $HISTFILE | |
# commit & push | |
git --git-dir $HOME/.history/.git/ --work-tree $HOME/.history/ commit -am "add $HISTFILE" | |
git --git-dir $HOME/.history/.git/ --work-tree $HOME/.history/ push | |
Logging out takes a second or two while committing to GitHub. It may be a good idea to find a way to disable this for cluster jobs, not sure if .bash_logout is invoked while terminating grid jobs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment