aboutsummaryrefslogtreecommitdiff
path: root/plugin/redact_pass.vim
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/redact_pass.vim')
-rw-r--r--plugin/redact_pass.vim43
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