Refactoring: g:startify_custom_header
This commit is contained in:
parent
d66c31f02e
commit
fbcba230e9
|
@ -75,8 +75,11 @@ function! startify#insane_in_the_membrane() abort
|
||||||
if exists('g:startify_custom_header')
|
if exists('g:startify_custom_header')
|
||||||
if type(g:startify_custom_header) == type([])
|
if type(g:startify_custom_header) == type([])
|
||||||
let g:startify_header = copy(g:startify_custom_header)
|
let g:startify_header = copy(g:startify_custom_header)
|
||||||
else
|
elseif type(g:startify_custom_header) == type('')
|
||||||
let g:startify_header = eval(g:startify_custom_header)
|
let g:startify_header = eval(g:startify_custom_header)
|
||||||
|
else
|
||||||
|
echomsg 'startify: wrong type of value for g:startify_custom_header'
|
||||||
|
let g:startify_header = startify#fortune#cowsay()
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
let g:startify_header = startify#fortune#cowsay()
|
let g:startify_header = startify#fortune#cowsay()
|
||||||
|
|
|
@ -28,8 +28,7 @@ endfunction
|
||||||
" Function: #boxed {{{1
|
" Function: #boxed {{{1
|
||||||
function! startify#fortune#boxed(...) abort
|
function! startify#fortune#boxed(...) abort
|
||||||
let wrapped_quote = []
|
let wrapped_quote = []
|
||||||
let Quote = a:0 && type(a:1) == type([]) ? a:1 : startify#fortune#quote()
|
let quote = a:0 && type(a:1) == type([]) ? a:1 : startify#fortune#quote()
|
||||||
let quote = type(Quote) == type(function('tr')) ? Quote() : Quote
|
|
||||||
for line in quote
|
for line in quote
|
||||||
let wrapped_quote += split(line, '\%50c.\{-}\zs\s', 1)
|
let wrapped_quote += split(line, '\%50c.\{-}\zs\s', 1)
|
||||||
endfor
|
endfor
|
||||||
|
@ -40,14 +39,17 @@ endfunction
|
||||||
" Function: #cowsay {{{1
|
" Function: #cowsay {{{1
|
||||||
function! startify#fortune#cowsay(...) abort
|
function! startify#fortune#cowsay(...) abort
|
||||||
if a:0
|
if a:0
|
||||||
let s:char_top_bottom = get(a:000, 0, s:char_top_bottom)
|
let quote = a:0 && type(a:1) == type([]) ? a:1 : startify#fortune#quote()
|
||||||
let s:char_sides = get(a:000, 1, s:char_sides)
|
let s:char_top_bottom = get(a:000, 1, s:char_top_bottom)
|
||||||
let s:char_top_left = get(a:000, 2, s:char_top_left)
|
let s:char_sides = get(a:000, 2, s:char_sides)
|
||||||
let s:char_top_right = get(a:000, 3, s:char_top_right)
|
let s:char_top_left = get(a:000, 3, s:char_top_left)
|
||||||
let s:char_bottom_right = get(a:000, 4, s:char_bottom_right)
|
let s:char_top_right = get(a:000, 4, s:char_top_right)
|
||||||
let s:char_bottom_left = get(a:000, 5, s:char_bottom_left)
|
let s:char_bottom_right = get(a:000, 5, s:char_bottom_right)
|
||||||
|
let s:char_bottom_left = get(a:000, 6, s:char_bottom_left)
|
||||||
|
else
|
||||||
|
let quote = startify#fortune#quote()
|
||||||
endif
|
endif
|
||||||
let boxed_quote = startify#fortune#boxed()
|
let boxed_quote = startify#fortune#boxed(quote)
|
||||||
let boxed_quote += s:cow
|
let boxed_quote += s:cow
|
||||||
return map(boxed_quote, '" ". v:val')
|
return map(boxed_quote, '" ". v:val')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
|
@ -516,17 +516,23 @@ NOTE: There is no sanitizing going on, so you should know what you're doing!
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*g:startify_custom_header*
|
*g:startify_custom_header*
|
||||||
>
|
>
|
||||||
let g:startify_custom_header = startify#fortune#cowsay()
|
let g:startify_custom_header = 'startify#fortune#cowsay()'
|
||||||
<
|
<
|
||||||
This is a list of strings to be shown before everything else. Every string
|
Define your own header.
|
||||||
will be written on its own line, hence you can use empty strings for blank
|
|
||||||
lines.
|
|
||||||
|
|
||||||
Static example:~
|
This option takes a `list of strings`, whereas each string will be put on its
|
||||||
>
|
own line. If it is a simple `string`, it should evaluate to a list of strings.
|
||||||
let g:startify_custom_header = ['line 1', '', 'line 3']
|
|
||||||
<
|
Helper functions:~
|
||||||
Static example #2:~
|
|
||||||
|
startify#fortune#quote() random quote
|
||||||
|
startify#fortune#boxed(...) random quote in a box
|
||||||
|
startify#fortune#cowsay(...) random quote in a box + cow
|
||||||
|
|
||||||
|
The last two functions optionally take a quote in the list of strings format.
|
||||||
|
They also return a list of strings, suitable for this option.
|
||||||
|
|
||||||
|
Example #1:~
|
||||||
>
|
>
|
||||||
let g:startify_custom_header = [
|
let g:startify_custom_header = [
|
||||||
\ ' ________ __ __ ',
|
\ ' ________ __ __ ',
|
||||||
|
@ -538,21 +544,13 @@ Static example #2:~
|
||||||
\ ' \/__/ \/_/\/_/\/_/\/_/ \// \/_/ \/_/ ',
|
\ ' \/__/ \/_/\/_/\/_/\/_/ \// \/_/ \/_/ ',
|
||||||
\ ]
|
\ ]
|
||||||
<
|
<
|
||||||
Dynamic example:~
|
Example #2:~
|
||||||
>
|
>
|
||||||
let g:startify_custom_header =
|
let g:startify_custom_header =
|
||||||
\ map(split(system('fortune | cowsay'), '\n'), '" ". v:val')
|
\ map(split(system('fortune | cowsay'), '\n'), '" ". v:val')
|
||||||
<
|
<
|
||||||
If you go for a dynamic header, you might find the following functions useful:
|
Example #3:~
|
||||||
|
|
||||||
startify#fortune#quote() raw random quote
|
|
||||||
startify#fortune#boxed(...) opt list or formatted random quote in a box
|
|
||||||
startify#fortune#cowsay() formatted random quote in a box + cow
|
|
||||||
|
|
||||||
Try them like this:
|
|
||||||
>
|
|
||||||
:echo join(startify#fortune#cowsay(), "\n")
|
|
||||||
<
|
|
||||||
Let's assume you like the default boxed random quote, but not the ASCII art
|
Let's assume you like the default boxed random quote, but not the ASCII art
|
||||||
cow. You'd rather have another small ASCII art come before the quote. No
|
cow. You'd rather have another small ASCII art come before the quote. No
|
||||||
problem!
|
problem!
|
||||||
|
|
Loading…
Reference in a new issue