All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.onerussian.com.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 #emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil -*-
2 #ex: set sts=4 ts=4 sw=4 noet:
4 #-------------------------- =+- Shell script -+= --------------------------
5 # @file .bashrc_history.sh
6 # @date Thu Mar 10 14:02:36 2005
9 # Created: Thu Mar 10 14:02:36 2005
11 # Yaroslav Halchenko CS@UNM, CS@NJIT
12 # web: http://www.onerussian.com & PSYCH@RUTGERS
13 # e-mail: yoh@onerussian.com ICQ#: 60653192
15 # DESCRIPTION (NOTES):
16 # A script to be sourced from .bashrc to provide ways to archive all the
17 # actions in infinitely long history file.
20 # '[ -r ~/.bashrc_history ] && source ~/.bashrc_history' in ~/.bashrc
23 # # to exit through calling exit function which will archive the history
24 # # next ones are optional: first is left for historical reasons
25 # "\C-x\C-x": "exit\n"
26 # "\C-x\C-w": "archive_history\n"
27 # $endif' in ~/.inputrc
29 # Then whenever you close bash (exit,logout or exit by pressing Ctrl-D
30 # or Ctrl-X twice you will have a piece of current history added to
31 # ~/.bash_history.archive
33 # Thanks to Philippe Teuwen for the comments and "patches"
35 # SOURCE (might be outdated):
36 # http://www.onerussian.com/Linux/.files/.bashrc_history
39 # Released under GNU Generic Public License. You should've received it with
40 # your GNU/Linux system. If not, write to the Free Software Foundation, Inc.,
41 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
42 #-----------------\____________________________________/------------------
44 # For easy migration under modular bash configuration (after madduck's
45 # zsh configuration) -- if we find older archive file and now HISTFILE
46 # points to $HOME/.var, we need to move things around
47 if [ "$HISTFILE" != "" ] && [ "$PS1" ] \
48 && [ -f $HOME/.bash_history ] && [ "$BASH_VARDIR" = "$HOME/.var/bash" ]; then
49 if [ ! -f "$BASH_VARDIR/history" ] ; then
50 echo -e "I: Found previousely allocated history files.\n Moving them under $BASH_VARDIR"
51 for f in $HOME/.bash_history*; do
52 mv "$f" "${f//.bash_/.var/bash/}"
55 echo -e "I: New layout of history files also found.\n Please remove/propagate old history into new"
59 if [ "$PS1" ] ; then # interactive shell
60 export STARTTIME="`date '+%Y-%m-%d %H:%M:%S'`" \
62 HISTTIMEFORMAT='%F %T '
63 shopt -s cmdhist histappend
65 # Next function really stores the history logs. Besides that if you want to store whatever you have so far
66 # you can call this function and it will save increment from the last call to it.
69 TFILE=${HISTFILE}.$$.temp
70 CURTIME=`date '+%Y-%m-%d %H:%M:%S'`
73 HISTORYDUMP=$(($HISTORYDUMP+1))
75 echo "#$USER@${HOSTNAME} [ ${STARTTIME} - ${CURTIME} ]:$HISTORYDUMP ($CURTTY) ----" >| $TFILE
78 # Append it to the archive
79 #cat ${TFILE} >> ${HISTFILE}.archive
80 which gawk >/dev/null \
81 && awk '/^#[0-9]+$/{print strftime("#%F %T ", gensub(/#/,"","g")) }//' ${TFILE} >> ${HISTFILE}.archive \
82 || cat ${TFILE} >> ${HISTFILE}.archive
84 # Adjust history file itself
85 # of cause we need to dump to some temp file and then rename... he heh
86 cat ${HISTFILE} ${TFILE} | tail -${HISTSIZE} >| ${HISTFILE}.$$
87 mv -f ${HISTFILE}.$$ ${HISTFILE}
88 # clean up after yourself - to be absessive remove the other tmp file as well -
89 # - might happen if there were no permission to move it at above point
90 rm -rf ${TFILE} ${HISTFILE}.$$
93 trap 'archive_history' EXIT HUP
98 # ---------------{ some shortcuts }---------------------
101 grep "$@" ${HISTFILE}.archive
106 grep -h "$@" ${HISTFILE}.archive{,s/.*}