Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've been following a similar approach for a while. In bash, I have `HISTCONTROL=IGNOREBOTH` activated (or `setopt hist_ignore_space hist_ignore_dups` in zsh - most shells have an equivalent setting), and I just prepend most commands with a space. So only the more or less important stuff ends up in .bash_history or .zsh_history. This has the added nice effect that I don't accidentally trigger something destructive when I browse through my history.

I also spend most of my online life in incognito windows, at least for sites that don't absolutely require a login. This keeps my browser history clean from all the disposable pages that I only visit once, and I take care to do only the more meaningful stuff in a regular browser window.



  HISTCONTROL=ignoreboth
  HISTIGNORE='rm *:ls *:cd *:cp *:builtin *'
The history file has ALL the lines prefixed by space. I curate it a lot, with most frequent/recent commands near the end. And I add a lot of comments to the file so things are easily searched. And search for things, for example /rsync to find the rsync quick backup snapshot lines so first comes one with -n to check what it would do, then if it looks OK I press 'n' (vi mode) and get the same line without -n, or another 'n' and I get the same without -n and with --delete.

    (cd ~ && [ -d ~/backup_mnt/ ] && rsync    -xav --delete --exclude='backup_mnt' --exclude='.debug' --exclude='.cache' "$HOME" ~/backup_mnt/backup )   # rsync DELETE
    (cd ~ && [ -d ~/backup_mnt/ ] && rsync    -xav          --exclude='backup_mnt' --exclude='.debug' --exclude='.cache' "$HOME" ~/backup_mnt/backup )   # rsync NO DELETE
    (cd ~ && [ -d ~/backup_mnt/ ] && rsync -n -xav          --exclude='backup_mnt' --exclude='.debug' --exclude='.cache' "$HOME" ~/backup_mnt/backup )   # rsync LIST
For very long lines I always explain it in a comment.

When trying to modify a command, I remove the space, and when done I search for saving history and editing with '/_hi':

    history -a ; vi ~/.bash_history && history -r
and voila.

I also keep the similar lines aligned with spacing to note the differences quickly. (e.g. the -n above)

When exiting a shell and there's nothing interesting, history -r; exit

Also always I go to the end of the file before quitting vi so next time I'm where it last ended and before the appended new commands.

It takes work upfront and discipline but the everyday use of shell becomes very fast and clean.


Two prehensile thumbs up - your HISTCONTROL or

HISTIGNORE='m:??:info STARHERE:info:[bf]g:exit:[bf]g %[0-9]:help STARHERE:date:cal:cal ????:exec env ENV\STARHERE' (replace STARHERE with an asterisk)

generally works for me in bash(1).


Oh crazy, I didn’t know about this aspect of bash.

The line above set up automatic history ignoring for the colon-delimited shell globs; eg

fg %3

won’t be recorded to shell history, since it’s matched by one of the globs.


  HISTIGNORE='m:??:info *:info:[bf]g:exit:[bf]g %[0-9]:help *:date:cal:cal ????:exec env ENV\*'


Thanks for the formatted/expanded:) repost!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: