• kmirl@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    8 months ago
    fuck() {
        sudo $(fc -ln -1)
    } 
    

    This function takes the last command and puts sudo in front of it. Actually used it in a zoom call at work without thinking and it took a second to realize why everyone was laughing. Not my invention–came across it years ago on stackoverflow or someplace and thought it was funny/useful.

    kmirl@tux:~$ ls /root
    ls: cannot open directory '/root': Permission denied
    kmirl@tux:~$ fuck
    [sudo] password for kmirl: 
    bin  debs  docs  Mail 
    
  • huginn@feddit.it
    link
    fedilink
    arrow-up
    1
    ·
    8 months ago

    Lazy vim way I do it:

    ggVG"wY:q! followed by sudo !! then VG"wp:x

    Grab entire file and stuff it in register W

    Exit file

    Reopen sudo

    Select all and replace with register W them write

      • huginn@feddit.it
        link
        fedilink
        arrow-up
        1
        ·
        7 months ago

        Yeah learning about tee from this thread honestly.

        It’s been interesting realizing I had such a useful tool at my disposal but never knew

    • rtxn@lemmy.worldM
      link
      fedilink
      English
      arrow-up
      1
      ·
      8 months ago

      Now I understand how the Adeptus Mechanicus feel when they perform a ritual power-on.

      • huginn@feddit.it
        link
        fedilink
        arrow-up
        1
        ·
        8 months ago

        It’s funny how years of use make that so intuitive but spelled out it’s a garbled mess