Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions plugin/eunuch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,28 @@ command! -bar SudoWrite
endif

function! s:SudoEditInit() abort
let files = split($SUDO_COMMAND, ' ')[1:-1]
if len(files) ==# argc()
for i in range(argc())
let ppid = system('ps -o ppid:1= -p ' . getpid())
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears not to work on BSD ps. Tested on macOS.

let files = split( system( "ps -o command= -p " . trim(ppid) ) )

if files[0] == 'sudoedit'
for i in range(len(files)-1)
execute 'autocmd BufEnter' s:fnameescape(argv(i))
\ 'if empty(&filetype) || &filetype ==# "conf"'
\ '|doautocmd filetypedetect BufReadPost' s:fnameescape(files[i+1])
\ '|endif'
endfor
endif
if files[0] == 'sudo' && files[1] == '-e'
for i in range(len(files)-2)
execute 'autocmd BufEnter' s:fnameescape(argv(i))
\ 'if empty(&filetype) || &filetype ==# "conf"'
\ '|doautocmd filetypedetect BufReadPost' s:fnameescape(files[i])
\ '|doautocmd filetypedetect BufReadPost' s:fnameescape(files[i+2])
\ '|endif'
endfor
endif
endfunction
if $SUDO_COMMAND =~# '^sudoedit '
let file_name = expand('%:t:p')
if file_name =~# '.\{-}\(XX\)\@='
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't portable either. XX appears to be Linux specific.

call s:SudoEditInit()
endif

Expand Down