This looks like a neat idea but the use case seems very specific. I have always found history (which I always alias to “hh”) to be very useful, combined with !<number> to quickly execute previous commands. The README doesn’t do enough to explain exactly how to use it, besides 3 screenshots.
I use `!:p` to the same effect. Which has the benefit that you can insert a history number between the bang! and the colon: ( set PS1 to include the command number if you do this a lot ).
I'm sure this exists in some form somewhere but something I really want is a way to pull up my command history numbered with a shortcut and then punch that number to run the last command than mindlessly hitting the up arrow for several seconds (why do we do this?). If anyone knows anything that has this functionality please share, thanks.
In the opposite vein, it can be helpful to stick something like ` #useful` or ` # description ` on the end of a command you expect to need again, so you can easily grab from history with C-r
This is so much better than CTRL+R that I've bound the key combo (CTRL+R/F) to this. `history | grep` suffices in those rare cases where I need the original CTRL+R behaviour.
I tried binding the arrow keys first, but it turns out I sometimes give up in the middle of writing a command in favor of reusing one from recent history, for which I need the original arrow bindings.
Also starting to type a command and using up-arrow to scroll through (I assume) endings of that command line that are in history. That's great too. But I often don't do, say,a do-release-upgrade (I use Kubuntu but prefer command line upgrade) within the time the command stays in history.
In connection with history, you can use !$ for the last argument, but you can also use escape-dot. I use that quite a bit (and escape-dot is slightly easier to type than !$).
Also worth pointing out that you can modify the command in the history list before running it, by typing !xxx:p (adding :p instead of !xxx that just re-runs the command). Then I use arrow-up and then modify it before running it.
to my .inputrc, I find it easier to use than C-r as it's some sort of autocomplete from history. But looking up commands with !number can still be very useful when you don't remember the command you need but remember when you used it (e.g. what commands you ran before and after).
For stuff like the example where you know you will be reusing the command, it's better to use an alias or script. Even if it's just a command you plan to run in a couple times in a row you can add a temporay alias with: alias foo = "!!" - that way you don't have to hit ctrl+r each time.
Still, it's a good tip in terms of adding comments to unusual/confusing commands so when you go through your history you're not like "wtf was I doing here?" or if you unexpectedly need to recall it.
My favorite bash trick is still Ctrl-O: submit command and advance history by one.
If you ever find yourself counting up-arrows to repeat a sequence of commands (that aren't worth scripting for whatever reason), next time, go to the top of the list and hit Ctrl-O. The result is the the command runs, and the one after it in the history is loaded into you prompt.
"By way of comparison, on my home PC I used a third-party command shell called 4DOS [...] It had a wonderful command line history mechanism: type part of a command, then press up-arrow."
Want in bash? Add to ~/.inputrc:
# up and down arrows do incremental history search
Cool idea, it's sometimes hard to use the standard history when I come back to an old project to build or run it with all the crazy build commands I have to do these days.
reply