Re: selective command history

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 17Sep2010 13:23, suvayu ali <fatkasuvayu+linux@xxxxxxxxx> wrote:
| On 17 September 2010 12:45, Andy Blanchard <zocalo@xxxxxxxxx> wrote:
| > Can you boil the commands that you don't want included in the history
| > file to a series of regular expressions such as the following:
| >
| >   ^cd
| >   ^ls
| >   ^rm
| >
| > If so, you can create a list of these regular expressions in a file,
| > then use the ~/.bash_logout script to clean up the history:
| 
| This is an excellent idea! I'll give this a shot. Coming up with the
| proper regex shouldn't be too difficult.

For myself, solving not-quite-your-problem, I contrive to log my
commands with a timestamp to an entirely separate history file
(~/var/log/shell), thus:

  : 20091119T115602; time ./backup-root-spare.sh
  : 20091119T115656; cd /opt

Just as many users have an alias "h=history" I also have small shell
function:

  hh()
  { grepall ${1+"$@"} <"$LOGDIR/shell"
  }

to search this file. (Grepall's a small script to look for lines
containing all words on the command line, so:

  [home/cameron]janus*> hh root spare
  : 20091119T115505; less backup-root-spare.sh
  : 20091119T115602; time ./backup-root-spare.sh

This means I don't care above preventing particular commands getting
into my history because I have an easy way to search the history
quite selectively.

The neat thing about that log format is that ":" is a legitimate shell
command, so I can cut/paste the whole line to reuse it instead of aiming
more precisely:-)

I'm doing this with zsh, which has a handy function it runs just before
every command is issued. I'd like to know if bash has similar, since I'm
force to use bash on some systems (notably recent Fedora, when my env
trips a memory issue in zsh somehow). Zsh runs preexec() before each
command, so I have:

  preexec()
  {
    loghistory "$1"
    ttyl "$1"
    last_cmdline=$1
    [ -n "$_slavefd" ] && toslave "$3"
  }

where loghistory is:

  loghistory()
  {
    _lh_line=": `date +%Y%m%dT%H%M%S`; $*"
    ##echo -E "$_lh_line" >>"$BASH_HISTFILE"      # give up trying to support bash's stupid history
    if [ -n "$LOGDIR" ] && [ -d "$LOGDIR/." ]
    then  echo -E "$_lh_line" >>"$LOGDIR/shell"
    fi
  }

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

You don't stop riding because you get old, you get old because you stop
riding.         - Anon. on rec.motorcycles
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux