Hacker News new | ask | show | jobs
by motoxpro 897 days ago
What should I be using shell history for? I've never wanted to go back in my history but obviously people are getting a lot of value from it.
11 comments

Here are some of my often use cases: Long kunernetes commands, or ssh into an ip you don’t have remembered, curl commands when testing an api. Anything on the CLI that is long and either hard to remember or just annoying to type.
I tend to write scripts or docs when things are annoying and hard to remember. shell history is usually littered with sensitive stuff, I usually go way out of my way to prevent my machines from saving any of it, but to each their own.
> shell history is usually littered with sensitive stuff

Atuin is trying to solve this one too :)

By default it won't save history containing AWS credentials, slack credentials, etc. The list of things to ignore is configurable with regex

While it's not difficult to avoid putting credentials into your shell, ik most people will just paste things in that perhaps they should not

I use [Shuttle](https://fitztrev.github.io/shuttle/) for that ssh issue which often comes in handy. Should solve for most of those CLI command issues.
True I use mcfly[1] works pretty smoothly for me

[1] https://github.com/cantino/mcfly

I've tried to move all of my kubectl workflow into k9s, the CLI is just way too verbose.
I'm lazy and I don't want to type

With fish's shell history for example I can just type 's' and it completes it to 'ssh user@host.tld', because that's the last one starting with S I used. If it's not right, I can type it up to 'ssh' and press arrow up to pick the ssh command I want.

Then I might remember that I did this fancy jq thing once to parse a field in a specific way, I can easily use Atuin to look for it with a nice text-mode UI just by pressing C-r and typing 'jq' as the initial filter.

I often hit CTRL-R to reload a services config. I press `CTRL+R`, enter `reload`, and continue to hit `CTRL+R` until the right service appears. Enter. Done. Usually way quicker, especially when switching between distros. As one calls it httpd and one apache, once it's systemd and once it's and init script, and so on.
Yes I'm using this command occasionally. While clearly the demo of Atuin (https://atuin.sh/) looks cool and more powerful than ctrl+r, I must say that ctrl+r has always been enough to me.
I feel like I get a decent return on mining historical command usage for new (single keystroke?) aliases to setup, the most useful ones change over time for me.

Another use case I feel pays off is complicated one-liners where I need to do something similar but not quite the same again - good starting time saver. This depends on you being a mostly cli kinda person obviously, if you instinctively reach for excel over awk then ymmv.

I’ll sometimes write a useful one liner that I want to write a shell script off but if I’m in the middle of something and don’t have time I’ll do this:

<my> | <cool> | <one liner> # add script for this

The # comment makes it easy for me to search through my history to find one liners I want to use to build a shell script from

I'm similar. I do most of my work in Emacs and I don't do much sys admin, so I don't really use the shell much. It's always interesting to me to see other people's workflows, though.
I don't really know how to use awk and ctrl-r is faster than going back to stackoverflow to figure out what I did last time
it's like having a multi-register clipboard in that once you figure out the workflow, it's hard to go back.

...but if you effectively have this in emacs, I can see why you wouldn't need it in the shell.

Minimize typing as much as possible.
Have you even used the up arrow key to go back to your last command? This is like that, but does a lot more.
Not to be dramatic but atuin is life-changing. I can resume my working context from any project, no matter how far in the past (e.g. what docker or cmake or make commands I run). I don't need a personal wiki of cli tricks like an "ffmpeg cheatsheet" or whatever, I just access my own personal ffmpeg history.

Oh, also, I use tmux to split my terminal and do separate things in each one, so I like that atuin consolidates all the histories from my separate panes.