aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-22 13:14:44 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-22 13:14:44 +1200
commita5ca6fe8aff145b000be1c10e54454d70a2516bb (patch)
treed22b2f78caeeecd1751084a7dd777c0abbcaf3ed
parentClean up Vim indent settings a bit (diff)
downloaddotfiles-a5ca6fe8aff145b000be1c10e54454d70a2516bb.tar.gz
dotfiles-a5ca6fe8aff145b000be1c10e54454d70a2516bb.zip
Add fortune.vim plugin as I've got it
-rw-r--r--vim/plugin/fortune.vim50
1 files changed, 50 insertions, 0 deletions
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