diff options
author | Mike Crute <mike@crute.us> | 2020-06-18 20:27:41 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2020-06-18 20:27:41 +0000 |
commit | 27379c96ba20f95f38fd6546600644cb88e5c73e (patch) | |
tree | 483e36d0288f42aa978a0086ced2a6d3dc89b2b0 /.vim | |
parent | 20990645bc05d9acd17a173efddb18374ea3d839 (diff) | |
download | dotfiles-27379c96ba20f95f38fd6546600644cb88e5c73e.tar.bz2 dotfiles-27379c96ba20f95f38fd6546600644cb88e5c73e.tar.xz dotfiles-27379c96ba20f95f38fd6546600644cb88e5c73e.zip |
vim: pass plugin
Diffstat (limited to '.vim')
-rw-r--r-- | .vim/ftdetect/redact_pass.vim | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/.vim/ftdetect/redact_pass.vim b/.vim/ftdetect/redact_pass.vim new file mode 100644 index 0000000..a3d67e8 --- /dev/null +++ b/.vim/ftdetect/redact_pass.vim | |||
@@ -0,0 +1,51 @@ | |||
1 | " | ||
2 | " redact_pass.vim: Switch off the 'viminfo', 'backup', 'writebackup', | ||
3 | " 'swapfile', and 'undofile' globally when editing a password in pass(1). | ||
4 | " | ||
5 | " This is to prevent anyone being able to extract passwords from your Vim | ||
6 | " cache files in the event of a compromise. | ||
7 | " | ||
8 | " Author: Tom Ryder <tom@sanctum.geek.nz> | ||
9 | " License: Same as Vim itself | ||
10 | " | ||
11 | if exists('g:loaded_redact_pass') || &compatible | ||
12 | finish | ||
13 | endif | ||
14 | if !has('autocmd') || v:version < 600 | ||
15 | finish | ||
16 | endif | ||
17 | let g:loaded_redact_pass = 1 | ||
18 | |||
19 | " Check whether we should set redacting options or not | ||
20 | function! s:CheckArgsRedact() | ||
21 | |||
22 | " Ensure there's one argument and it's the matched file | ||
23 | if argc() != 1 || fnamemodify(argv(0), ':p') !=# expand('<afile>:p') | ||
24 | return | ||
25 | endif | ||
26 | |||
27 | " Disable all the leaky options globally | ||
28 | set nobackup | ||
29 | set nowritebackup | ||
30 | set noswapfile | ||
31 | set viminfo= | ||
32 | if has('persistent_undo') | ||
33 | set noundofile | ||
34 | endif | ||
35 | |||
36 | " Tell the user what we're doing so they know this worked, via a message and | ||
37 | " a global variable they can check | ||
38 | echomsg 'Editing password file--disabled leaky options!' | ||
39 | let g:redact_pass_redacted = 1 | ||
40 | |||
41 | endfunction | ||
42 | |||
43 | " Auto function loads only when Vim starts up | ||
44 | augroup redact_pass | ||
45 | autocmd! | ||
46 | autocmd VimEnter | ||
47 | \ /dev/shm/pass.?*/?*.txt | ||
48 | \,$TMPDIR/pass.?*/?*.txt | ||
49 | \,/tmp/pass.?*/?*.txt | ||
50 | \ call s:CheckArgsRedact() | ||
51 | augroup END | ||