" Mail file type extension to pick files for attachments via vifm
" Maintainer: xaizek <xaizek@posteo.net>
" Last Change: June 22, 2020
" Insert attachment picked via vifm after 'Subject' header
function! s:AddMailAttachments()
call vifm#globals#Init()
" XXX: similar code is in plugins/vifm.vim, but it's different in details
let l:listf = tempname()
if !has('nvim')
if has('gui_running')
execute 'silent !' g:vifm_term g:vifm_exec
\ '--choose-files' shellescape(l:listf, 1)
\ g:vifm_exec_args
else
execute 'silent !' g:vifm_exec
\ '--choose-files' shellescape(l:listf, 1)
\ g:vifm_exec_args
endif
redraw!
call s:HandleRunResults(v:shell_error, l:listf)
else
" Work around handicapped neovim...
let callback = { 'listf': l:listf }
function! callback.on_exit(id, code, event)
buffer #
silent! bdelete! #
call s:HandleRunResults(a:code, self.listf)
endfunction
enew
call termopen(g:vifm_exec . ' --choose-files ' . shellescape(l:listf, 1)
\. ' ' . g:vifm_exec_args, callback)
startinsert
endif
endfunction
function! s:HandleRunResults(exitcode, listf)
if a:exitcode != 0
echoerr 'Got non-zero code from vifm: ' . a:exitcode
call delete(a:listf)
return
endif
let l:insert_pos = search('^Subject:', 'nw')
if filereadable(a:listf) && l:insert_pos != 0
for line in readfile(a:listf)
call append(l:insert_pos, 'Attach: '.escape(line, " "))
let l:insert_pos += 1
endfor
endif
call delete(a:listf)
endfunction
nnoremap <buffer> <silent> <localleader>a :call <sid>AddMailAttachments()<cr>
" vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 :
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master