Last active
October 16, 2023 20:37
-
-
Save fanf/bad235a1b587eeb176c0 to your computer and use it in GitHub Desktop.
vimrc config to auto decrypt/encrypt .gpg files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" GPG config | |
" Don't save backups of *.gpg files | |
set backupskip+=*.gpg | |
" To avoid that parts of the file is saved to .viminfo when yanking or | |
" deleting, empty the 'viminfo' option. | |
set viminfo= | |
augroup encrypted | |
au! | |
" Disable swap files, and set binary file format before reading the file | |
autocmd BufReadPre,FileReadPre *.gpg | |
\ setlocal noswapfile bin | |
" Decrypt the contents after reading the file, reset binary file format | |
" and run any BufReadPost autocmds matching the file name without the .gpg | |
" extension | |
autocmd BufReadPost,FileReadPost *.gpg | |
\ execute "'[,']!gpg --decrypt --default-recipient-self" | | |
\ setlocal nobin | | |
\ execute "doautocmd BufReadPost " . expand("%:r") | |
" Set binary file format and encrypt the contents before writing the file | |
autocmd BufWritePre,FileWritePre *.gpg | |
\ setlocal bin | | |
\ '[,']!gpg --encrypt --default-recipient-self | |
" After writing the file, do an :undo to revert the encryption in the | |
" buffer, and reset binary file format | |
autocmd BufWritePost,FileWritePost *.gpg | |
\ silent u | | |
\ setlocal nobin | |
augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment