Kaynağa Gözat

New option: g:startify_use_env

References #197.
Marco Hinz 10 yıl önce
ebeveyn
işleme
9e4a159637
2 değiştirilmiş dosya ile 47 ekleme ve 0 silme
  1. 37 0
      autoload/startify.vim
  2. 10 0
      doc/startify.txt

+ 37 - 0
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 $\<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

+ 10 - 0
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*
 >