logoalt Hacker News

hnlmorgtoday at 9:24 AM3 repliesview on HN

I’ve been burnt before using ! and forgetting what command I typed previously, thus invoking the wrong command line.

!! is handy for the sudo example, but beyond that, I tend to prefer pressing the up arrow to cycle through the history rather than picking the first item. Eg:

  !ssh
vs

  ssh[up]

It’s the same number of key strokes but less error prone

Replies

refptoday at 10:07 AM

Worth noting that `ssh[up]` isn't available by default in bash nor zsh — though it wouldn't surprise me if helpers such as oh-my-zsh enables it for you. `ssh[up]` is certainly an awesome feature — though (perhaps sadly) not default behavior.

> I've been burnt before using ! and forgetting what command I typed previously

If you want to make sure you do not execute commands you did not intend to, the section linked below is a great start:

- https://refp.se/articles/your-shell-and-the-lazy-exclamation...

You may also look into `magic-space` which makes the expansion of event-designators happen inline, I thought about including it but the article felt long even without it.

Thanks for reading the article, I hope it was a worthwhile read even with alternate workflows elsewhere!

show 1 reply
CoastalCodertoday at 9:38 AM

Agreed. I especially cringed at the author's example of mixing that with "sudo".

show 2 replies
pwdisswordfishqtoday at 10:07 AM

    bind space:magic-space