aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/fortune.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/autoload/fortune.vim')
-rw-r--r--vim/autoload/fortune.vim43
1 files changed, 43 insertions, 0 deletions
diff --git a/vim/autoload/fortune.vim b/vim/autoload/fortune.vim
new file mode 100644
index 00000000..4fb1d0cd
--- /dev/null
+++ b/vim/autoload/fortune.vim
@@ -0,0 +1,43 @@
+let s:paths = [
+ \ $HOME.'/.fortunes',
+ \ $HOME.'/.local/share/games/fortunes',
+ \]
+highlight Fortune
+ \ term=NONE
+ \ cterm=NONE ctermfg=248 ctermbg=NONE
+
+function! 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