blob: 4fb1d0cd6f2b65f6c8ac5fce5b4a207d76688e56 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
|