Skip to content

Commit

Permalink
Use fnamemodify to modify the file path
Browse files Browse the repository at this point in the history
This should ensure that we don't run into any more OS-specific path
issues, and we no longer need to use a regex to substitute the home
directory for Linux users.
  • Loading branch information
Lokaltog committed Apr 30, 2012
1 parent 4652f59 commit a413b26
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions autoload/Powerline/Functions.vim
Expand Up @@ -5,31 +5,33 @@ function! Powerline#Functions#GetFilepath() " {{{
if exists('b:Powerline_filepath')
return b:Powerline_filepath
endif

let dirsep = has('win32') && ! &shellslash ? '\' : '/'
let relpath = expand('%')
let filepath = expand('%')

if empty(relpath)
if empty(filepath)
return ''
endif

let headpath = substitute(expand('%:h'), escape($HOME, '~\'), '~', '')
let fullpath = substitute(expand('%:p:h'), escape($HOME, '~\'), '~', '')
let ret = ''

if g:Powerline_stl_path_style == 'short'
" Display a short path where the first directory is displayed with its
" full name, and the subsequent directories are shortened to their
" first letter, i.e. "/home/user/foo/foo/bar/baz.vim" becomes
" "~/foo/f/b/baz.vim"
let fpath = split(fullpath, dirsep)
"
" This displays the shortest possible path, relative to ~ or the
" current directory.
let fpath = split(fnamemodify(filepath, ':~:.:h'), dirsep)
let fpath_shortparts = map(fpath[1:], 'v:val[0]')
let ret = join(extend([fpath[0]], fpath_shortparts), dirsep) . dirsep
elseif g:Powerline_stl_path_style == 'relative'
" Display a relative path, similar to the %f statusline item
let ret = headpath . dirsep
let ret = fnamemodify(filepath, ':.:h') . dirsep
elseif g:Powerline_stl_path_style == 'full'
" Display the full path, similar to the %F statusline item
let ret = fullpath . dirsep
let ret = filepath . dirsep
endif

if ret == ('.'. dirsep)
Expand Down

0 comments on commit a413b26

Please sign in to comment.