From a5ca6fe8aff145b000be1c10e54454d70a2516bb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 22 Jun 2019 13:14:44 +1200 Subject: Add fortune.vim plugin as I've got it --- vim/plugin/fortune.vim | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 vim/plugin/fortune.vim (limited to 'vim') diff --git a/vim/plugin/fortune.vim b/vim/plugin/fortune.vim new file mode 100644 index 00000000..e52f50af --- /dev/null +++ b/vim/plugin/fortune.vim @@ -0,0 +1,50 @@ +let s:paths = [ + \ $HOME.'/.fortunes', + \ $HOME.'/.local/share/games/fortunes', + \] +highlight Fortune + \ term=NONE + \ cterm=NONE ctermfg=248 ctermbg=NONE + +function! s:Fortune() abort + if !has('unix') + echoerr 'Only works on *nix' + endif + if !executable('fortune') + echoerr 'Missing "fortune" executable' + endif + if !executable('timeout') + echoerr 'Missing "timeout" executable' + endif + let limit = &columns - 1 + let command = [ + \ 'timeout', + \ '0.3s', + \ 'fortune', + \ '-s', + \ '-n', + \ limit, + \] + for path in s:paths + if isdirectory(path) + call add(command, path) + break + endif + endfor + let fortune = substitute( + \ system(join(command)), + \ '[[:cntrl:]]\+', + \ ' ', + \ 'g', + \) + echohl Fortune + echo fortune + echohl None +endfunction +command! -bar Fortune + \ call s:Fortune() +augroup fortune + autocmd! + autocmd VimEnter * + \ if !argc() && line2byte('$') == -1 | Fortune | endif +augroup END -- cgit v1.2.3