• Ephera@lemmy.ml
      link
      fedilink
      arrow-up
      31
      ·
      17 days ago

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

      • printf("%s", name);@piefed.blahaj.zone
        link
        fedilink
        English
        arrow-up
        59
        ·
        edit-2
        17 days ago

        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
          link
          fedilink
          arrow-up
          14
          ·
          17 days ago

          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
          link
          fedilink
          English
          arrow-up
          4
          ·
          10 days ago

          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.

          • printf("%s", name);@piefed.blahaj.zone
            link
            fedilink
            English
            arrow-up
            2
            ·
            edit-2
            10 days ago

            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
              link
              fedilink
              English
              arrow-up
              2
              ·
              10 days ago

              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.

      • Nilz@sopuli.xyz
        link
        fedilink
        arrow-up
        13
        ·
        17 days ago

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

      • ClownStatue@piefed.social
        link
        fedilink
        English
        arrow-up
        3
        ·
        17 days ago

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

          • ClownStatue@piefed.social
            link
            fedilink
            English
            arrow-up
            2
            ·
            edit-2
            16 days ago

            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

  • Caveman@lemmy.world
    link
    fedilink
    arrow-up
    138
    arrow-down
    1
    ·
    edit-2
    17 days ago

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

  • insufferableninja@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    21
    ·
    17 days ago

    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

  • Albbi@piefed.ca
    link
    fedilink
    English
    arrow-up
    16
    ·
    17 days ago

    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.

      • Mountainaire@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        10 days ago

        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…

        • Mountainaire@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          10 days ago

          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!

    • sem@piefed.blahaj.zone
      link
      fedilink
      English
      arrow-up
      2
      ·
      14 days ago

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

  • eco_game@discuss.tchncs.de
    link
    fedilink
    arrow-up
    9
    ·
    17 days ago

    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.

  • TrickDacy@lemmy.world
    link
    fedilink
    arrow-up
    8
    arrow-down
    1
    ·
    edit-2
    17 days ago

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

    • yeehaw@lemmy.ca
      link
      fedilink
      arrow-up
      9
      ·
      17 days ago

      !! 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
        link
        fedilink
        arrow-up
        8
        arrow-down
        1
        ·
        17 days ago

        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
          link
          fedilink
          arrow-up
          5
          ·
          edit-2
          17 days ago

          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.

      • softotteep@pawb.social
        link
        fedilink
        English
        arrow-up
        1
        ·
        17 days ago

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

        Not if you don’t type your password.

        • ClownStatue@piefed.social
          link
          fedilink
          English
          arrow-up
          3
          ·
          17 days ago

          Adding to this, if you notice numbers next to your previous commands when you run history, you can do !<number> and it will rerun that command. Probably the second cool shell trick I learned back in the olden days or yore (mid-90s?) after ⬆️

        • yeehaw@lemmy.ca
          link
          fedilink
          arrow-up
          2
          ·
          17 days ago

          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.mlOP
      link
      fedilink
      English
      arrow-up
      1
      arrow-down
      1
      ·
      16 days ago

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

      • jenesaisquoi@feddit.org
        link
        fedilink
        English
        arrow-up
        1
        ·
        16 days ago

        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.

      • x0x7@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        14 days ago

        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
        link
        fedilink
        arrow-up
        3
        ·
        17 days ago

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

        • moopet@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          2
          ·
          16 days ago

          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
            link
            fedilink
            arrow-up
            1
            ·
            16 days ago

            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.

            • moopet@sh.itjust.works
              link
              fedilink
              English
              arrow-up
              2
              ·
              15 days ago

              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.

    • BCsven@lemmy.ca
      link
      fedilink
      arrow-up
      1
      ·
      17 days ago

      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