Comments (4)
Interesting. I'd love to see the PR.
My thought for the idea are
- I don't think the internal code need to be changed a lot. Adding extra BufReadPre and FileReadPre seems enough (not confirme)
- The behavior need to be optional while some users would prefer explicit way
- Using BufWritePre/FileWritePre may help for writing a file which only miss a write permission
Thanks for your idea :-]
from suda.vim.
Hello again @lambdalisue,
I've started working on this PR and I have already wrote a nice function that returns if sudo
is needed at all for a given file, it considers if we know it exists and if we can read it's parent directories contents and their permissions.
I'm not sure whether a new configuration variable should be introduced or whether we should call suda#init()
differently according to a g:suda#prefix
which would be empty? My vision is that it would be much more elegant if a user wanting to change the prefix or make the plugin act automatically would add a single command in his init.vim
, something like this:
call suda#init('sudo:*')
I must say that I find the current relationship between g:suda#prefix
and suda#init()
rather complicated. For example, IMO, having to write 2 lines just to change the prefix makes things a little bit confusing.
What do you think about this patch:
autoload/suda.vim | 16 ++++++----------
doc/suda.txt | 5 ++---
plugin/suda.vim | 2 +-
3 files changed, 9 insertions(+), 14 deletions(-)
diff --git c/autoload/suda.vim i/autoload/suda.vim
index fa623d9..5e0a3f4 100644
--- c/autoload/suda.vim
+++ i/autoload/suda.vim
@@ -1,11 +1,11 @@
-function! suda#init(...) abort
- let pat = a:0 ? a:1 : printf('%s*', g:suda#prefix)
+function! suda#init(pat) abort
+ let g:suda#prefix = a:pat[:-2]
augroup suda_internal
autocmd! *
- execute printf('autocmd BufReadCmd %s call suda#BufReadCmd()', pat)
- execute printf('autocmd FileReadCmd %s call suda#FileReadCmd()', pat)
- execute printf('autocmd BufWriteCmd %s call suda#BufWriteCmd()', pat)
- execute printf('autocmd FileWriteCmd %s call suda#FileWriteCmd()', pat)
+ execute printf('autocmd BufReadCmd %s call suda#BufReadCmd()', a:pat)
+ execute printf('autocmd FileReadCmd %s call suda#FileReadCmd()', a:pat)
+ execute printf('autocmd BufWriteCmd %s call suda#BufWriteCmd()', a:pat)
+ execute printf('autocmd FileWriteCmd %s call suda#FileWriteCmd()', a:pat)
augroup END
endfunction
@@ -247,7 +247,3 @@ function! s:doautocmd(name) abort
\ fnameescape(expand('<afile>'))
\)
endfunction
-
-
-" Configure
-let g:suda#prefix = get(g:, 'suda#prefix', 'suda://')
diff --git c/doc/suda.txt i/doc/suda.txt
index d0d28d4..7aead83 100644
--- c/doc/suda.txt
+++ i/doc/suda.txt
@@ -117,10 +117,9 @@ g:suda#prefix
QUESTIONS *suda-questions*
Q. How to use "sudo:" instead of "suda://" like "sudo.vim".
-A. Use |g:suda#prefix|| like below.
+A. Call |suda#init| with a pattern of your choice.
>
- let g:suda#prefix = 'sudo:'
- call suda#init('sudo:*,sudo:*/*')
+ call suda#init('sudo:*')
<
Q. How to use SudoRead/SudoWrite command like "sudo.vim".
A. Write the following scripts in your |vimrc|.
diff --git c/plugin/suda.vim i/plugin/suda.vim
index 9ed1c74..e7187ae 100644
--- c/plugin/suda.vim
+++ i/plugin/suda.vim
@@ -4,5 +4,5 @@ endif
let g:loaded_suda = 1
if get(g:, 'suda_startup', 1)
- call suda#init()
+ call suda#init('suda://*')
endif
from suda.vim.
You said "make it completely automatic", mean that users with your optional feature actually do not need to use suda://
prefix or whatever.
So I think you don't need to care about g:suda#prefix
, just overwrite the default value forcedly.
" autoload/suda.vim
function! suda#init(...) abort
" ...
endfunction
function! suda#init_auto() abort
let g:suda#prefix = 'suda://'
call suda#init()
" autocmd for normal files
augroup suda_auto_internal
autocmd BufReadCmd * call suda#YOUR_OPTIONAL_FEATURE_BufReadCmd()
autocmd BufWriteCmd * call suda#YOUR_OPTIONAL_FEATURE_BufWriteCmd()
" ...
augroup END
endfunction
" plugin/suda.vim
if get(g:, 'suda_startup', 1)
if get(g:, 'suda_automode')
call suda#init_auto()
else
call suda#init()
endif
endif
from suda.vim.
This seems rather too complicated IMO but I don't have enough experience to judge or suggest a better idea so I'll stick with this in the meantime.
from suda.vim.
Related Issues (20)
- Prompt to re-read file after SudaWrite HOT 2
- lost suda#prefix option HOT 1
- [suda] dd: failed to open 'suda:///etc/i3blocks.conf': No Such file or directory HOT 1
- SudaWrite failure based on cwd? HOT 15
- Problem with -p flag HOT 2
- How do I install this? HOT 1
- Duplicate buffers with smart edit HOT 4
- neovim lsp jump to definition throws error on readonly files when using suda_smart_edit HOT 3
- When sudo is configured to ask for a fingerprint, suda halts for a long time HOT 1
- suda does not work when `sudo` command is aliased to something else HOT 3
- How can I set this variable in nvim lua? HOT 11
- Cannot activate suda_smart_edit HOT 4
- suda:///the/path/of/file will disable language server's jumpDefinition HOT 2
- Empty "suda:" directory created in $HOME on write HOT 2
- Prompt on new buffer with g:suda_smart_edit and g:suda#nopass HOT 5
- suda cannot handle files that include '#' in the name HOT 1
- bug suda.vim seems to not be working with lazy.nvim
- Problems with suda_smart_edit if it's set after the plugin loaded. [[SOLVED]]
- Duplicate tag "suda" in doc
- Rename undescriptive name `suda#nopass` to more descriptive name like `suda#...something...` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from suda.vim.