From 0b0c76626bbb6b674018ac63fe050d039131f618 Mon Sep 17 00:00:00 2001 From: Dave Aitken Date: Thu, 7 Jul 2011 02:38:01 -0700 Subject: [PATCH 1/3] Added support for windows network shares (\\box\share format paths) --- plugin/NERD_tree.vim | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index b5d014b..96f048a 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -1880,7 +1880,7 @@ let s:Path = {} function! s:Path.AbsolutePathFor(str) let prependCWD = 0 if s:running_windows - let prependCWD = a:str !~# '^.:\(\\\|\/\)' + let prependCWD = a:str !~# '^.:\(\\\|\/\)' && a:str !~# '^\(\\\\\|\/\/\)' else let prependCWD = a:str !~# '^/' endif @@ -2109,7 +2109,12 @@ endfunction "If running windows, cache the drive letter for this path function! s:Path.extractDriveLetter(fullpath) if s:running_windows - let self.drive = substitute(a:fullpath, '\(^[a-zA-Z]:\).*', '\1', '') + if a:fullpath =~ '^\(\\\\\|\/\/\)' + let self.drive = substitute(a:fullpath, '^\(\(\\\\\|\/\/\)[^\\\/]*\(\\\|\/\)[^\\\/]*\).*', '\1', '') + let self.drive = substitute(self.drive, '/', '\', "g") + else + let self.drive = substitute(a:fullpath, '\(^[a-zA-Z]:\).*', '\1', '') + endif else let self.drive = '' endif @@ -2489,6 +2494,9 @@ function! s:Path.WinToUnixPath(pathstr) "remove the x:\ of the front let toReturn = substitute(toReturn, '^.*:\(\\\|/\)\?', '/', "") + "remove the \\ network share from the front + let toReturn = substitute(toReturn, '^\(\\\\\|\/\/\)[^\\\/]*\(\\\|\/\)[^\\\/]*\(\\\|\/\)\?', '/', "") + "convert all \ chars to / let toReturn = substitute(toReturn, '\', '/', "g") @@ -4114,4 +4122,4 @@ endfunction "reset &cpo back to users setting let &cpo = s:old_cpo -" vim: set sw=4 sts=4 et fdm=marker: +" vim: set sw=4 sts=4 et fdm=marker: \ No newline at end of file From bc745b6e99888c97c7e8f6ff3b7e8f605cab5af1 Mon Sep 17 00:00:00 2001 From: Dave Aitken Date: Thu, 7 Jul 2011 02:51:13 -0700 Subject: [PATCH 2/3] Fixed resolve() double endslash defect --- plugin/NERD_tree.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 96f048a..aae0f18 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -2297,7 +2297,7 @@ function! s:Path.readInfoFromDisk(fullpath) let lastPathComponent = self.getLastPathComponent(0) "get the path to the new node with the parent dir fully resolved - let hardPath = resolve(self.strTrunk()) . '/' . lastPathComponent + let hardPath = resolve(self.strTrunk()) . lastPathComponent "if the last part of the path is a symlink then flag it as such let self.isSymLink = (resolve(hardPath) != hardPath) @@ -2472,9 +2472,13 @@ function! s:Path._str() endfunction "FUNCTION: Path.strTrunk() {{{3 -"Gets the path without the last segment on the end. +"Gets the path without the last segment on the end, always with an endslash function! s:Path.strTrunk() - return self.drive . '/' . join(self.pathSegments[0:-2], '/') + let toReturn = self.drive . '/' . join(self.pathSegments[0:-2], '/') + if toReturn !~# '\/$' + let toReturn .= '/' + endif + return toReturn endfunction "FUNCTION: Path.WinToUnixPath(pathstr){{{3 @@ -4122,4 +4126,4 @@ endfunction "reset &cpo back to users setting let &cpo = s:old_cpo -" vim: set sw=4 sts=4 et fdm=marker: \ No newline at end of file +" vim: set sw=4 sts=4 et fdm=marker: From ba3d43138a867c9116641e8b99d4e10bb72c2ec3 Mon Sep 17 00:00:00 2001 From: Dave Aitken Date: Fri, 6 Jan 2012 19:36:26 +0000 Subject: [PATCH 3/3] Added comment to clarify which part of the path is the 'drive' for windows network shares --- plugin/NERD_tree.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index aae0f18..44abf7f 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -2110,6 +2110,7 @@ endfunction function! s:Path.extractDriveLetter(fullpath) if s:running_windows if a:fullpath =~ '^\(\\\\\|\/\/\)' + "For network shares, the 'drive' consists of the first two parts of the path, i.e. \\boxname\share let self.drive = substitute(a:fullpath, '^\(\(\\\\\|\/\/\)[^\\\/]*\(\\\|\/\)[^\\\/]*\).*', '\1', '') let self.drive = substitute(self.drive, '/', '\', "g") else