Hacker News new | past | comments | ask | show | jobs | submit

A shell exclamation mark is not for yelling. Be lazy

https://refp.se/articles/your-shell-and-the-lazy-exclamation-mark
loading story #49268708
loading story #49270208
IMO, !$ is most useful of them all (it is the one that gets replaced with the last argument of the last command).

!! you can do just as easily with up-arrow enter, which is just as quick. !ssh you can do with ctrl+r, which actually shows you what it's going to run and whether the last ssh is to where you think it is. sudo !! is up arrow, ctrl+a, 'sudo ', one more keystroke but it's natural if you know your readline. The rest are too complex and not worth learning. !$ is the sweet spot.

loading story #49271963
loading story #49274058
loading story #49272373
loading story #49270221
loading story #49268685
I got used to doing this over many many years with the tcsh shell. I switched to Fish recently and I continue to be annoyed by its refusal to implement this feature. Yes, I tried using all the newfangled history-search thingamajigs. They all kind of work, and they all have their issues. But the !, together with in-place expansion, is something I still dearly miss.
loading story #49268695
loading story #49271232
loading story #49270195
loading story #49269021
loading story #49269745
loading story #49270701
i love the mkdir example, so i’m going to exercise that muscle and see where it goes

and yeah ^r works, though i often type a few chars and ^p till i get the match. history-search-backward in your inputrc, iirc

edit: on a computer now :) my `if emacs` block, allowing arrows or ^n/^p to run through history. so for e.g., type "tar" and now as you shift through history with :binding:, it only shows history that began with "tar"

    $if mode=emacs
    "\e[A": history-search-backward
    "\e[B": history-search-forward
    "\C-p": history-search-backward
    "\C-n": history-search-forward
    ...
    $endif
loading story #49269338
loading story #49269023
loading story #49269008
loading story #49268693
loading story #49269754
loading story #49269467