New option: g:startify_use_env

References #197.
This commit is contained in:
Marco Hinz 2016-02-12 14:21:05 +01:00
parent b3127cb0d4
commit 9e4a159637
2 changed files with 47 additions and 0 deletions

View file

@ -483,6 +483,19 @@ function! s:filter_oldfiles(path_prefix, path_format) abort
let oldfiles += [[fnameescape(absolute_path), entry_path]] let oldfiles += [[fnameescape(absolute_path), entry_path]]
endfor endfor
if get(g:, 'startify_use_env')
call s:init_env()
for i in range(len(oldfiles))
for [k,v] in s:env_by_len
let p = oldfiles[i][1]
if !stridx(p, v)
let oldfiles[i][1] = printf('$%s%s', k, p[len(v):])
break
endif
endfor
endfor
endif
return oldfiles return oldfiles
endfun endfun
@ -779,3 +792,27 @@ function! s:create_last_session_link(spath)
endif endif
endif endif
endfunction endfunction
" Function: s:init_env {{{1
function! s:init_env()
let env = []
let ignore = { 'PWD': 1, 'OLDPWD': 1 }
function! s:get_env()
silent execute "normal! :return $\<c-a>')\<c-b>\<c-right>\<right>\<del>split('\<cr>"
endfunction
function! s:compare(foo, bar)
return len(a:bar[1]) - len(a:foo[1])
endfunction
for k in s:get_env()
let v = eval('$'.k)
if v[0] != '/' || has_key(ignore, k) || len(k) > len(v)
continue
endif
call insert(env, [k,v], 0)
endfor
let s:env_by_len = sort(env, 's:compare')
endfunction

View file

@ -107,6 +107,7 @@ default values.
|g:startify_files_number| |g:startify_files_number|
|g:startify_mapping_nowait| |g:startify_mapping_nowait|
|g:startify_skiplist_server| |g:startify_skiplist_server|
|g:startify_use_env|
Sessions:~ Sessions:~
|g:startify_session_autoload| |g:startify_session_autoload|
@ -471,6 +472,15 @@ Show filenames relative to the current working directory instead of as
absolute paths. This only applies to the "files" list, since the "dir" list is absolute paths. This only applies to the "files" list, since the "dir" list is
relative by nature. relative by nature.
-----------------------------------------------------------------------------
*g:startify_use_env*
>
let g:startify_use_env = 0
<
Show environment variables in path, if their name is shorter than their value.
$PWD and $OLDPWD are ignored.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
*g:startify_mapping_nowait* *g:startify_mapping_nowait*
> >