refp

Joined 11 years ago

Karma
243
Submissions
62
Member since
Apr 26
Filip Roséen, author and maintainer of <https://refp.se>
View on Hacker News

Recent submissions

Comment · 2 months ago
Comment · 2 months ago
Comment · 2 months ago
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.

Comment · 2 months ago
Comment · 2 months ago
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!

Comment · 2 months ago
Comment · 2 months ago
Comment · 2 months ago
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?
Comment · 2 months ago
I wonder which language creator would be hired to figure that one out; are you creative enough to think of one on the spot?

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton