Hacker News new | ask | show | jobs
by williamvds 1141 days ago
With bash's HISTIGNORE, I can consciously prefix my command with a space to prevent it being added to history.

ls I usually don't care about, but there are directories I regularly cd to, so it would be nice to have those in history.

I can think of a neat heuristic, which is that I often cd to an absolute or home directory, so if the path starts with / or ~ I'll possibly want to cd there again in the future. Changing to a relative path on the other hand, I tend to do more rarely and while doing more ephemeral work.

2 comments

1. I don't always know beforehand if the command I am about to execute is garbage I'd like not to save.

2. I just don't want to be conscious about that every time I write a command. I'd rather edit history after I've finished some work. But that's just too tedious to do manually, I'd like to have some pre-configured heuristics applied automatically, like "never save cd/ls to history", but provide a way to overrule that rule in rare situations.

3. Absolute/partial/symlinked paths - are another separate problem :'(

* HISTCONTROL=ignoreboth

* prefix with space the commands you don't want to keep

* edit your existing .bash_history by prefixing all commands with space (then reload with history -r)

* after session exit or on next login, edit the new commands at the end (vi ~/.bash_history && history -r)

* use comments on the commands to make it easy to search (use keywords)

* group command lines by category (e.g. package manager, git, ssh, backup, find, dev)