Merge pull request #734 from lifecrisis/issue733
BUGFIX: Make the NERDTree aware of the 'shellslash' setting.
This commit is contained in:
commit
5782b228e4
@ -1,9 +1,16 @@
|
|||||||
"we need to use this number many times for sorting... so we calculate it only
|
" ============================================================================
|
||||||
"once here
|
|
||||||
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
|
|
||||||
|
|
||||||
" CLASS: Path
|
" CLASS: Path
|
||||||
"============================================================
|
"
|
||||||
|
" The Path class provides an abstracted representation of a file system
|
||||||
|
" pathname. Various operations on pathnames are provided and a number of
|
||||||
|
" representations of a given path name can be accessed here.
|
||||||
|
" ============================================================================
|
||||||
|
|
||||||
|
|
||||||
|
" This constant is used throughout this script for sorting purposes.
|
||||||
|
let s:NERDTreeSortStarIndex = index(g:NERDTreeSortOrder, '*')
|
||||||
|
lockvar s:NERDTreeSortStarIndex
|
||||||
|
|
||||||
let s:Path = {}
|
let s:Path = {}
|
||||||
let g:NERDTreePath = s:Path
|
let g:NERDTreePath = s:Path
|
||||||
|
|
||||||
@ -529,9 +536,20 @@ function! s:Path.New(path)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: Path.Slash() {{{1
|
" FUNCTION: Path.Slash() {{{1
|
||||||
"return the slash to use for the current OS
|
" Return the path separator used by the underlying file system. Special
|
||||||
|
" consideration is taken for the use of the 'shellslash' option on Windows
|
||||||
|
" systems.
|
||||||
function! s:Path.Slash()
|
function! s:Path.Slash()
|
||||||
return nerdtree#runningWindows() ? '\' : '/'
|
|
||||||
|
if nerdtree#runningWindows()
|
||||||
|
if exists('+shellslash') && &shellslash
|
||||||
|
return '/'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return '\'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return '/'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: Path.Resolve() {{{1
|
" FUNCTION: Path.Resolve() {{{1
|
||||||
@ -633,27 +651,27 @@ function! s:Path.rename(newPath)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: Path.str() {{{1
|
" FUNCTION: Path.str() {{{1
|
||||||
|
" Return a string representation of this Path object.
|
||||||
"
|
"
|
||||||
"Returns a string representation of this Path
|
" Args:
|
||||||
|
" This function takes a single dictionary (optional) with keys and values that
|
||||||
|
" specify how the returned pathname should be formatted.
|
||||||
"
|
"
|
||||||
"Takes an optional dictionary param to specify how the output should be
|
" The dictionary may have the following keys:
|
||||||
"formatted.
|
|
||||||
"
|
|
||||||
"The dict may have the following keys:
|
|
||||||
" 'format'
|
" 'format'
|
||||||
" 'escape'
|
" 'escape'
|
||||||
" 'truncateTo'
|
" 'truncateTo'
|
||||||
"
|
"
|
||||||
" The 'format' key may have a value of:
|
" The 'format' key may have a value of:
|
||||||
" 'Cd' - a string to be used with the :cd command
|
" 'Cd' - a string to be used with ":cd" and similar commands
|
||||||
" 'Edit' - a string to be used with :e :sp :new :tabedit etc
|
" 'Edit' - a string to be used with ":edit" and similar commands
|
||||||
" 'UI' - a string used in the NERD tree UI
|
" 'UI' - a string to be displayed in the NERDTree user interface
|
||||||
"
|
"
|
||||||
"The 'escape' key, if specified will cause the output to be escaped with
|
" The 'escape' key, if specified, will cause the output to be escaped with
|
||||||
"shellescape()
|
" Vim's internal "shellescape()" function.
|
||||||
"
|
"
|
||||||
"The 'truncateTo' key causes the resulting string to be truncated to the value
|
" The 'truncateTo' key shortens the length of the path to that given by the
|
||||||
"'truncateTo' maps to. A '<' char will be prepended.
|
" value associated with 'truncateTo'. A '<' is prepended.
|
||||||
function! s:Path.str(...)
|
function! s:Path.str(...)
|
||||||
let options = a:0 ? a:1 : {}
|
let options = a:0 ? a:1 : {}
|
||||||
let toReturn = ""
|
let toReturn = ""
|
||||||
@ -698,33 +716,33 @@ function! s:Path._strForUI()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: Path._strForCd() {{{1
|
" FUNCTION: Path._strForCd() {{{1
|
||||||
"
|
" Return a string representation of this Path that is suitable for use as an
|
||||||
" returns a string that can be used with :cd
|
" argument to Vim's internal ":cd" command.
|
||||||
function! s:Path._strForCd()
|
function! s:Path._strForCd()
|
||||||
return escape(self.str(), self._escChars())
|
return fnameescape(self.str())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: Path._strForEdit() {{{1
|
" FUNCTION: Path._strForEdit() {{{1
|
||||||
"
|
" Return a string representation of this Path that is suitable for use as an
|
||||||
"Return: the string for this path that is suitable to be used with the :edit
|
" argument to Vim's internal ":edit" command.
|
||||||
"command
|
|
||||||
function! s:Path._strForEdit()
|
function! s:Path._strForEdit()
|
||||||
let p = escape(self.str(), self._escChars())
|
|
||||||
|
|
||||||
"make it relative
|
" Make the path relative to the current working directory, if possible.
|
||||||
let p = fnamemodify(p, ':.')
|
let l:result = fnamemodify(self.str(), ':.')
|
||||||
|
|
||||||
"handle the edge case where the file begins with a + (vim interprets
|
" On Windows, the drive letter may be removed by "fnamemodify()". Add it
|
||||||
"the +foo in `:e +foo` as an option to :edit)
|
" back, if necessary.
|
||||||
if p[0] == "+"
|
if nerdtree#runningWindows() && l:result[0] == s:Path.Slash()
|
||||||
let p = '\' . p
|
let l:result = self.drive . l:result
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if p ==# ''
|
let l:result = fnameescape(l:result)
|
||||||
let p = '.'
|
|
||||||
|
if empty(l:result)
|
||||||
|
let l:result = '.'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return p
|
return l:result
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: Path._strForGlob() {{{1
|
" FUNCTION: Path._strForGlob() {{{1
|
||||||
@ -745,19 +763,17 @@ function! s:Path._strForGlob()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: Path._str() {{{1
|
" FUNCTION: Path._str() {{{1
|
||||||
"
|
" Return the absolute pathname associated with this Path object. The pathname
|
||||||
"Gets the string path for this path object that is appropriate for the OS.
|
" returned is appropriate for the underlying file system.
|
||||||
"EG, in windows c:\foo\bar
|
|
||||||
" in *nix /foo/bar
|
|
||||||
function! s:Path._str()
|
function! s:Path._str()
|
||||||
let lead = s:Path.Slash()
|
let l:separator = s:Path.Slash()
|
||||||
|
let l:leader = l:separator
|
||||||
|
|
||||||
"if we are running windows then slap a drive letter on the front
|
|
||||||
if nerdtree#runningWindows()
|
if nerdtree#runningWindows()
|
||||||
let lead = self.drive . '\'
|
let l:leader = self.drive . l:separator
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return lead . join(self.pathSegments, s:Path.Slash())
|
return l:leader . join(self.pathSegments, l:separator)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: Path.strTrunk() {{{1
|
" FUNCTION: Path.strTrunk() {{{1
|
||||||
|
@ -243,7 +243,7 @@ function! s:TreeDirNode._glob(pattern, all)
|
|||||||
let l:pathSpec = fnamemodify(self.path.str({'format': 'Glob'}), ':.')
|
let l:pathSpec = fnamemodify(self.path.str({'format': 'Glob'}), ':.')
|
||||||
|
|
||||||
" On Windows, the drive letter may be removed by "fnamemodify()".
|
" On Windows, the drive letter may be removed by "fnamemodify()".
|
||||||
if nerdtree#runningWindows() && l:pathSpec[0] == '\'
|
if nerdtree#runningWindows() && l:pathSpec[0] == g:NERDTreePath.Slash()
|
||||||
let l:pathSpec = self.path.drive . l:pathSpec
|
let l:pathSpec = self.path.drive . l:pathSpec
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
@ -212,14 +212,40 @@ endfunction
|
|||||||
|
|
||||||
" FUNCTION: NERDTreeListNodeWin32() {{{1
|
" FUNCTION: NERDTreeListNodeWin32() {{{1
|
||||||
function! NERDTreeListNodeWin32()
|
function! NERDTreeListNodeWin32()
|
||||||
let treenode = g:NERDTreeFileNode.GetSelected()
|
let l:node = g:NERDTreeFileNode.GetSelected()
|
||||||
if treenode != {}
|
|
||||||
let metadata = split(system('DIR /Q ' . shellescape(treenode.path.str()) . ' | FINDSTR "^[012][0-9]/[0-3][0-9]/[12][0-9][0-9][0-9]"'), '\n')
|
if !empty(l:node)
|
||||||
call nerdtree#echo(metadata[0])
|
|
||||||
else
|
let l:save_shell = &shell
|
||||||
call nerdtree#echo("No information avaialable")
|
set shell&
|
||||||
|
|
||||||
|
if exists('+shellslash')
|
||||||
|
let l:save_shellslash = &shellslash
|
||||||
|
set noshellslash
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let l:command = 'DIR /Q '
|
||||||
|
\ . shellescape(l:node.path.str())
|
||||||
|
\ . ' | FINDSTR "^[012][0-9]/[0-3][0-9]/[12][0-9][0-9][0-9]"'
|
||||||
|
|
||||||
|
let l:metadata = split(system(l:command), "\n")
|
||||||
|
|
||||||
|
if v:shell_error == 0
|
||||||
|
call nerdtree#echo(l:metadata[0])
|
||||||
|
else
|
||||||
|
call nerdtree#echoError('shell command failed')
|
||||||
|
endif
|
||||||
|
|
||||||
|
let &shell = l:save_shell
|
||||||
|
|
||||||
|
if exists('l:save_shellslash')
|
||||||
|
let &shellslash = l:save_shellslash
|
||||||
|
endif
|
||||||
|
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
call nerdtree#echo('node not recognized')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" FUNCTION: NERDTreeCopyNode() {{{1
|
" FUNCTION: NERDTreeCopyNode() {{{1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user