Add crypt indicator

If editing an encrypted file, add an indicator, that the file is
encrypted
This commit is contained in:
Christian Brabandt 2015-06-02 20:37:08 +02:00
parent 67de5f2257
commit 9d90e2cbfe
4 changed files with 22 additions and 3 deletions

View File

@ -161,6 +161,10 @@ function! airline#check_mode(winnr)
call add(l:mode, 'paste') call add(l:mode, 'paste')
endif endif
if g:airline_detect_crypt && !empty(&key)
call add(l:mode, 'crypt')
endif
if &readonly || ! &modifiable if &readonly || ! &modifiable
call add(l:mode, 'readonly') call add(l:mode, 'readonly')
endif endif

View File

@ -15,13 +15,13 @@ function! airline#init#bootstrap()
let s:loaded = 1 let s:loaded = 1
let g:airline#init#bootstrapping = 1 let g:airline#init#bootstrapping = 1
call s:check_defined('g:airline_left_sep', get(g:, 'airline_powerline_fonts', 0)?"\ue0b0":">") call s:check_defined('g:airline_left_sep', get(g:, 'airline_powerline_fonts', 0)?"\ue0b0":">")
call s:check_defined('g:airline_left_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"\ue0b1":">") call s:check_defined('g:airline_left_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"\ue0b1":">")
call s:check_defined('g:airline_right_sep', get(g:, 'airline_powerline_fonts', 0)?"\ue0b2":"<") call s:check_defined('g:airline_right_sep', get(g:, 'airline_powerline_fonts', 0)?"\ue0b2":"<")
call s:check_defined('g:airline_right_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"\ue0b3":"<") call s:check_defined('g:airline_right_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"\ue0b3":"<")
call s:check_defined('g:airline_detect_modified', 1) call s:check_defined('g:airline_detect_modified', 1)
call s:check_defined('g:airline_detect_paste', 1) call s:check_defined('g:airline_detect_paste', 1)
call s:check_defined('g:airline_detect_crypt', 1)
call s:check_defined('g:airline_detect_iminsert', 0) call s:check_defined('g:airline_detect_iminsert', 0)
call s:check_defined('g:airline_inactive_collapse', 1) call s:check_defined('g:airline_inactive_collapse', 1)
call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus']) call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus'])
@ -55,6 +55,9 @@ function! airline#init#bootstrap()
\ }, 'keep') \ }, 'keep')
call s:check_defined('g:airline_symbols', {}) call s:check_defined('g:airline_symbols', {})
let s:airline_crypt=''
" generate crypt symbol, "\u" only accepts up to 4 chars
exe 'sil norm!' ":\<C-V>U1F512\<c-\>eextend(s:, {'airline_crypt': getcmdline()}).airline_crypt\n"
call extend(g:airline_symbols, { call extend(g:airline_symbols, {
\ 'paste': get(g:, 'airline_paste_symbol', 'PASTE'), \ 'paste': get(g:, 'airline_paste_symbol', 'PASTE'),
\ 'readonly': get(g:, 'airline_readonly_symbol', get(g:, 'airline_powerline_fonts', 0) ? "\ue0a2" : 'RO'), \ 'readonly': get(g:, 'airline_readonly_symbol', get(g:, 'airline_powerline_fonts', 0) ? "\ue0a2" : 'RO'),
@ -63,7 +66,9 @@ function! airline#init#bootstrap()
\ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? "\ue0a0" : ''), \ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? "\ue0a0" : ''),
\ 'modified': '+', \ 'modified': '+',
\ 'space': ' ', \ 'space': ' ',
\ 'crypt': get(g:, 'airline_crypt_symbol', s:airline_crypt),
\ }, 'keep') \ }, 'keep')
unlet! s:airline_crypt
call airline#parts#define('mode', { call airline#parts#define('mode', {
\ 'function': 'airline#parts#mode', \ 'function': 'airline#parts#mode',
@ -71,6 +76,7 @@ function! airline#init#bootstrap()
\ }) \ })
call airline#parts#define_function('iminsert', 'airline#parts#iminsert') call airline#parts#define_function('iminsert', 'airline#parts#iminsert')
call airline#parts#define_function('paste', 'airline#parts#paste') call airline#parts#define_function('paste', 'airline#parts#paste')
call airline#parts#define_function('crypt', 'airline#parts#crypt')
call airline#parts#define_function('filetype', 'airline#parts#filetype') call airline#parts#define_function('filetype', 'airline#parts#filetype')
call airline#parts#define('readonly', { call airline#parts#define('readonly', {
\ 'function': 'airline#parts#readonly', \ 'function': 'airline#parts#readonly',
@ -88,7 +94,7 @@ endfunction
function! airline#init#sections() function! airline#init#sections()
let spc = g:airline_symbols.space let spc = g:airline_symbols.space
if !exists('g:airline_section_a') if !exists('g:airline_section_a')
let g:airline_section_a = airline#section#create_left(['mode', 'paste', 'capslock', 'iminsert']) let g:airline_section_a = airline#section#create_left(['mode', 'crypt', 'paste', 'capslock', 'iminsert'])
endif endif
if !exists('g:airline_section_b') if !exists('g:airline_section_b')
let g:airline_section_b = airline#section#create(['hunks', 'branch']) let g:airline_section_b = airline#section#create(['hunks', 'branch'])

View File

@ -54,6 +54,10 @@ function! airline#parts#mode()
return get(w:, 'airline_current_mode', '') return get(w:, 'airline_current_mode', '')
endfunction endfunction
function! airline#parts#crypt()
return g:airline_detect_crypt && !empty(&key) ? g:airline_symbols.crypt : ''
endfunction
function! airline#parts#paste() function! airline#parts#paste()
return g:airline_detect_paste && &paste ? g:airline_symbols.paste : '' return g:airline_detect_paste && &paste ? g:airline_symbols.paste : ''
endfunction endfunction

View File

@ -70,6 +70,9 @@ values):
* enable paste detection > * enable paste detection >
let g:airline_detect_paste=1 let g:airline_detect_paste=1
< <
* enable crypt detection >
let g:airline_detect_crypt=1
<
* enable iminsert detection > * enable iminsert detection >
let g:airline_detect_iminsert=0 let g:airline_detect_iminsert=0
< <
@ -176,6 +179,7 @@ its contents. >
let g:airline_left_sep = '▶' let g:airline_left_sep = '▶'
let g:airline_right_sep = '«' let g:airline_right_sep = '«'
let g:airline_right_sep = '◀' let g:airline_right_sep = '◀'
let g:airline_symbols.crypt = '🔒'
let g:airline_symbols.linenr = '␊' let g:airline_symbols.linenr = '␊'
let g:airline_symbols.linenr = '␤' let g:airline_symbols.linenr = '␤'
let g:airline_symbols.linenr = '¶' let g:airline_symbols.linenr = '¶'
@ -214,7 +218,7 @@ section.
> >
variable names default contents variable names default contents
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
let g:airline_section_a (mode, paste, iminsert) let g:airline_section_a (mode, crypt, paste, iminsert)
let g:airline_section_b (hunks, branch) let g:airline_section_b (hunks, branch)
let g:airline_section_c (bufferline or filename) let g:airline_section_c (bufferline or filename)
let g:airline_section_gutter (readonly, csv) let g:airline_section_gutter (readonly, csv)
@ -639,6 +643,7 @@ Before is a list of parts that are predefined by vim-airline.
* `mode` displays the current mode * `mode` displays the current mode
* `iminsert` displays the current insert method * `iminsert` displays the current insert method
* `paste` displays the paste indicator * `paste` displays the paste indicator
* crypt displays the crypted indicator
* `filetype` displays the file type * `filetype` displays the file type
* `readonly` displays the read only indicator * `readonly` displays the read only indicator
* `file` displays the filename and modified indicator * `file` displays the filename and modified indicator