You just blew my mind. sudo [space] [shift] !! [enter] (4+1+1+1+1+1) is one keypress longer than ↑ + home + sudo + space + enter (1+1+4+1+1). In your face, universe.
Actually, after kinematic analysis of the required fingertip trajectories upheaves both of these arguments. If you calculate the aggregate spatial displacement across a standard 2D Euclidean plane for both input strings, the former macro sequence yields a significantly lower metric footprint than the latter.
For the sake of empirical demonstration, we can map this across a standard ANSI 100% layout using a normalized key pitch constraint where 1 U = 19.05 mm. By establishing a Home Row Idle-State Matrix as our behavioral anchor and tracking independent multi-finger vectors using the standard Pythagorean metric tensor—calculating the straight-line distance d = sqrt( delta_x^2 + delta_y^2 ) between consecutive keystroke coordinates—we arrive at the following quantitative breakdown:
Fewer keystrokes != less work. Even though typing !! looks like more work, it isn't because your finger travel distance is significantly shorter when executing those keys using two-handed touch typing on a standard ANSI QWERTY keyboard.
Maybe someone who only used csh? I can’t remember if ^a is a default in that shell. I thought it started with ksh or bash.
ETA: just looked it up and I’m dumb. Comes from emacs (of course) and looks like it was introduced in bash. I guess I could claim ignorance, being a VI man, but I actually knew at some point that it came from emacs. I think I can count on 1 hand the number of times I’ve used emacs
I've used it for so many years that it's not an issue anymore. I remember using !! a lot but it was literally just for sudo. Now i either write what I need and do up or write what I need and then press alt+s, which seems even more intuitive now.
Oof. Posix non-compliant stuff always gives me the ick.
I highly recommend switching to zsh, it can do the same stuff and more, and it is actually a proper terminal. Switching scripts might be a bit complicated if you're deep into it, but it's worth it
Top text should maybe say copying by, rather than copying then? Since sudo !! will automatically copy the previous command with sudo in front of it, so there's no manual copying involved
Same reason there's a ScrollLock key on keyboards. Didn't always have scrollbars and if the application prints more than you can read, you want to pause that...
Short answer, terminals are built on the same technology as physical terminals from the 60s and 70s when controlling the flow of data from the server was a more useful feature.
!! Just puts in your last typed command. So if you typed rm -rf /etc, you wouldn't have permission. But if you typed in sudo !! Right after, then you're really fucked.
Adding to this, if you notice numbers next to your previous commands when you run history, you can do ! and it will rerun that command. Probably the second cool shell trick I learned back in the olden days or yore (mid-90s?) after ⬆️
GNU readline is the library that powers features like Ctrl-A, Ctrl-R and Alt+S. By default, it is in emacs mode - that is why it supports these shortcuts, they are the same as in emacs. It also supports vi style editing. You can switch to that by typing set -o vi in your shell. Then you can edit commands as if you were in vi, for example, instead of Ctrl-A you'd do Esc 0. Instead of Ctrl-R you'd do Esc /. If you are fluent in vi then this mode will be more useful.
I used to work on really old Unix systems, sometimes over serial connections. They didn't have bash (only ksh), and they didn't understand arrow keys. Vi mode was the only way to edit commands that worked reliably.
But in almost any shell there is also ctrl+a sudo. ctrl+s requires you haven't sent it yet.
Or also up ctrl+a sudo. It's only one more key press than sudo !!, and unlocks ctrl-a. More useful to teach noobs IMO. Teach a skill instead of a quirk.
Yeah, I tried it for a bit. It gives you coloured autocompletes for things in your history but you accept them with right-arrow rather than tab as well, which is a weird choice, and ctrl-r is still faster. It's very much a day-to-day user's experience rather than a scripting shell, I think people stick with others in their shebangs.
Not sure, I assumed universal because you use it with your history. Type history, see the number next to the command, do a !nnn and it will run that command from history
122 Comments
akunohana@piefed.blahaj.zone · 149 pts · 84d
Ephera@lemmy.ml · 33 pts · 84d
Always amused me that
sudo !!is actually more keypresses (at least on keyboards where typing!requires holding Shift).akunohana@piefed.blahaj.zone · 62 pts · 84d
You just blew my mind.
sudo [space] [shift] !! [enter](4+1+1+1+1+1) is one keypress longer than↑ + home + sudo + space + enter(1+1+4+1+1). In your face, universe.logi@lemmy.world · 16 pts · 84d
If you have an actual home key. If it's ctrl+a or (IIRC, AFK) ctrl+← then we're even.
And if we track hand movements then pressing ! twice may be faster than moving to another key.
But yeah, it's not at all clear that
sudo !!is faster like you'd expect it to be.gankouskhan@piefed.zip · 6 pts · 77d
Actually, after kinematic analysis of the required fingertip trajectories upheaves both of these arguments. If you calculate the aggregate spatial displacement across a standard 2D Euclidean plane for both input strings, the former macro sequence yields a significantly lower metric footprint than the latter.
For the sake of empirical demonstration, we can map this across a standard ANSI 100% layout using a normalized key pitch constraint where 1 U = 19.05 mm. By establishing a Home Row Idle-State Matrix as our behavioral anchor and tracking independent multi-finger vectors using the standard Pythagorean metric tensor—calculating the straight-line distance d = sqrt( delta_x^2 + delta_y^2 ) between consecutive keystroke coordinates—we arrive at the following quantitative breakdown:
Macro Sequence 1:
sudo [shift] !! [enter]Macro Sequence 2:
[up] [home] sudo [space] [enter]tl;dr
Fewer keystrokes != less work. Even though typing !! looks like more work, it isn't because your finger travel distance is significantly shorter when executing those keys using two-handed touch typing on a standard ANSI QWERTY keyboard.
akunohana@piefed.blahaj.zone · 3 pts · 77d
Edit: I will forward your thesis to the cat.
My day started out catastrophically bad, resulting in taking a sick day.
Then came you.
I cried and laughed in some sequence and it gave me the energy to get out of bed. Now, I will have breakfast*.
*Loose definition.
gankouskhan@piefed.zip · 3 pts · 77d
bows thank you thank you. Glad about my efforts being well received, and even more so it got you out of bed! Cheers and may your day remain on the up.
Axolotl_cpp@feddit.it · 19 pts · 84d
But it's faster since your hand move less and you can keep
shiftpressedNilz@sopuli.xyz · 13 pts · 84d
I use zsh with the sudo plugin. Double tap
escand your current or last command will be prefixed with sudo.akunohana@piefed.blahaj.zone · 10 pts · 84d
I don't dabble in black magic. /j
It's actually pretty neat.
SkaveRat@discuss.tchncs.de · 17 pts · 84d
Ctrl A is easier to reach than the home key
ClownStatue@piefed.social · 4 pts · 84d
Unless you’re in a default screen session (I always thought ^A was such a dumb default for screen to use).
AnUnusualRelic@lemmy.world · 4 pts · 83d
Screen must have been written by someone who wasn't familiar with the shell. It's the only logical explanation.
ClownStatue@piefed.social · 3 pts · 83d
Maybe someone who only used csh? I can’t remember if ^a is a default in that shell. I thought it started with ksh or bash.
ETA: just looked it up and I’m dumb. Comes from emacs (of course) and looks like it was introduced in bash. I guess I could claim ignorance, being a VI man, but I actually knew at some point that it came from emacs. I think I can count on 1 hand the number of times I’ve used emacs
Obnomus@lemmy.ml · 12 pts · 83d
Ayo chill
akunohana@piefed.blahaj.zone · 3 pts · 82d
I approve of the ice to coke ratio. I am now chill.
Obnomus@lemmy.ml · 1 pts · 82d
Good
certified_expert@lemmy.world · 3 pts · 82d
Obnomus@lemmy.ml · 0 pts · 82d
How about just one keyboard shortcut and enter.
a14o@feddit.org · 1 pts · 82d
Start with ctrl+p, ctrl+a but yes
olafurp@lemmy.world · 144 pts · 84d
You can also just do a
sudo !!the!!is a shorthand for whatever you tried to run previously.juipeltje@lemmy.world · 78 pts · 84d
Was about to say, why would you copy anything when using
sudo !!lolMountainaire@lemmy.world · 1 pts · 77d
... because I had no idea about this until now. Sweet!
devfuuu@lemmy.world · 27 pts · 84d
Not all shells support that.
I use fish btw.
protogen420@lemmy.blahaj.zone · 17 pts · 84d
I made my own !!
ArchAengelus@lemmy.dbzer0.com · 18 pts · 84d
I know what you meant (I have one for fish as well), but I chucked because you looked very enthusiastic about it!
The fish function for
!!is super useful thoughNannerBanner@literature.cafe · 7 pts · 84d
I don't even know what I use anymore. My distro seems to keep changing it when I reinstall.
unbuckled_easily933@lemmy.ml · 9 pts · 84d
NannerBanner@literature.cafe · 5 pts · 84d
Lol, thanks. Now I know.
guymontag@lemmy.ml · 2 pts · 83d
Holy shit I wish fish supported it. I just press up arrow then hold left arrow and manually type sudo. It fucking sucks
eneff@discuss.tchncs.de · 6 pts · 83d
... are you not aware of Alt+S?!
guymontag@lemmy.ml · 1 pts · 82d
Nope haha. Thanks for letting me know
tekino@pawb.social · 3 pts · 83d
I've been using this plugin https://github.com/oh-my-fish/plugin-bang-bang fish also allows going through previous arguments with alt+up
guymontag@lemmy.ml · 1 pts · 82d
Epicc. I should install thjs
devfuuu@lemmy.world · 2 pts · 83d
I've used it for so many years that it's not an issue anymore. I remember using !! a lot but it was literally just for sudo. Now i either write what I need and do up or write what I need and then press alt+s, which seems even more intuitive now.
BolshoyToster@sh.itjust.works · 2 pts · 83d
Does your keyboard not have a home key?
guymontag@lemmy.ml · 2 pts · 82d
Didn't know home key could do that lol.
Sarcasmo220@lemmy.ml · 16 pts · 84d
I learned something new today!
adeoxymus@lemmy.world · 6 pts · 84d
I completely forgot about this one!
lefixxx@lemmy.world · 4 pts · 83d
wish i could alias that
alias ffs="sudo !!"
timbuck2themoon@sh.itjust.works · 5 pts · 83d
alias ffs='sudo $(history -p !!)'TedZanzibar@feddit.uk · 2 pts · 83d
Just to confirm: I tried this, it works.
olafurp@lemmy.world · 1 pts · 83d
That doesn't work? I would have thought it would work.
lefixxx@lemmy.world · 2 pts · 83d
!! Gets replaced by whatever was run before the alias command
Obnomus@lemmy.ml · -1 pts · 83d
Bruh
Nalivai@lemmy.world · 3 pts · 82d
What shell are you using? In both bash and zsh,
!!is a substitute for a previous commandObnomus@lemmy.ml · 0 pts · 82d
Fish
Nalivai@lemmy.world · 2 pts · 81d
Oof. Posix non-compliant stuff always gives me the ick.
I highly recommend switching to zsh, it can do the same stuff and more, and it is actually a proper terminal. Switching scripts might be a bit complicated if you're deep into it, but it's worth it
Obnomus@lemmy.ml · 0 pts · 80d
All I do in terminal is type, I don't know scripting. But I heard a lot of things about zsh.
Nalivai@lemmy.world · 2 pts · 80d
Oh-my-zsh is a good start then. It gives you a bunch of themes and presets and plugins so you can do whatever you want with your zsh
Obnomus@lemmy.ml · 1 pts · 80d
I'll try thanks for the recommendation.
ikidd@lemmy.dbzer0.com · 74 pts · 84d
alias fuck="sudo !!"Nilz@sopuli.xyz · 38 pts · 84d
Wait, you don't have The Fuck installed?
olafurp@lemmy.world · 7 pts · 83d
Waiting for it to be rewritten in rust
daeraxa@programming.dev · 4 pts · 82d
Only worth installing if it is 🔥🔥🔥blazing⚡⚡⚡fast
imsufferableninja@sh.itjust.works · 21 pts · 84d
Top text should maybe say copying by, rather than copying then? Since sudo !! will automatically copy the previous command with sudo in front of it, so there's no manual copying involved
Obnomus@lemmy.ml · 7 pts · 84d
Yeah I remembered that after uploading the meme.
albbi@piefed.ca · 17 pts · 84d
I know alt +. inserts the last argument of previous commands. There must be a good list of alt commands somewhere because they're pretty damn useful.
softwarist@programming.dev · 8 pts · 84d
The manual is a good place to start. It's just GNU Readline under the hood.
Obnomus@lemmy.ml · 1 pts · 83d
Thanks to you, I just find out new keyboard shortcut
nibbler@discuss.tchncs.de · 15 pts · 84d
I used to have an alias 'please' for that.
Obnomus@lemmy.ml · 1 pts · 83d
Lmao
GarboDog@lemmy.world · 15 pts · 83d
Wait… YOU CAN DO THAT?!
Obnomus@lemmy.ml · 6 pts · 83d
Forgot to mention but only in fish shell.
GarboDog@lemmy.world · 1 pts · 82d
Ah oki lol
Mountainaire@lemmy.world · 2 pts · 77d
I figured it out, at least in Linux Mint:
.ksfolder:Set it as a Startup Program with the command
keysharp "(filepath)/(filename).ks"and it'll always be ready to go!Mountainaire@lemmy.world · 1 pts · 77d
What is the "fish shell?" Anyway, I'm gonna see if I can actually get this to work in any terminal through an external program...
RedstoneValley@sh.itjust.works · 12 pts · 84d
Or press Ctrl-S and take a nice walk outside
sem@piefed.blahaj.zone · 2 pts · 81d
I misread this image and have been doing this the past day and it keeps breaking my terminal :(
b161@lemmy.blahaj.zone · 11 pts · 83d
sudo !!
Obnomus@lemmy.ml · 1 pts · 83d
For some reason I get this
wpb@lemmy.world · 1 pts · 83d
Use zsh
Obnomus@lemmy.ml · 0 pts · 82d
It works.
eco_game@discuss.tchncs.de · 9 pts · 84d
On my Terminal that just makes it so I can't type anymore, I feel like I'm doing something wrong...
My solution to the problem is CTRL+U, type sudo, CTRL+Y.
imsufferableninja@sh.itjust.works · 15 pts · 84d
If you hit ctrl-s, ctrl-q will unfreeze
eco_game@discuss.tchncs.de · 6 pts · 84d
Interesting, why is that? Like what feature is that?
Ephera@lemmy.ml · 9 pts · 84d
Same reason there's a ScrollLock key on keyboards. Didn't always have scrollbars and if the application prints more than you can read, you want to pause that...
solxix@pawb.social · 13 pts · 84d
THAT'S WHAT IT'S FOR??
Now that I think about it, it does seem pretty obvious.
neclimdul@lemmy.world · 5 pts · 84d
Short answer, terminals are built on the same technology as physical terminals from the 60s and 70s when controlling the flow of data from the server was a more useful feature.
imsufferableninja@sh.itjust.works · 4 pts · 84d
It's part of the terminal emulator flow control
qprimed@lemmy.ml · 3 pts · 84d
x👏off👏... x👏on👏... x👏off👏, x👏on👏...flowcontrol.
dracc@discuss.tchncs.de · 9 pts · 84d
Ctrl + S freezes your shell yes. But Alt + S?
eco_game@discuss.tchncs.de · 6 pts · 84d
Ah indeed, ALT+S does nothing. I must have pressed both before realizing it was frozen.
Dionysus@leminal.space · 8 pts · 84d
Need to use the fish shell instead of the others for this to work. (May be a way to enable it in other shells but I'm not sure how)
TrickDacy@lemmy.world · 7 pts · 84d
Cannot find any reference online. What is this supposed to do? Not at a PC right now.
cyberpunk007@lemmy.ca · 9 pts · 84d
!! Just puts in your last typed command. So if you typed rm -rf /etc, you wouldn't have permission. But if you typed in sudo !! Right after, then you're really fucked.
TrickDacy@lemmy.world · 7 pts · 84d
Ah I wasn't clear -- those, I knew. It's alt+S I don't know. I'm at my machine now and it doesn't seem to do anything on Pop_OS.
clif@lemmy.world · 5 pts · 84d
Seem to be a
fishshell thing.I tested on my good ole trusty
bashand got nothing so I went searching.EDIT: Clarification :
alt+sseems to be afishshell thing.cyberpunk007@lemmy.ca · 3 pts · 84d
Ya I haven't tried alt s. Never heard of it before either.
solxix@pawb.social · 1 pts · 84d
Not if you don't type your password.
ClownStatue@piefed.social · 3 pts · 84d
Adding to this, if you notice numbers next to your previous commands when you run history, you can do ! and it will rerun that command. Probably the second cool shell trick I learned back in the olden days or yore (mid-90s?) after ⬆️
moopet@sh.itjust.works · 3 pts · 83d
ctrl-r is generally quicker
ClownStatue@piefed.social · 1 pts · 83d
Learned that one embarrassingly much later.
cyberpunk007@lemmy.ca · 2 pts · 84d
I assume if you are silly enough to type in rm -rf /etc, then you are silly enough to type in your password 😅
Obnomus@lemmy.ml · 0 pts · 83d
It runs the previous command with sudo, also its only for fish shell.
wpb@lemmy.world · 5 pts · 83d
<Esc> k I sudo <Space> <Enter>Obnomus@lemmy.ml · 2 pts · 83d
jenesaisquoi@feddit.org · 4 pts · 83d
lol no vi mode
Obnomus@lemmy.ml · 2 pts · 83d
Vi mode?
jenesaisquoi@feddit.org · 1 pts · 83d
GNU readline is the library that powers features like Ctrl-A, Ctrl-R and Alt+S. By default, it is in emacs mode - that is why it supports these shortcuts, they are the same as in emacs. It also supports vi style editing. You can switch to that by typing
set -o viin your shell. Then you can edit commands as if you were in vi, for example, instead of Ctrl-A you'd do Esc 0. Instead of Ctrl-R you'd do Esc /. If you are fluent in vi then this mode will be more useful.I used to work on really old Unix systems, sometimes over serial connections. They didn't have bash (only ksh), and they didn't understand arrow keys. Vi mode was the only way to edit commands that worked reliably.
cupcakezealot@piefed.blahaj.zone · 3 pts · 84d
oh my zsh plugin just let's you press esc twice :3
Obnomus@lemmy.ml · 2 pts · 83d
Ayo what, I didn't know that but I use fish.
cupcakezealot@piefed.blahaj.zone · 1 pts · 82d
i know you dont use it but just in case you were curious; it's the sudo plugin: https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/sudo/README.md
thedormantotaku@lemmy.world · 3 pts · 82d
You can do that??
I always did sudo !!
Obnomus@lemmy.ml · 1 pts · 82d
Well its only for fish shell.
thedormantotaku@lemmy.world · 1 pts · 82d
I am using fish shell and just tried it. Thanks man. Such a convenient feature NGL
Obnomus@lemmy.ml · 0 pts · 81d
No problem.
x0x7@lemmy.world · 1 pts · 81d
But in almost any shell there is also ctrl+a sudo. ctrl+s requires you haven't sent it yet.
Or also up ctrl+a sudo. It's only one more key press than sudo !!, and unlocks ctrl-a. More useful to teach noobs IMO. Teach a skill instead of a quirk.
muhyb@programming.dev · 2 pts · 84d
Is this a shell thing or a terminal thing? It doesn't work for me on
foot.Ephera@lemmy.ml · 6 pts · 84d
@Dionysus@leminal.space found out that it's a feature in
fishshell, which I can confirm.muhyb@programming.dev · 3 pts · 84d
Thanks. I think I should check out
fishsoon, I keep seeing it a lot lately and it seems to be made for lazy people like me. :)moopet@sh.itjust.works · 2 pts · 83d
Fish has a bunch or weirdness if you're used to other shells for things like substitution, and shortcuts like $_ don't work afaik.
muhyb@programming.dev · 1 pts · 83d
Huh, I checked and noticed that
fishis non-POSIX. I guess I'll just stick tozshbut I still want to checkfishto see what's all this about.moopet@sh.itjust.works · 2 pts · 82d
Yeah, I tried it for a bit. It gives you coloured autocompletes for things in your history but you accept them with right-arrow rather than tab as well, which is a weird choice, and ctrl-r is still faster. It's very much a day-to-day user's experience rather than a scripting shell, I think people stick with others in their shebangs.
Obnomus@lemmy.ml · 2 pts · 83d
Ig its for fish shell
BCsven@lemmy.ca · 1 pts · 84d
Not sure, I assumed universal because you use it with your history. Type history, see the number next to the command, do a !nnn and it will run that command from history
muhyb@programming.dev · 5 pts · 84d
Oh,
!!definitely works. I meant Alt+S shortcut.BCsven@lemmy.ca · 3 pts · 84d
Oh, LOL
BetaSoldier@lemmy.world · 1 pts · 83d
basxto@discuss.tchncs.de · 1 pts · 82d
Why do you not press the up arrow + Pos1?
Obnomus@lemmy.ml · 0 pts · 82d
What is Pos1?
basxto@discuss.tchncs.de · 1 pts · 80d
home key
prenatal_confusion@feddit.org · 1 pts · 82d
Fuckit should be able to catch that