Spyke
Epherareply
lemmy.ml

Always amused me that sudo !! is actually more keypresses (at least on keyboards where typing ! requires holding Shift).

33

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.

62

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.

17
piefed.zip

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]

  • Single-Handed Vector String: 40.878 U
    • Net Linear Displacement: 778.7 mm
  • Dual-Handed Touch-Typing Matrix: 8.424 U
    • Net Linear Displacement: 160.5 mm

Macro Sequence 2: [up] [home] sudo [space] [enter]

  • Single-Handed Vector String: 40.989 U
    • Net Linear Displacement: 780.8 mm
  • Dual-Handed Touch-Typing Matrix: 21.728 U
    • Net Linear Displacement: 413.9 mm

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.

5

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.

2

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.

2

But it's faster since your hand move less and you can keep shift pressed

19
Nilzreply
sopuli.xyz

I use zsh with the sudo plugin. Double tap esc and your current or last command will be prefixed with sudo.

13
piefed.social

Unless you’re in a default screen session (I always thought ^A was such a dumb default for screen to use).

4
lemmy.world

Screen must have been written by someone who wasn't familiar with the shell. It's the only logical explanation.

4

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

3
lemmy.world

You can also just do a sudo !! the !! is a shorthand for whatever you tried to run previously.

144
juipeltjereply
lemmy.world

Was about to say, why would you copy anything when using sudo !! lol

78

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 though

17
literature.cafe

I don't even know what I use anymore. My distro seems to keep changing it when I reinstall.

7
guymontagreply
lemmy.ml

Holy shit I wish fish supported it. I just press up arrow then hold left arrow and manually type sudo. It fucking sucks

2

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.

2
Cavemanreply
lemmy.world

That doesn't work? I would have thought it would work.

1
Nalivaireply
lemmy.world

What shell are you using? In both bash and zsh, !! is a substitute for a previous command

3
Nalivaireply
lemmy.world

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

2
obnomusreply
lemmy.ml

All I do in terminal is type, I don't know scripting. But I heard a lot of things about zsh.

0
Nalivaireply
lemmy.world

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

2

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

21
piefed.ca

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.

17

Thanks to you, I just find out new keyboard shortcut

1
obnomusreply
lemmy.ml

Forgot to mention but only in fish shell.

6

I figured it out, at least in Linux Mint:

  1. Install Keysharp (which includes installing Microsoft's .NET 10 Runtime, but not SDK!)
  2. Put this in a .ks folder:

!s::{ ; Press Alt+S to use sudo on the previous Terminal line
    KeyWait 's'
    If WinActive('ahk_exe gnome-terminal-server')
        Send 'sudo {!}{!}{Enter}'
}

Set it as a Startup Program with the command keysharp "(filepath)/(filename).ks" and it'll always be ready to go!

2

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...

1

I misread this image and have been doing this the past day and it keeps breaking my terminal :(

2
discuss.tchncs.de

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.

9
Epherareply
lemmy.ml

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...

9

THAT'S WHAT IT'S FOR??

Now that I think about it, it does seem pretty obvious.

13

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.

5

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)

8
lemmy.world

Cannot find any reference online. What is this supposed to do? Not at a PC right now.

7
yeehawreply
lemmy.ca

!! 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.

9
TrickDacyreply
lemmy.world

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.

7

Seem to be a fish shell thing.

I tested on my good ole trusty bash and got nothing so I went searching.

EDIT: Clarification : alt+s seems to be a fish shell thing.

5

Ya I haven't tried alt s. Never heard of it before either.

3
softotteepreply
pawb.social

But if you typed in sudo !! Right after, then you're really fucked.

Not if you don't type your password.

1
piefed.social

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 ⬆️

3

I assume if you are silly enough to type in rm -rf /etc, then you are silly enough to type in your password 😅

2

It runs the previous command with sudo, also its only for fish shell.

0

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.

1
obnomusreply
lemmy.ml

Ayo what, I didn't know that but I use fish.

2

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.

1
lemmy.world

I am using fish shell and just tried it. Thanks man. Such a convenient feature NGL

1
programming.dev

Is this a shell thing or a terminal thing? It doesn't work for me on foot.

2
muhybreply
programming.dev

Thanks. I think I should check out fish soon, I keep seeing it a lot lately and it seems to be made for lazy people like me. :)

3
moopetreply
sh.itjust.works

Fish has a bunch or weirdness if you're used to other shells for things like substitution, and shortcuts like $_ don't work afaik.

2
muhybreply
programming.dev

Huh, I checked and noticed that fish is non-POSIX. I guess I'll just stick to zsh but I still want to check fish to see what's all this about.

1

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.

2
BCsvenreply
lemmy.ca

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

1