diff --git a/autoload/startify.vim b/autoload/startify.vim index 126471c..d242fde 100644 --- a/autoload/startify.vim +++ b/autoload/startify.vim @@ -483,6 +483,19 @@ function! s:filter_oldfiles(path_prefix, path_format) abort let oldfiles += [[fnameescape(absolute_path), entry_path]] 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 endfun @@ -779,3 +792,27 @@ function! s:create_last_session_link(spath) endif endif 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 $\')\\\\split('\" + 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 diff --git a/doc/startify.txt b/doc/startify.txt index c6799e0..1126d32 100644 --- a/doc/startify.txt +++ b/doc/startify.txt @@ -107,6 +107,7 @@ default values. |g:startify_files_number| |g:startify_mapping_nowait| |g:startify_skiplist_server| + |g:startify_use_env| Sessions:~ |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 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* >