4 ms·
> alt-. is great for what it is designed to do, iterating over the previous "last arguments" of your shell history. It's great at doing that, but it is also lim
by mkl 2mo ago
> alt-. is great for what it is designed to do, iterating over the previous "last arguments" of your shell history. It's great at doing that, but it is also limited to doing just that one thing.
No, it isn't limited to just that. Alt-0 alt-. will give you the zeroth "argument" (the program), alt-1 alt-. will get you the next (the program's first argument), etc. Negative arguments count back from the end: alt-- 1 alt-. will get you the argument before the last one (note that alt is held for the "-" but not the digit).
When you do use event designators, ctrl-alt-e (or alt-^) is critical. It expands all the ! codes inline to what they refer to, so you can see what you're doing before you hit enter, and as you're constructing the command too.
- refp 2mo agoAuthor 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-mark#i-dont-trust-my-exclamation-mark-fu-just-yet-any-advice 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!
- deleted 2mo ago[deleted]
- refp 2mo agoAlso, 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.
- deleted 2mo ago[deleted]
- bandie91 2mo agoi use `shopt -s histverify` instead of ctrl-alt-e.
- arijanj 2mo agoThis article taught me about alt-. and it's probably going to become my new favorite fish shortcut: if I type a portion of a word (for example an ssh hostname), hitting alt-. searches all previous arguments and autofills the entire username+hostname at that position. Seems much more powerful than bash's implementation. (and allows you to go forward/backward with alt+arrow keys if you overshoot it)
- mturmon 2mo agoInstead of alt-^, I set “magic-space” in `.inputrc`. This will expand the event designator after you type space to end it. So you type “!” “$” “space” and the designated argument expands in-place.