aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-22 13:36:03 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-22 13:37:18 +1200
commit045d9242bec6c67c789c2656943de3aa8640d54b (patch)
treeee20a26dc3590120cf1a095ab623cf47e6078f91 /vim
parenta6bbfa1a9b3b5c082ab313d7ff42d82394a43242 (diff)
downloaddotfiles-045d9242bec6c67c789c2656943de3aa8640d54b.tar.gz
dotfiles-045d9242bec6c67c789c2656943de3aa8640d54b.zip
Flesh out fortune.vim a little more
Diffstat (limited to 'vim')
-rw-r--r--vim/autoload/fortune.vim48
-rw-r--r--vim/plugin/fortune.vim1
2 files changed, 34 insertions, 15 deletions
diff --git a/vim/autoload/fortune.vim b/vim/autoload/fortune.vim
index 4fb1d0cd..dbb4c7c4 100644
--- a/vim/autoload/fortune.vim
+++ b/vim/autoload/fortune.vim
@@ -2,42 +2,60 @@ let s:paths = [
\ $HOME.'/.fortunes',
\ $HOME.'/.local/share/games/fortunes',
\]
-highlight Fortune
- \ term=NONE
- \ cterm=NONE ctermfg=248 ctermbg=NONE
+
+let s:executables = [
+ \ 'fortune',
+ \ 'timeout',
+ \]
+
+function! s:Highlight() abort
+ highlight Fortune
+ \ term=NONE
+ \ cterm=NONE ctermfg=248 ctermbg=NONE
+ \ gui=NONE guifg=#585858 guibg=NONE
+endfunction
+augroup fortune
+ autocmd!
+ autocmd ColorScheme *
+ \ call s:Highlight()
+augroup END
+doautocmd fortune ColorScheme
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
+
+ for executable in s:executables
+ if !executable(executable)
+ echoerr 'Missing executable "'.executable.'"'
+ endif
+ endfor
+
let limit = &columns - 1
+
let command = [
\ 'timeout',
\ '0.3s',
\ 'fortune',
- \ '-s',
- \ '-n',
+ \ '-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:]]\+',
+ \ '[[:cntrl:][:space:]]\+',
\ ' ',
\ 'g',
\)
+
echohl Fortune
echo fortune
echohl None
+
endfunction
diff --git a/vim/plugin/fortune.vim b/vim/plugin/fortune.vim
index 825ed9f7..6681312a 100644
--- a/vim/plugin/fortune.vim
+++ b/vim/plugin/fortune.vim
@@ -1,5 +1,6 @@
command! -bar Fortune
\ call fortune#()
+
augroup fortune
autocmd!
autocmd VimEnter *