HNHacker News
TopNewBestAskShowJobs

refp

243 karma · joined April 26, 2015

Filip Roséen, author and maintainer of <https://refp.se>
submissionscomments
refp··on A shell exclamation mark is not for yelling. Be lazy
FAQ updated: https://refp.se/articles/your-shell-and-the-lazy-exclamation...

really appreciate the feedback, thanks a million!

refp··on A shell exclamation mark is not for yelling. Be lazy
I think you are very much on point, I can definitely relate to the complexity of C++ turning it both into a wonderful adventure, but also a swamp where every step feels uncertain.

Disclaimer; author of this post, and also https://refp.se/articles/non-constant-constant-expressions and related post in that series.

refp··on A shell exclamation mark is not for yelling. Be lazy
Also, on the note of "you can do everything with Alt-<key>", I'd like to highlight that modifiers such as `:h` (directory part), `:t` (filename), and `:r` (strip extension) etc., is what the article was aimed at when saying you can do more with event-designators.

What you can do with what is always hard to answer given that all roads lead to Rome, though some roads have more turns than others.

refp··on A shell exclamation mark is not for yelling. Be lazy
Author here, thanks for reading and taking time to reply!

---

You are very much correct that `Alt-.` with modifiers can do more than what has been described, it is however important to note that the behavior of `Alt-<key>` changes heavily both between zsh and bash, but also between `vi-mode` and `emacs-mode`.

For instance, zsh will switch to `vi-mode` depending on env variables such as `$EDITOR`, making `Alt-<key>` unavailable in that regard.

---

It's also worth noting that `ctrl-alt-e` is _not_ a zsh default, though it is a fair point that it could have been added in the below linked section:

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

For what it's worth, I had troubles finding a proper scope for the article contents — and with that the lines became a bit blurry in terms of what to include, and what not to include.

---

I really appreciate constructive comments like yours, and hope it together with the article can help future shell ninjas!

refp··on A shell exclamation mark is not for yelling. Be lazy
Your questions would be a great addition to the FAQ, thank you!

--

> When I enter `sudo !!` will it be stored unchanged in the shell history, or stored after interpolation of `!!`?

event-designators themselves do not end up in history, it will be the expanded contents:

    $ echo "hello world"
    hello world
    $ echo !$:s/world/idoubtit/
    echo "hello idoubtit"
    hello idoubtit
    $ history
        1  echo "hello world"
        2  echo "hello idoubtit"
        3  history
The above is ironically enough quite annoying when writing a post about event-designators, as you'd want to reach for previous pre-interpolation commands.

> When I start a command line with a space, so that zsh does not put it in the shell history, will !… also ignore that line?

leading space to ignore adding things to the history is not default behavior, but event designators will still be able to capture their contents. Notice how "echo 321" is _not_ part of the history, but our usage of !$ is:

    % setopt HIST_IGNORE_SPACE
    % echo "abc"
    abc
    %  echo "321"
    321
    % echo last-argument-was !$
    echo last-argument-was "321"
    last-argument-was 321
    % history
    22092  setopt HIST_IGNORE_SPACE
    22093  echo "abc"
    22094  echo last-argument-was "321"
> Is `!$` recursive?

I think this is indirectly answered by the above, if not let me know and I will see if I can answer.

---

Will try to update the post within the next few hours with your additional questions — much much appreciate the feedback, and thanks for reading!

refp··on A shell exclamation mark is not for yelling. Be lazy
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!

refp··on A shell exclamation mark is not for yelling. Be lazy
> you have to accurately remember the past

From personal experience I rarely reach for event-designators beyond the current viewport of the terminal. Referring to a command beyond that is, as you very much correctly point out, an easy way to get behavior you don't want. However, if you are always referring to things that are near-memory or even still directly visible in your terminal buffer — the gun-to-foot ratio becomes manageable. I use many (many) of these daily without issues, but it does require some additional discipline.

Also, and this I find important to note, `!!` and `!$` sit outside of the memory argument as they always refer to the last command and last-command's last-argument respectively — as such there shouldn't be any recall related problems (unless you are context switching and come back to a shell in a state you don't remember).

A common occurrence when my posts acquire attention is that I retroactively realize that some things could have been conveyed better; I read every comment and yours is a blessing in disguise to improve future writing.

Thanks for reading the article, and thanks for indirectly making me a better writer!

---

EDIT:

by the way, for what it's worth, the below linked section describes how to effectively explicitly confirm what you would run as a safety measure if unsure:

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

refp··on A shell exclamation mark is not for yelling. Be lazy
the "mixing of sudo"-example is using `!!`, which as explained is the immediately previous command, a little confused how that translates to the "execute command somewhere in the history" argument?
refp··on High-frequency trading firm just hired Bjarne Stroustrup (creator of C++)
I wonder which language creator would be hired to figure that one out; are you creative enough to think of one on the spot?
refp··on My girlfriend broke up with me – This is my body's reaction to the news
https://www.reddit.com/r/dataisbeautiful/comments/1v874lz/my...

I submitted the above link, seems HN is rewriting it automatically. :-/

refp··on My girlfriend broke up with me – This is my body's reaction to the news
> My girlfriend sat me down on June 20th and told me that she had been cheating on me and was choosing to be with "the other man".

> This is my body's reaction to that news.

> HR, Sleep, and Energy scores recorded by my [smartwatch]

refp··on A shell colon does nothing. Use it anyway
I think you should take a deep breath and read this updated FAQ:

https://refp.se/articles/your-shell-and-the-magic-colon#why-...

I am not asking anyone to put this in production, it is a tongue-in-cheek/cute way of explaining/showing what the null-command _can_ do, not what it _must_ do.

No, any distro that stopped shipping entities mentioned to use only null-command variants.. well, I'd save whatever your end goal is to a meeting with them.

Just enjoy the article for what it is — a piece of trivia.

Best Regards, Filip Roséen - refp

refp··on A shell colon does nothing. Use it anyway
This question seems to pop up all over the place, so I took some time to answer it here:

https://refp.se/articles/your-shell-and-the-magic-colon#why-...

refp··on A shell colon does nothing. Use it anyway
damn, nice one — definitely gonna use this myself (or variations thereof)!
refp··on A shell colon does nothing. Use it anyway
DUDE!

I wrote my first real `.ps1` the other day for auto-installing all dependencies needed to run a `gitea`-runner on windows for windows builds; powershell - felt like the lover I never had. And the documentation in readable comments at the top that just.. generates usable docs? Damn, damn, damn.

There is a part of me that low-key wanna try that as my daily driver for a week or two. But with that said, I'm a zsh vi-mode guy - always have been, always will be.. but I'd happily take powershell on a romantic getaway every once in a while!

refp··on A shell colon does nothing. Use it anyway
I have never been in this situation before but I do agree with you, and honestly it feels very bad. I saw the comment when it was posted and, perhaps naively, thought "oh well, no one will care - its just another fluff comment".

Fast-forward to seeing that comment climb up the ranks, posted by a person who has 270x my karma, who seemingly gets upvotes by just.. writing things? no proof? no rationale? nothing?

Yeah, feels bad. I'm super happy so many are enjoying the article, and this situation can't take too much away from that, but man.. discouraging for sure.

refp··on A shell colon does nothing. Use it anyway
They are NOT superflous, and all you need to prove it is `zsh` (but there are others that follow suit in similar fashions):

  zsh% echo "hello world" > data
  
  zsh% < data && echo "READABLE"   # <- will print the contents of data
  hello world
  READABLE
  
  zsh% : < data && echo "READABLE" # <- this will not
  READABLE
So, if you want something that "everyone can use" without going into details about the difference between commonly used shells.. you'd use the null-command.

---

and given that we use the null-command, it _WILL_ behave different with or without subshell.. and all you need is `bash --posix` to prove it:

    % cat subshell.sh
    #!/bin/bash --posix
    ( : < missing.json ); echo AFTER    # <- will echo AFTER
    
    % ./subshell.sh
    ./subshell.sh: line 2: missing.json: No such file or directory
    AFTER
    
    % cat no-subshell.sh
    #!/bin/bash --posix
    : < missing.json; echo AFTER        # <- this will not
    
    % ./no-subshell.sh
    ./no-subshell.sh: line 2: missing.json: No such file or directory

    % : ^- apparently.. there is a difference

The output above is not truncated, `no-subshell.sh` will stop executing due to the broken read.

---

One should never trust things just because they are written, but that also applies to comments on HN. Originally when I read your message I actually thought I made a mistake, I was very close to writing an apology comment and adding a note to the blog post, but not close enough - I had to test it again.

I'm thankful for the watchful eyes and scrutiny when reading things online, that's good - keep it up, but your message is factually wrong - on so many levels.

refp··on A shell colon does nothing. Use it anyway
First of all, I must salute you on the joke; well put haha!

---

It is a (contrived) example of usage where a command is required and `:` can fill in the blanks. There are certainly scenarios where negating an expression becomes harder than doing the "dumb" way, and I for one has written code where `:` can be used as a placeholder meaning "fill this in later" or equivalent.

With that said, 100% agree with you that in actual "production" code - there is always a cleaner way.

refp··on A shell colon does nothing. Use it anyway
Hey jiveturkey, author here!

I agree with you, and for what it's worth the truncation snippet is very much tongue-in-cheek much like `( : >> output ) && echo "is writable"`.

I wasn't expecting anyone to actually use these in Prod, rather I aimed to show what can be done with a command designed to.. do nothing (crazy).

Happy you enjoyed the article, and thank you!

refp··on A shell colon does nothing. Use it anyway
Yo, author here.

You are very much correct and I 100% agree with you, I have updated the first example to include a snippet where a proper env-var is used to show of the automatic diagnostic.

Thanks for your feedback, much much appreciated!

refp··on OSS-SEC: 432 Linux kernel CVEs (in less than 32 hours)
The comment in question is a joke; it was never intended to be read as actual advice.
refp··on OSS-SEC: 432 Linux kernel CVEs (in less than 32 hours)
perhaps we better add a job to automatically order new IoT devices from amazon too; once a month is probably good enough not to suffer. I think we just invented Upgrades-As-A-Service.. only $50/month for freshly not-yet-known-to-be-b0rked firmware!

are you gonna spot the LLM bill or should I?

refp··on OSS-SEC: 432 Linux kernel CVEs (in less than 32 hours)
I remember when you were actually able to keep up with CVEs and you could (at least somewhat) prioritize patches while disregarding those which felt irrelevant.

But now.. are we simply supposed to use our f̶a̶v̶o̶r̶i̶t̶e̶ package manager and batch update our systems in a loop?

    while true; do apt-get update && apt-get upgrade -y; sleep 1d; done
wait. erhm... and probably an automatic reboot/kernel reload every 48h; THAT WILL DO IT! </sarcasm>
refp··on The psychological cost of having an RSS feed
The TLDR is that I back in 2015 published some C++ related posts that got way more traction than I originally anticipated, and given the subscriptions to the RSS-feed I felt like I could not live up to the contents people perhaps expected.

On the other hand, I have no idea what people _actually_ expected to be published, but in my head I have for what it's worth created this nightmare scenario where I post something not related to C++, and all those readers would be /pinged and disappointed.

Impressions and clicks are a confident booster, though the fear of disappointing or letting people down because they expect "better" content is something I for sure struggle with

refp··on The psychological cost of having an RSS feed
For me it boils down to the fact that rss-feeds propagate without any knowledge or control. One left-over subscription somewhere can ping so far, whereas a manually copied link (like if someone reads an article and decide to share it) at least is an isolated event.

It is not the author of the RSS who "disturbs" sleeping agents, it is simply the one who actually forwarded the message. If that makes sense?

refp··on The psychological cost of having an RSS feed
Solid advice for sure, and ignorance is bliss but damn does this nuddle of mine (brain) make it difficult at times; "no logs for an httpd? you cray-cray-crazy? what if something happens!?"

Perhaps I need some further self-reflection, because I fear that with no logs I would assume the worse and end up in the same boat. Though.. maybe it is time to grow up? No idea, weirdly enough this problem is one of the hardest I have ever faced

refp··on The psychological cost of having an RSS feed
Ever since I first started blogging I have struggled with performance anxiety, and I have concluded that much of this boils down to me adding an RSS feed to my site.

This article dives into why that is, and the hidden costs of adding something as simple as /rss.xml to your blog.

refp··on Hacker News RSS
I have recently switched to mozilla thunderbird, and one of the <3 moments is definitely the builtin RSS-reader (which I use extensively now that I have it easily accessible on my third monitor).
refp··on The C++ Type Loophole (C++14)
Sadly I never finished that blog series due to severe suicidal depression (ended up being hospitalized for several months), but I do have a toy implementation of that laying around somewhere.

Currently abroad for my primary profession (fashion model), but as soon as this current job is finished and I'm back home I could look for it and ping you.

Any preferred channel where I can reach you, or do you prefer me replying here?

refp··on “Show my password” checkbox shouldn't be where “Remember my password” is
No, but in general, issues like this boils down to grouping too many actions into the same visual category (when they are not acting upon the same entity).

As an example, I often see software where modification of the current entity is grouped together with actions that are really _making use of_ said entity.

Whenever I see "delete" next to "reply" in communicational tools a red flag is waved high. It's a disaster waiting to happen.

In the "delete" scenario the problem is often circumvented by having a confirmation dialog - but other more subtle bloopers often go overlooked.

Page 1 of 2Next →