Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SudoWrite is stuck after typing password #45

Closed
doronbehar opened this issue Oct 18, 2016 · 9 comments
Closed

SudoWrite is stuck after typing password #45

doronbehar opened this issue Oct 18, 2016 · 9 comments

Comments

@doronbehar
Copy link

I get this weird behavior: After typing the password and pressing Enter, the shell seems to be stuck and I have to press a few times in order to stop it, Afterwards the file is not saved and I don't gain sudo permissions. I tried change the function! s:SudoWriteCmd() and it worked, but it seems weird to make a pull request about it because I don't know what doesn't work in the original function.
my version for the function is as follow:

function! s:SudoWriteCmd() abort
  execute (has('gui_running') ? '' : 'silent') 'write !sudo tee "%"'
  let &modified = v:shell_error
endfunction

And your version for the execute command is:

  execute (has('gui_running') ? '' : 'silent') 'write !env SUDO_EDITOR=tee VISUAL=tee sudo -e "%" >/dev/null'

What is the purpose of > /dev/null? Why wouldn't you keep it simple like in my version?

@hiberabyss
Copy link

I have the same problem.

@tpope
Copy link
Owner

tpope commented May 3, 2017

I think we could probably drop the >/dev/null when silent is given (i.e., when the gui is running), if that helps.

@tpope
Copy link
Owner

tpope commented Jun 8, 2017

To answer the actual questions:

  1. Depending on the terminal of lack thereof, omitting >/dev/null can allow the entire file to be flooded to stdout, sometimes visible as flickering. Dropping it is not necessarily a deal breaker.
  2. The rest of the construct is to use sudoedit permissions rather than tee. See --edit in sudo(8).

tpope added a commit that referenced this issue Jun 8, 2017
@doronbehar
Copy link
Author

doronbehar commented Jun 16, 2017

I'm not sure how to start implementing this myself but it crossed my mind that perhaps it could be possible to use su -c instead of sudo. Would that break any other features of the plugin?

@tpope
Copy link
Owner

tpope commented Jun 16, 2017

Well su is a completely different security model, requiring the root password rather than the user password. I could maybe see supporting it as a fallback, if people actually want that sort of thing, but I don't see it as a solution to the hanging problem.

On a related note, I did switch things up to use -A (--askpass) in the GUI, which I think is probably a better solution to your problem? Assuming you're experiencing the problem in a GUI Vim.

@doronbehar
Copy link
Author

doronbehar commented Jun 16, 2017 via email

@tpope
Copy link
Owner

tpope commented Jun 17, 2017

Oh that's a whole nother kettle of fish. Neovim essentially forces you to use :terminal for any interactive command, and I doubt that's an option in BufReadCmd. I don't understand why your proposed fix in the original issue would help, but I could easily be missing something.

@kiooss
Copy link

kiooss commented Mar 17, 2018

The neovim issue is this neovim/neovim#1716 .
But strangely :SudoWrite works in neovim on my Ubuntu but not macOS version.

tpope added a commit that referenced this issue Mar 17, 2018
@tpope
Copy link
Owner

tpope commented Mar 17, 2018

I just changed it use -A for local Neovim instances, which might work around the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants