Hacker News new | ask | show | jobs
by boffinAudio 702 days ago
Where does it live? In a .bashrc I have to maintain? The point is, not having to create an alias or function, because the tool lives in history.

None of these are that complicated that they deserve a dedicated shell script and chmod'ing, or presence in a cloneable repo, etc.

2 comments

Tools that live in history are fine and good ... until they roll out of history.

Mind: I rely on shell history all the time, and I'm noting, admiring, and planning to adopt your commenting hack, it's ingenious.

But once a particular shell hack / one-liner / function has become sufficiently useful and proven, I'll typically add it to a shell function file (~/.bash_functions, sourced from ~/.bash_profile or ~/.bashrc), or my scripts directory (typically ~/.bin/ for personal hacks, /usr/local/bin/ if it's something I'll use from multiple accounts. Also park that under git and back it up / archive it somewhere or several somewheres.

Atuin should help with large histories; https://atuin.sh/

Graduating specific oneliners into functions/scripts is also a good chance to clean them up a bit, but it's a balance that's hard to strike - too many aliases and scripts, and you quickly forget they exist :-)

Thats fine, but do you understand the point that, by putting these utilities into a shell script, you're negating the ability to search for common commands through history, and now also need to load up your working memory with the name of the script, where it's located and so on?

I do put bigger/heftier utility functions into shell scripts - its just that I, more often than not, forget where they are and have to go searching. But with Ctrl-R, the flow does not get interrupted.

Anyway, not arguing for/against either technique - they are both appropriate when needed.

Commands which I make frequent use of as shell scripts or functions ... are also in my shell history, interestingly enough.

They also benefit by the further mnemonic / rediscovery trigger of existing in my local ~/.bin/ or ~/.bash_functions directory and/or file(s).

If you're not worried about multiple machines, then appending to bashrc is low effort. If you are, then jumping to version controlling at least part of your bashrc (just source it from the main file) is probably the easiest solution anyways. I agree that all of this is more effort than history, but only barely and I think it's worth it for common things that are suited to becoming functions or such