Pantherina,

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,

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.

Waffelson,
SexualPolytope, (edited )
@SexualPolytope@lemmy.sdf.org avatar

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.


<span style="font-style:italic;color:#969896;">-- Disable Suda in diff views
</span><span style="font-weight:bold;color:#a71d5d;">if not</span><span style="color:#323232;"> vim.api.nvim_win_get_option(</span><span style="color:#0086b3;">0</span><span style="color:#323232;">, </span><span style="color:#183691;">'diff'</span><span style="color:#323232;">) </span><span style="font-weight:bold;color:#a71d5d;">then
</span><span style="color:#323232;">    vim.g.suda_smart_edit </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#0086b3;">1
</span><span style="font-weight:bold;color:#a71d5d;">end
</span>

The vimscript version of the same would be:


<span style="color:#323232;">" Disable Suda in diff views
</span><span style="color:#323232;">if ! &diff
</span><span style="color:#323232;">    let g:suda_smart_edit = 1
</span><span style="color:#323232;">endif
</span>
hex_m_hell,

C-x C-f /sudo::/path/to/file

jxk,

I love Emacs. Thanks for teaching me someyhing today

RoyaltyInTraining,
@RoyaltyInTraining@lemmy.world avatar

One of the many reasons why I use micro

huginn,

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

dukk,

Lazier way:

:w !sudo tee %

huginn,

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,

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

huginn,

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

MonkderZweite,

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.

caseyweederman,

So does Micro. Nano… Nano does not.

MonkderZweite,

Eh, on console i can just do ssu nano <file>. Graphical editors are in question.

stardreamer,
@stardreamer@lemmy.blahaj.zone avatar

<span style="color:#323232;">:w !sudo tee %
</span>

Warning: does not work for neovim

cybersandwich,

Neovim, the one true vim, why hast thou forsaken me.

stardreamer,
@stardreamer@lemmy.blahaj.zone avatar

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, (edited )

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 - youtu.be/YKZuAvoSW5g

dream_weasel,

sure it works in neovim

I didn’t do any editing since it’s just to prove a point, but I think it does fine.

kmirl,

<span style="color:#323232;">fuck() {
</span><span style="color:#323232;">    sudo $(fc -ln -1)
</span><span style="color:#323232;">} 
</span>

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.


<span style="color:#323232;">kmirl@tux:~$ ls /root
</span><span style="color:#323232;">ls: cannot open directory '/root': Permission denied
</span><span style="color:#323232;">kmirl@tux:~$ fuck
</span><span style="color:#323232;">[sudo] password for kmirl: 
</span><span style="color:#323232;">bin  debs  docs  Mail 
</span>
Esca,

Isn’t this the same effect as just running ‘sudo !!’ ?

Cinnamon3431,

no because it takes the previous command and adds sudo to it right?

subtext, (edited )

!! is a shortcut for whatever the last command was is it not?

E: devhints.io/bash#history

subtext,

According to this super user question, someone said that !! won’t work in a function, so you must use the fc -ln -1 command in a subshell instead. Note the response that says eval shouldn’t be used (not sure why)

Johanno,

Eval shouldn’t be used on userinput. Meaning that if smb other than you may use this to change the system he could put malicious code in the eval part.

Probably doesn’t matter on shell level

Esca,

Yeah but instead of a function you just make it an alias.

subtext,

Oh good point, I didn’t think about that

Rustmilian, (edited )
@Rustmilian@lemmy.world avatar

<span style="color:#62a35c;">alias </span><span style="font-weight:bold;color:#795da3;">fuck</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">'sudo $(fc -ln -1)'
</span>
folkrav,

Considering the function name, here’s an obligatory thefuck plug

bjoern_tantau,
@bjoern_tantau@swg-empire.de avatar

Is there an editor that can request root privileges without restarting it? That would be quite useful.

django,
chtk,
@chtk@feddit.nl avatar

(n)vim + suda.vim.

h3rm17,

In vim, in normal mode you can do: :w !sudo tee %

z3rOR0ne,
@z3rOR0ne@lemmy.ml avatar

Apparently that doesn’t work in NeoVim, so recently I installed the suda plugin.

Personally, I just doas nvim and then the file name that needs root access, but it’s a handy plugin in case I forget.

dream_weasel,

??? I used this in neovim twice today

:w !sudo tee % then reload when it asks.

YodaDaCoda,
@YodaDaCoda@sh.itjust.works avatar

kate does this in KDE, but it’s not cli.

eager_eagle,
@eager_eagle@lemmy.world avatar

micro ftw, no need to even memorize a command, it’ll just ask if you want to use sudo

hex_m_hell, (edited )

Yeah, in emacs you use tramp to open the file with /sudo::

Botzo,

It’s a simple trick in Vim:

stackoverflow.com/a/7078429

For the lazy: :w !sudo tee > /dev/null %

Vilian,

i use micro

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linuxmemes@lemmy.world
  • ethstaker
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • ngwrru68w68
  • cubers
  • thenastyranch
  • Youngstown
  • rosin
  • slotface
  • cisconetworking
  • mdbf
  • kavyap
  • Durango
  • megavids
  • khanakhh
  • GTA5RPClips
  • anitta
  • osvaldo12
  • everett
  • normalnudes
  • tester
  • tacticalgear
  • provamag3
  • modclub
  • Leos
  • JUstTest
  • lostlight
  • All magazines