diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-24 01:46:50 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-24 01:49:13 +1200 |
commit | b816873507fb35e413f041c01cb63688836faed4 (patch) | |
tree | a00cc3b522b0b010a3786e64a3f679967b07d518 | |
parent | Bump VERSION (diff) | |
download | vim-redact-pass-b816873507fb35e413f041c01cb63688836faed4.tar.gz vim-redact-pass-b816873507fb35e413f041c01cb63688836faed4.zip |
Drastically simplify filename detection
I don't know why a simple match on the VimEnter autocmd didn't occur to
me before.
-rw-r--r-- | plugin/redact_pass.vim | 43 |
1 files changed, 7 insertions, 36 deletions
diff --git a/plugin/redact_pass.vim b/plugin/redact_pass.vim index cf6dcbf..a3d67e8 100644 --- a/plugin/redact_pass.vim +++ b/plugin/redact_pass.vim @@ -16,44 +16,11 @@ if !has('autocmd') || v:version < 600 endif let g:loaded_redact_pass = 1 -" Pattern to match for the portion of the path after the temporary dir, -" starting with the leading slash -let s:pattern = '\m\C/pass\.[^/]\+/[^/]\+\.txt$' - -" Check whether the given dir name is not an empty string, whether the first -" file in the argument list is within the named dir, and that the whole path -" matches the above pattern immediately after that dir name -function! s:PassPath(root) - - " Check we actually got a value, i.e. this wasn't an empty environment - " variable - if !strlen(a:root) - return 0 - endif - - " Full resolved path to the root dir with no trailing slashes - let l:root = fnamemodify(a:root, ':p:h') - - " Full resolved path to the first file in the arg list - let l:path = fnamemodify(argv(0), ':p') - - " Check the string all match and at the expected points - return stridx(l:path, l:root) == 0 - \ && strlen(l:root) == match(l:path, s:pattern) - -endfunction - " Check whether we should set redacting options or not function! s:CheckArgsRedact() - " Short-circuit unless we're editing just one file and it looks like a path - " in one of the three expected directories; we're trying hard to make sure - " this really is a password file and we're not messing with the user's - " precious settings unnecessarily - if argc() != 1 - \ || !s:PassPath('/dev/shm') - \ && !s:PassPath($TMPDIR) - \ && !s:PassPath('/tmp') + " Ensure there's one argument and it's the matched file + if argc() != 1 || fnamemodify(argv(0), ':p') !=# expand('<afile>:p') return endif @@ -76,5 +43,9 @@ endfunction " Auto function loads only when Vim starts up augroup redact_pass autocmd! - autocmd VimEnter * call s:CheckArgsRedact() + autocmd VimEnter + \ /dev/shm/pass.?*/?*.txt + \,$TMPDIR/pass.?*/?*.txt + \,/tmp/pass.?*/?*.txt + \ call s:CheckArgsRedact() augroup END |