From de965726eb42050821d15eb67e19560785fc3ec0 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Fri, 12 Feb 2016 18:04:59 +0100 Subject: [PATCH] Env: prefer shortest variable name If several environment variables point to the same directory, prefer the one with the shortest name. References #197. --- autoload/startify.vim | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/autoload/startify.vim b/autoload/startify.vim index d42e662..0d0db1a 100644 --- a/autoload/startify.vim +++ b/autoload/startify.vim @@ -486,7 +486,7 @@ function! s:filter_oldfiles(path_prefix, path_format) abort if get(g:, 'startify_use_env') call s:init_env() for i in range(len(oldfiles)) - for [k,v] in s:env_by_len + for [k,v] in s:env let p = oldfiles[i][1] if !stridx(tolower(p), tolower(v)) let oldfiles[i][1] = printf('$%s%s', k, p[len(v):]) @@ -795,14 +795,17 @@ endfunction " Function: s:init_env {{{1 function! s:init_env() - let env = [] + let s:env = [] let ignore = { 'PWD': 1, 'OLDPWD': 1 } function! s:get_env() silent execute "normal! :return $\')\\\\split('\" endfunction - function! s:compare(foo, bar) + function! s:compare_by_key_len(foo, bar) + return len(a:foo[0]) - len(a:bar[0]) + endfunction + function! s:compare_by_val_len(foo, bar) return len(a:bar[1]) - len(a:foo[1]) endfunction @@ -813,8 +816,9 @@ function! s:init_env() \ || len(k) > len(v) continue endif - call insert(env, [k,v], 0) + call insert(s:env, [k,v], 0) endfor - let s:env_by_len = sort(env, 's:compare') + let s:env = sort(s:env, 's:compare_by_key_len') + let s:env = sort(s:env, 's:compare_by_val_len') endfunction