|
| 1 | +" FUNCTIONS IN THIS FILE ARE MEANT TO BE USED BY NETRW.VIM AND NETRW.VIM ONLY. |
| 2 | +" THESE FUNCTIONS DON'T COMMIT TO ANY BACKWARDS COMPATIBILITY. SO CHANGES AND |
| 3 | +" BREAKAGES IF USED OUTSIDE OF NETRW.VIM ARE EXPECTED. |
| 4 | + |
| 5 | +let s:slash = &shellslash ? '/' : '\' |
| 6 | + |
| 7 | +" netrw#fs#PathJoin: Appends a new part to a path taking different systems into consideration {{{ |
| 8 | + |
| 9 | +function! netrw#fs#PathJoin(...) |
| 10 | + let path = "" |
| 11 | + |
| 12 | + for arg in a:000 |
| 13 | + if empty(path) |
| 14 | + let path = arg |
| 15 | + else |
| 16 | + let path .= s:slash . arg |
| 17 | + endif |
| 18 | + endfor |
| 19 | + |
| 20 | + return path |
| 21 | +endfunction |
| 22 | + |
| 23 | +" }}} |
| 24 | +" netrw#fs#ComposePath: Appends a new part to a path taking different systems into consideration {{{ |
| 25 | + |
| 26 | +function! netrw#fs#ComposePath(base, subdir) |
| 27 | + if has('amiga') |
| 28 | + let ec = a:base[s:Strlen(a:base)-1] |
| 29 | + if ec != '/' && ec != ':' |
| 30 | + let ret = a:base . '/' . a:subdir |
| 31 | + else |
| 32 | + let ret = a:base.a:subdir |
| 33 | + endif |
| 34 | + |
| 35 | + " COMBAK: test on windows with changing to root directory: :e C:/ |
| 36 | + elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has('win32') |
| 37 | + let ret = a:subdir |
| 38 | + |
| 39 | + elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has('win32') |
| 40 | + if a:base =~ '[/\\]$' |
| 41 | + let ret = a:base . a:subdir |
| 42 | + else |
| 43 | + let ret = a:base . '/' . a:subdir |
| 44 | + endif |
| 45 | + |
| 46 | + elseif a:base =~ '^\a\{3,}://' |
| 47 | + let urlbase = substitute(a:base, '^\(\a\+://.\{-}/\)\(.*\)$', '\1', '') |
| 48 | + let curpath = substitute(a:base, '^\(\a\+://.\{-}/\)\(.*\)$', '\2', '') |
| 49 | + if a:subdir == '../' |
| 50 | + if curpath =~ '[^/]/[^/]\+/$' |
| 51 | + let curpath = substitute(curpath, '[^/]\+/$', '', '') |
| 52 | + else |
| 53 | + let curpath = '' |
| 54 | + endif |
| 55 | + let ret = urlbase.curpath |
| 56 | + else |
| 57 | + let ret = urlbase.curpath.a:subdir |
| 58 | + endif |
| 59 | + |
| 60 | + else |
| 61 | + let ret = substitute(a:base . '/' .a:subdir, '//', '/', 'g') |
| 62 | + if a:base =~ '^//' |
| 63 | + " keeping initial '//' for the benefit of network share listing support |
| 64 | + let ret = '/' . ret |
| 65 | + endif |
| 66 | + let ret = simplify(ret) |
| 67 | + endif |
| 68 | + |
| 69 | + return ret |
| 70 | +endfunction |
| 71 | + |
| 72 | +" }}} |
| 73 | +" netrw#fs#AbsPath: returns the full path to a directory and/or file {{{ |
| 74 | + |
| 75 | +function! netrw#fs#AbsPath(filename) |
| 76 | + let filename = a:filename |
| 77 | + |
| 78 | + if filename !~ '^/' |
| 79 | + let filename = resolve(getcwd() . '/' . filename) |
| 80 | + endif |
| 81 | + |
| 82 | + if filename != "/" && filename =~ '/$' |
| 83 | + let filename = substitute(filename, '/$', '', '') |
| 84 | + endif |
| 85 | + |
| 86 | + return filename |
| 87 | +endfunction |
| 88 | + |
| 89 | +" }}} |
| 90 | +" netrw#fs#Cwd: get the current directory. {{{ |
| 91 | +" Change backslashes to forward slashes, if any. |
| 92 | +" If doesc is true, escape certain troublesome characters |
| 93 | + |
| 94 | +function! netrw#fs#Cwd(doesc) |
| 95 | + let curdir = substitute(getcwd(), '\\', '/', 'ge') |
| 96 | + |
| 97 | + if curdir !~ '[\/]$' |
| 98 | + let curdir .= '/' |
| 99 | + endif |
| 100 | + |
| 101 | + if a:doesc |
| 102 | + let curdir = fnameescape(curdir) |
| 103 | + endif |
| 104 | + |
| 105 | + return curdir |
| 106 | +endfunction |
| 107 | + |
| 108 | +" }}} |
| 109 | +" netrw#fs#Glob: does glob() if local, remote listing otherwise {{{ |
| 110 | +" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob() |
| 111 | +" expr : this is the expression to follow the directory. Will use netrw#fs#ComposePath() |
| 112 | +" pare =1: remove the current directory from the resulting glob() filelist |
| 113 | +" =0: leave the current directory in the resulting glob() filelist |
| 114 | + |
| 115 | +function! netrw#fs#Glob(direntry, expr, pare) |
| 116 | + if netrw#CheckIfRemote() |
| 117 | + keepalt 1sp |
| 118 | + keepalt enew |
| 119 | + let keep_liststyle = w:netrw_liststyle |
| 120 | + let w:netrw_liststyle = s:THINLIST |
| 121 | + if s:NetrwRemoteListing() == 0 |
| 122 | + keepj keepalt %s@/@@ |
| 123 | + let filelist = getline(1,$) |
| 124 | + q! |
| 125 | + else |
| 126 | + " remote listing error -- leave treedict unchanged |
| 127 | + let filelist = w:netrw_treedict[a:direntry] |
| 128 | + endif |
| 129 | + let w:netrw_liststyle = keep_liststyle |
| 130 | + else |
| 131 | + let path= netrw#fs#ComposePath(fnameescape(a:direntry), a:expr) |
| 132 | + if has("win32") |
| 133 | + " escape [ so it is not detected as wildcard character, see :h wildcard |
| 134 | + let path = substitute(path, '[', '[[]', 'g') |
| 135 | + endif |
| 136 | + let filelist = glob(path, 0, 1, 1) |
| 137 | + if a:pare |
| 138 | + let filelist = map(filelist,'substitute(v:val, "^.*/", "", "")') |
| 139 | + endif |
| 140 | + endif |
| 141 | + |
| 142 | + return filelist |
| 143 | +endfunction |
| 144 | + |
| 145 | +" }}} |
| 146 | +" netrw#fs#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{ |
| 147 | + |
| 148 | +function! netrw#fs#WinPath(path) |
| 149 | + if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32") |
| 150 | + " remove cygdrive prefix, if present |
| 151 | + let path = substitute(a:path, g:netrw_cygdrive . '/\(.\)', '\1:', '') |
| 152 | + " remove trailing slash (Win95) |
| 153 | + let path = substitute(path, '\(\\\|/\)$', '', 'g') |
| 154 | + " remove escaped spaces |
| 155 | + let path = substitute(path, '\ ', ' ', 'g') |
| 156 | + " convert slashes to backslashes |
| 157 | + let path = substitute(path, '/', '\', 'g') |
| 158 | + else |
| 159 | + let path = a:path |
| 160 | + endif |
| 161 | + |
| 162 | + return path |
| 163 | +endfunction |
| 164 | + |
| 165 | +" }}} |
| 166 | + |
| 167 | +" vim:ts=8 sts=4 sw=4 et fdm=marker |
0 commit comments