• kmirl@lemmy.world
    link
    fedilink
    English
    arrow-up
    50
    arrow-down
    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
    27
    arrow-down
    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

    • rtxn@lemmy.worldM
      link
      fedilink
      English
      arrow-up
      28
      ·
      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
        10
        ·
        8 months ago

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

      • huginn@feddit.it
        link
        fedilink
        arrow-up
        2
        ·
        8 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

  • MonkderZweite@feddit.ch
    link
    fedilink
    arrow-up
    11
    ·
    8 months ago

    Kwrite/Kate asks you for password. Seriously, why can’t they all just use pkexec or some abstraction of it?

    Sadly, i currently borked all Qt apps on my Gtk setup.

      • StarDreamer@lemmy.blahaj.zone
        link
        fedilink
        English
        arrow-up
        2
        ·
        8 months ago

        Iirc the specific reason behind this is

        • sudo by default requires a tty to run
        • vim’s bang spawns a tty to execute commands
        • nvim’s bang executes the command directly, then pipes the output to nvim

        As a result, sudo (without args) can’t work in nvim as it doesn’t have a tty to prompt the user for passwords. Nvim also used to do what vim did, but they found out spawning the tty was causing other issues (still present in vim) so they changed it.

        • dream_weasel
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          8 months ago

          There must be more to this. I just launched a terminal and created a file to test with nvim on arch and it works perfectly fine.

          Take a file, sudo chown root:root filename, sudo chmod 700 filename, edit with nvim and save with :w !sudo tee % then reload. Works fine.

          I’m on arch with suckless st.

          Edit:

          Made a demo vid - https://youtu.be/YKZuAvoSW5g

    • jxk
      link
      fedilink
      arrow-up
      3
      ·
      8 months ago

      I love Emacs. Thanks for teaching me someyhing today

  • ѕєχυαℓ ρσℓутσρє@lemmy.sdf.org
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    8 months ago

    Use suda.vim for automatically dealing with such cases. Works with neovim as well.

    I’ll also recommend adding the following to your init.lua or some config file because suda doesn’t play nicely with nvim -d or vimdiff.

    -- Disable Suda in diff views
    if not vim.api.nvim_win_get_option(0, 'diff') then
        vim.g.suda_smart_edit = 1
    end
    

    The vimscript version of the same would be:

    " Disable Suda in diff views
    if ! &diff
        let g:suda_smart_edit = 1
    endif
    
  • Pantherina@feddit.de
    link
    fedilink
    arrow-up
    4
    ·
    8 months ago

    sudoedit is more secure btw. Many editors are not built to be ran as root, and this copies the file to a temo directory, edits it without root, and then overwrites the original file on save with root.

  • Hoimo@ani.social
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    8 months ago

    I am here for one reason and one reason alone: source anime is Watamote, episode 12 @18:36

    Tomoko tries to approach a girl, but the wind confuses her and she runs away in embarrassment, even though the girl was really friendly and would have liked to talk to her.

    In the meme, this scene is used to parallel the feeling of an external system blocking an operation that both participants would agree to.

    A similar feeling could be memed with the “myth of consensual sex” format.