Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

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.


sort by: page size:

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.

I haven't used the ! history for many years. It's simply easier and faster to use command line editing.

! was useful before command line editing; but not much since.


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

https://github.com/MauriceGit/Repeat_History

Use it daily when working with Linux to execute old commands as alternative to ctrl+r, AWESOME tool :)


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.


Yes, thank you.

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.


My dream command is

[somekey] + up

that scrolls through history sorted by frequency of use.


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.

https://henrikwarne.com/2018/08/11/my-favorite-command-line-...


I always add

  "\e[A": history-search-backward
  "\e[B": history-search-forward
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).

Er, why not just use the `history` command (or hit the up arrow)?

Lookup with the command history And execute with ![nn].

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.


Fun fact: if you don't want to put a command in history, prefix it with a space. This works in many shells.

I just want to throw in that you can get that nice up-arrow-history in bash too. It's the first thing I put in a new bash environment:

  bind '"\e[A":history-search-backward'
  bind '"\e[B":history-search-forward'

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

"\e[A": history-search-backward

"\e[B": history-search-forward


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.

I alias "history | grep" to "hrep" and I'd bet it is one of my top 3-5 commands.
next

Legal | privacy