Skip to content

Commit

Permalink
Fallback to current-directory for URIs
Browse files Browse the repository at this point in the history
closes #127
  • Loading branch information
justinmk committed Nov 15, 2018
1 parent 9c67fa7 commit 3dc59a7
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions autoload/dirvish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ function! s:sl(path) abort
return tr(a:path, '\', '/')
endfunction

function! s:normalize_dir(dir) abort
function! s:normalize_dir(dir, silent) abort
let dir = s:sl(a:dir)
if !isdirectory(dir)
"cygwin/MSYS fallback for paths that lack a drive letter.
" Fallback for cygwin/MSYS paths lacking a drive letter.
let dir = empty($SYSTEMDRIVE) ? dir : '/'.tolower($SYSTEMDRIVE[0]).(dir)
if !isdirectory(dir)
call s:msg_error("invalid directory: '".a:dir."'")
if !a:silent
call s:msg_error("invalid directory: '".a:dir."'")
endif
return ''
endif
endif
Expand All @@ -35,7 +37,7 @@ endfunction

function! s:parent_dir(dir) abort
let mod = isdirectory(s:sl(a:dir)) ? ':p:h:h' : ':p:h'
return s:normalize_dir(fnamemodify(a:dir, mod))
return s:normalize_dir(fnamemodify(a:dir, mod), 0)
endfunction

if v:version > 703
Expand Down Expand Up @@ -235,7 +237,7 @@ function! s:open_selected(splitcmd, bg, line1, line2) abort
for path in paths
let path = s:sl(path)
if !isdirectory(path) && !filereadable(path)
call s:msg_error("invalid (or access denied): ".path)
call s:msg_error("invalid (access denied?): ".path)
continue
endif

Expand Down Expand Up @@ -439,21 +441,24 @@ function! dirvish#open(...) range abort
endif

let d = {}
let is_uri = -1 != match(a:1, '^\w\+:[\/][\/]')
let from_path = fnamemodify(bufname('%'), ':p')
let to_path = fnamemodify(s:sl(a:1), ':p')
" ^resolves to CWD if a:1 is empty

let d._dir = filereadable(to_path) ? fnamemodify(to_path, ':p:h') : to_path
let d._dir = s:normalize_dir(d._dir)
if '' ==# d._dir " s:normalize_dir() already showed error.
let d._dir = s:normalize_dir(d._dir, is_uri)
" Fallback to CWD for URIs. #127
let d._dir = empty(d._dir) && is_uri ? s:normalize_dir(getcwd(), is_uri) : d._dir
if empty(d._dir) " s:normalize_dir() already showed error.
return
endif

let reloading = exists('b:dirvish') && d._dir ==# b:dirvish._dir

if reloading
let d.lastpath = '' " Do not place cursor when reloading.
elseif d._dir ==# s:parent_dir(from_path)
elseif !is_uri && d._dir ==# s:parent_dir(from_path)
let d.lastpath = from_path " Save lastpath when navigating _up_.
endif

Expand Down

0 comments on commit 3dc59a7

Please sign in to comment.