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

SudaWrite failure based on cwd? #48

Open
axieax opened this issue Jun 5, 2022 · 15 comments
Open

SudaWrite failure based on cwd? #48

axieax opened this issue Jun 5, 2022 · 15 comments

Comments

@axieax
Copy link

axieax commented Jun 5, 2022

Was struggling to debug this issue for a while, not sure if this is expected behaviour?

SudaWrite /etc/environment from / ->

image

SudoWrite /etc/environment from /etc -> success

@lambdalisue
Copy link
Owner

Not sure but it seems https://github.com/lambdalisue/suda.vim/blob/master/autoload/suda.vim#L74 fails somehow...

What happen if you directly call suda#write() like (note that it will overwrite the content of /etc/foobar so BE CAREFUL!)

:call suda#write('suda:///etc/foobar')

And

:echo substitute('suda:///etc/foobar', '\v^(suda://)+', '', '')

@axieax
Copy link
Author

axieax commented Jun 5, 2022

:call suda#write('suda:///etc/foobar')

No errors, working as expected

:echo substitute('suda:///etc/foobar', '\v^(suda://)+', '', '')

/etc/foobar

@axieax
Copy link
Author

axieax commented Jun 5, 2022

Debugging:

plugin/suda.vim

  • args in line 28: "/etc/environment"

autoload/suda.vim

  • a:expr: <afile>
  • path in line 74 and onwards: "uda:///etc/environment"

@lambdalisue
Copy link
Owner

It's quite strange. What happen if you modify the code like

function! suda#write(expr, ...) abort range
  echomsg "expr:" . a:expr
  echomsg "expand:" . expand(a:expr)
  echomsg "path:" . s:strip_prefix(expand(a:expr))
  " Original code starts from here
  let path = s:strip_prefix(expand(a:expr))
  " ...

@axieax
Copy link
Author

axieax commented Jun 5, 2022

Sometimes I have issues, sometimes not..

Successful (call nvim /etc/environment from user home directory, or nvim environment from /etc):
image

Fail (call nvim /etc/environment from root directory):
image

@lambdalisue
Copy link
Owner

What about

function! suda#write(expr, ...) abort range
  echomsg "expr:" . a:expr
  echomsg "expand:" . expand(a:expr)
  echomsg "bufname:" . bufname("%")
  echomsg "expand:" . expand("%")
  echomsg "path:" . s:strip_prefix(expand(a:expr))
  " Original code starts from here
  let path = s:strip_prefix(expand(a:expr))
  " ...

@axieax
Copy link
Author

axieax commented Jun 13, 2022

image

@lambdalisue
Copy link
Owner

It's quite puzzling... I'm sorry but I've no idea...

@axieax
Copy link
Author

axieax commented Aug 27, 2022

Thought this was an issue with my Linux permissions after removing some shada files, but it seems that I can also reproduce this on my Mac. Just wondering if you are able to reproduce this as well?

@lambdalisue
Copy link
Owner

How to reproduce the issue?

@axieax
Copy link
Author

axieax commented Aug 27, 2022

Fail (call nvim /etc/environment from root directory)

Then launch :SudaWrite

@lambdalisue
Copy link
Owner

Then I could not reproduce it

@aarondill
Copy link
Collaborator

aarondill commented Jun 27, 2023

@axieax I can not reproduce this either. Is your vim config available online?

@axieax
Copy link
Author

axieax commented Jun 27, 2023

Hi, yes it's available in my dotconfig repo: https://www.github.com/axieax/dotconfig

@aarondill
Copy link
Collaborator

Have you tried reproducing this since your migration to lazy.nvim?

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

No branches or pull requests

3 participants