[PATCH] vim: fix redact_pass.vim for macOS

Lakshay Garg lakshayg at outlook.in
Sun Dec 27 21:29:24 CET 2020


Problem: redact_pass.vim did not work on macOS machines
Fix: add resolve($TMPDIR) to the autcmd pattern list

Explanation
===========

pass creates files under /private/var/<some-stuff> on macOS.
redact_pass.vim uses the following pattern to detect when to
enable the plugin:

```
$TMPDIR/pass.?*/?*.txt
```

This pattern expands to "/var/<some-stuff>//pass.?*/?*.txt"
on my macbook and has two problems:

1. The double forward slash in the expanded pattern (after <some-stuff>)
2. pass uses /private/var but the pattern looks for /var

Turns out, /var on macos is just a symlink to /private/var.
The autocmd fails to trigger because it is trying to match
the pattern: "/var/<some-stuff>//pass.?*/?*.txt"
to filename: "/private/var/<some-stuff>/pass.<random-chars>/<random-chars>.txt"

The simplest fix is to make $TMPDIR point to "/private/var/..."
which is achieved by calling resolve on $TMPDIR prior to running
the autocmd. This also handles the double forward-slash.
---
 contrib/vim/redact_pass.vim | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/contrib/vim/redact_pass.vim b/contrib/vim/redact_pass.vim
index 008c8c1..a866a90 100644
--- a/contrib/vim/redact_pass.vim
+++ b/contrib/vim/redact_pass.vim
@@ -41,12 +41,17 @@ function! s:CheckArgsRedact()
 
 endfunction
 
+" $TMPDIR points to a symlink on macOS, which can cause the autocmd pattern to
+" not match because vim seems to be resolving paths before matching patterns
+let $RESOLVED_TMPDIR = resolve($TMPDIR)
+
 " Auto function loads only when Vim starts up
 augroup redact_pass
   autocmd!
   autocmd VimEnter
         \ /dev/shm/pass.?*/?*.txt
         \,$TMPDIR/pass.?*/?*.txt
+        \,$RESOLVED_TMPDIR/pass.?*/?*.txt
         \,/tmp/pass.?*/?*.txt
         \ call s:CheckArgsRedact()
 augroup END
-- 
2.29.2


More information about the Password-Store mailing list