Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1 | " netrw.vim: Handles file transfer and remote directory listing across a network |
| 2 | " Last Change: Jun 24, 2004 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3 | " Maintainer: Charles E. Campbell, Jr. PhD <drchipNOSPAM at campbellfamily.biz> |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 4 | " Version: 47c NOT RELEASED |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5 | " License: Vim License (see vim's :help license) |
| 6 | " |
| 7 | " But be doers of the word, and not only hearers, deluding your own selves |
| 8 | " (James 1:22 RSV) |
| 9 | " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
| 10 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 11 | " Exit quickly when already loaded or when 'compatible' is set. {{{1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 12 | if exists("loaded_netrw") || &cp |
| 13 | finish |
| 14 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 15 | let loaded_netrw = "v47c" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 16 | let s:save_cpo = &cpo |
| 17 | set cpo&vim |
| 18 | |
| 19 | " --------------------------------------------------------------------- |
| 20 | " Default values for global netrw variables {{{1 |
| 21 | if !exists("g:netrw_ftpmode") |
| 22 | let g:netrw_ftpmode= "binary" |
| 23 | endif |
| 24 | if !exists("g:netrw_win95ftp") |
| 25 | let g:netrw_win95ftp= 1 |
| 26 | endif |
| 27 | if !exists("g:netrw_cygwin") |
| 28 | if has("win32") |
| 29 | let g:netrw_cygwin= 1 |
| 30 | else |
| 31 | let g:netrw_cygwin= 0 |
| 32 | endif |
| 33 | endif |
| 34 | |
| 35 | " --------------------------------------------------------------------- |
| 36 | " Default values for global protocol variables {{{1 |
| 37 | if !exists("g:netrw_rcp_cmd") |
| 38 | let g:netrw_rcp_cmd = "rcp" |
| 39 | endif |
| 40 | if !exists("g:netrw_ftp_cmd") |
| 41 | let g:netrw_ftp_cmd = "ftp" |
| 42 | endif |
| 43 | if !exists("g:netrw_scp_cmd") |
| 44 | let g:netrw_scp_cmd = "scp -q" |
| 45 | endif |
| 46 | if !exists("g:netrw_sftp_cmd") |
| 47 | let g:netrw_sftp_cmd = "sftp" |
| 48 | endif |
| 49 | if !exists("g:netrw_http_cmd") |
| 50 | if executable("wget") |
| 51 | let g:netrw_http_cmd = "wget -q -O" |
| 52 | elseif executable("fetch") |
| 53 | let g:netrw_http_cmd = "fetch -o" |
| 54 | else |
| 55 | let g:netrw_http_cmd = "" |
| 56 | endif |
| 57 | endif |
| 58 | if !exists("g:netrw_dav_cmd") |
| 59 | let g:netrw_dav_cmd = "cadaver" |
| 60 | endif |
| 61 | if !exists("g:netrw_rsync_cmd") |
| 62 | let g:netrw_rsync_cmd = "rsync" |
| 63 | endif |
| 64 | if !exists("g:netrw_fetch_cmd") |
| 65 | if executable("fetch") |
| 66 | let g:netrw_fetch_cmd = "fetch -o" |
| 67 | else |
| 68 | let g:netrw_fetch_cmd = "" |
| 69 | endif |
| 70 | endif |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 71 | if !exists("g:netrw_list_cmd") |
| 72 | if executable("ssh") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 73 | let g:netrw_list_cmd= "ssh HOSTNAME ls -FLa" |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 74 | else |
| 75 | " call Decho("ssh is not executable, can't do netlist") |
| 76 | let g:netrw_list_cmd= "" |
| 77 | endif |
| 78 | endif |
| 79 | if exists("g:netrw_silent") && g:netrw_silent != 0 |
| 80 | let g:netrw_silentxfer= "silent " |
| 81 | else |
| 82 | let g:netrw_silentxfer= "" |
| 83 | endif |
| 84 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 85 | |
| 86 | if has("win32") |
| 87 | \ && exists("g:netrw_use_nt_rcp") |
| 88 | \ && g:netrw_use_nt_rcp |
| 89 | \ && executable( $SystemRoot .'/system32/rcp.exe') |
| 90 | let s:netrw_has_nt_rcp = 1 |
| 91 | let s:netrw_rcpmode = '-b' |
| 92 | else |
| 93 | let s:netrw_has_nt_rcp = 0 |
| 94 | let s:netrw_rcpmode = '' |
| 95 | endif |
| 96 | |
| 97 | " --------------------------------------------------------------------- |
| 98 | " Transparency Support: {{{1 |
| 99 | " Auto-detection for ftp://*, rcp://*, scp://*, sftp://*, http://*, dav://*, |
| 100 | " and rsync://* |
| 101 | " Should make file transfers across networks transparent. Currently I haven't |
| 102 | " supported appends. Hey, gotta leave something for a future <netrw.vim>! |
| 103 | if version >= 600 |
| 104 | augroup Network |
| 105 | au! |
| 106 | if has("win32") |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 107 | au BufReadCmd file://* exe "silent doau BufReadPre ".expand("<afile>")|exe 'e '.substitute(expand("<afile>"),"file:/*","","")|exe "silent doau BufReadPost ".expand("<afile>") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | else |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 109 | au BufReadCmd file:///* exe "silent doau BufReadPre ".expand("<afile>")|exe 'e /'.substitute(expand("<afile>"),"file:/*","","")|exe "silent doau BufReadPost ".expand("<afile>") |
| 110 | au BufReadCmd file://localhost/* exe "silent doau BufReadPre ".expand("<afile>")|exe 'e /'.substitute(expand("<afile>"),"file:/*","","")|exe "silent doau BufReadPost ".expand("<afile>") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 111 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 112 | au BufReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("<afile>")|exe "Nread 0r ".expand("<afile>")|exe "silent doau BufReadPost ".expand("<afile>") |
| 113 | au FileReadCmd ftp://*,rcp://*,scp://*,http://*,dav://*,rsync://*,sftp://* exe "silent doau BufReadPre ".expand("<afile>")|exe "Nread " .expand("<afile>")|exe "silent doau BufReadPost ".expand("<afile>") |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 114 | au BufWriteCmd ftp://*,rcp://*,scp://*,dav://*,rsync://*,sftp://* exe "Nwrite " .expand("<afile>")|call <SID>NetRestorePosn() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 115 | augroup END |
| 116 | endif |
| 117 | |
| 118 | " ------------------------------------------------------------------------ |
| 119 | " Commands: :Nread, :Nwrite, and :NetUserPass {{{1 |
| 120 | com! -nargs=* Nread call <SID>NetSavePosn()<bar>call <SID>NetRead(<f-args>)<bar>call <SID>NetRestorePosn() |
| 121 | com! -range=% -nargs=* Nwrite call <SID>NetSavePosn()<bar><line1>,<line2>call <SID>NetWrite(<f-args>)<bar>call <SID>NetRestorePosn() |
| 122 | com! -nargs=* NetUserPass call NetUserPass(<f-args>) |
| 123 | |
| 124 | " ------------------------------------------------------------------------ |
| 125 | " NetSavePosn: saves position of cursor on screen {{{1 |
| 126 | fun! s:NetSavePosn() |
| 127 | " call Dfunc("NetSavePosn()") |
| 128 | " Save current line and column |
| 129 | let s:netrw_winnr= winnr() |
| 130 | let s:netrw_line = line(".") |
| 131 | let s:netrw_col = virtcol(".") |
| 132 | |
| 133 | " Save top-of-screen line |
| 134 | norm! H0 |
| 135 | let s:netrw_hline= line(".") |
| 136 | |
| 137 | call s:NetRestorePosn() |
| 138 | " call Dret("NetSavePosn : winnr=".s:netrw_winnr." line=".s:netrw_line." col=".s:netrw_col." hline=".s:netrw_hline) |
| 139 | endfun |
| 140 | |
| 141 | " ------------------------------------------------------------------------ |
| 142 | " NetRestorePosn: restores the cursor and file position as saved by NetSavePosn() {{{1 |
| 143 | fun! <SID>NetRestorePosn() |
| 144 | " call Dfunc("NetRestorePosn() winnr=".s:netrw_winnr." line=".s:netrw_line." col=".s:netrw_col." hline=".s:netrw_hline) |
| 145 | |
| 146 | exe "silent! ".s:netrw_winnr."wincmd w" |
| 147 | if v:shell_error == 0 |
| 148 | " as suggested by Bram M: redraw on no error |
| 149 | " allows protocol error messages to remain visible |
| 150 | redraw! |
| 151 | endif |
| 152 | " restore top-of-screen line |
| 153 | exe "norm! ".s:netrw_hline."G0z\<CR>" |
| 154 | " restore position |
| 155 | exe "norm! ".s:netrw_line."G0".s:netrw_col."\<bar>" |
| 156 | |
| 157 | " call Dret("NetRestorePosn") |
| 158 | endfun |
| 159 | |
| 160 | " ------------------------------------------------------------------------ |
| 161 | " NetRead: responsible for reading a file over the net {{{1 |
| 162 | fun! s:NetRead(...) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 163 | " call Dfunc("NetRead(a:1<".a:1.">)") |
| 164 | |
| 165 | " save options |
| 166 | call s:NetOptionSave() |
| 167 | |
| 168 | " Special Exception: if a file is named "0r", then |
| 169 | " "0r" will be used to read the |
| 170 | " following files instead of "r" |
| 171 | if a:0 == 0 |
| 172 | let readcmd= "r" |
| 173 | let ichoice= 0 |
| 174 | elseif a:1 == "0r" |
| 175 | let readcmd = "0r" |
| 176 | let ichoice = 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 177 | else |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 178 | let readcmd = "r" |
| 179 | let ichoice = 1 |
| 180 | endif |
| 181 | |
| 182 | " get name of a temporary file |
| 183 | let tmpfile= tempname() |
| 184 | |
| 185 | " call Decho("ichoice=".ichoice." readcmd<".readcmd.">") |
| 186 | while ichoice <= a:0 |
| 187 | |
| 188 | " attempt to repeat with previous host-file-etc |
| 189 | if exists("b:netrw_lastfile") && a:0 == 0 |
| 190 | " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">") |
| 191 | let choice = b:netrw_lastfile |
| 192 | let ichoice= ichoice + 1 |
| 193 | |
| 194 | else |
| 195 | exe "let choice= a:" . ichoice |
| 196 | " call Decho("no lastfile: choice<" . choice . ">") |
| 197 | |
| 198 | " Reconstruct Choice if choice starts with '"' |
| 199 | if match(choice,"?") == 0 |
| 200 | echo 'NetRead Usage:' |
| 201 | echo ':Nread machine:path uses rcp' |
| 202 | echo ':Nread "machine path" uses ftp with <.netrc>' |
| 203 | echo ':Nread "machine id password path" uses ftp' |
| 204 | echo ':Nread dav://machine[:port]/path uses cadaver' |
| 205 | echo ':Nread fetch://machine/path uses fetch' |
| 206 | echo ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>' |
| 207 | echo ':Nread http://[user@]machine/path uses http wget' |
| 208 | echo ':Nread rcp://[user@]machine/path uses rcp' |
| 209 | echo ':Nread rsync://machine[:port]/path uses rsync' |
| 210 | echo ':Nread scp://[user@]machine[[:#]port]/path uses scp' |
| 211 | echo ':Nread sftp://[user@]machine[[:#]port]/path uses sftp' |
| 212 | break |
| 213 | elseif match(choice,"^\"") != -1 |
| 214 | " call Decho("reconstructing choice") |
| 215 | if match(choice,"\"$") != -1 |
| 216 | " case "..." |
| 217 | let choice=strpart(choice,1,strlen(choice)-2) |
| 218 | else |
| 219 | " case "... ... ..." |
| 220 | let choice = strpart(choice,1,strlen(choice)-1) |
| 221 | let wholechoice = "" |
| 222 | |
| 223 | while match(choice,"\"$") == -1 |
| 224 | let wholechoice = wholechoice . " " . choice |
| 225 | let ichoice = ichoice + 1 |
| 226 | if ichoice > a:0 |
| 227 | echoerr "Unbalanced string in filename '". wholechoice ."'" |
| 228 | " call Dret("NetRead") |
| 229 | return |
| 230 | endif |
| 231 | let choice= a:{ichoice} |
| 232 | endwhile |
| 233 | let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1) |
| 234 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 235 | endif |
| 236 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 237 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 238 | " call Decho("choice<" . choice . ">") |
| 239 | let ichoice= ichoice + 1 |
| 240 | |
| 241 | " fix up windows urls |
| 242 | if has("win32") |
| 243 | let choice = substitute(choice,'\\','/','ge') |
| 244 | " call Decho("fixing up windows url to <".choice."> tmpfile<".tmpfile) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 245 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 246 | exe 'lcd ' . fnamemodify(tmpfile,':h') |
| 247 | let tmpfile = fnamemodify(tmpfile,':t') |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 248 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 249 | |
| 250 | " Determine method of read (ftp, rcp, etc) |
| 251 | call s:NetMethod(choice) |
| 252 | |
| 253 | " Check if NetList() should be handling this request |
| 254 | " call Decho("checking if netlist: choice<".choice."> netrw_list_cmd<".g:netrw_list_cmd.">") |
| 255 | if choice =~ "^.*/$" |
| 256 | if strlen(g:netrw_list_cmd) > 0 |
| 257 | keepjumps call s:NetList(choice) |
| 258 | " call Dret("NetRead") |
| 259 | else |
| 260 | echoerr "sorry, can't do a remote listing; ssh isn't executable" |
| 261 | endif |
| 262 | return |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 263 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 264 | |
| 265 | " ============ |
| 266 | " Perform Read |
| 267 | " ============ |
| 268 | |
| 269 | "......................................... |
| 270 | " rcp: NetRead Method #1 |
| 271 | if b:netrw_method == 1 " read with rcp |
| 272 | " call Decho("read via rcp (method #1)") |
| 273 | " ER: noting done with g:netrw_uid yet? |
| 274 | " ER: on Win2K" rcp machine[.user]:file tmpfile |
| 275 | " ER: if machine contains '.' adding .user is required (use $USERNAME) |
| 276 | " ER: the tmpfile is full path: rcp sees C:\... as host C |
| 277 | if s:netrw_has_nt_rcp == 1 |
| 278 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 279 | let uid_machine = g:netrw_machine .'.'. g:netrw_uid |
| 280 | else |
| 281 | " Any way needed it machine contains a '.' |
| 282 | let uid_machine = g:netrw_machine .'.'. $USERNAME |
| 283 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 284 | else |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 285 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 286 | let uid_machine = g:netrw_uid .'@'. g:netrw_machine |
| 287 | else |
| 288 | let uid_machine = g:netrw_machine |
| 289 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 290 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 291 | " call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile) |
| 292 | exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".uid_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile |
| 293 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 294 | let b:netrw_lastfile = choice |
| 295 | |
| 296 | "......................................... |
| 297 | " ftp + <.netrc>: NetRead Method #2 |
| 298 | elseif b:netrw_method == 2 " read with ftp + <.netrc> |
| 299 | " call Decho("read via ftp+.netrc (method #2)") |
| 300 | let netrw_fname= b:netrw_fname |
| 301 | new |
| 302 | set ff=unix |
| 303 | exe "put ='".g:netrw_ftpmode."'" |
| 304 | exe "put ='get ".netrw_fname." ".tmpfile."'" |
| 305 | if exists("g:netrw_port") && g:netrw_port != "" |
| 306 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port) |
| 307 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port |
| 308 | else |
| 309 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine) |
| 310 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine |
| 311 | endif |
| 312 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 313 | if getline(1) !~ "^$" |
| 314 | echoerr getline(1) |
| 315 | endif |
| 316 | bd! |
| 317 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 318 | let b:netrw_lastfile = choice |
| 319 | |
| 320 | "......................................... |
| 321 | " ftp + machine,id,passwd,filename: NetRead Method #3 |
| 322 | elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname |
| 323 | " Construct execution string (four lines) which will be passed through filter |
| 324 | " call Decho("read via ftp+mipf (method #3)") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 325 | let netrw_fname= b:netrw_fname |
| 326 | new |
| 327 | set ff=unix |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 328 | if exists("g:netrw_port") && g:netrw_port != "" |
| 329 | put ='open '.g:netrw_machine.' '.g:netrw_port |
| 330 | else |
| 331 | put ='open '.g:netrw_machine |
| 332 | endif |
| 333 | |
| 334 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
| 335 | put =g:netrw_uid |
| 336 | put =g:netrw_passwd |
| 337 | else |
| 338 | put ='user '.g:netrw_uid.' '.g:netrw_passwd |
| 339 | endif |
| 340 | |
| 341 | if exists("g:netrw_ftpmode") && g:netrw_ftpmode != "" |
| 342 | put =g:netrw_ftpmode |
| 343 | endif |
| 344 | put ='get '.netrw_fname.' '.tmpfile |
| 345 | |
| 346 | " perform ftp: |
| 347 | " -i : turns off interactive prompting from ftp |
| 348 | " -n unix : DON'T use <.netrc>, even though it exists |
| 349 | " -n win32: quit being obnoxious about password |
| 350 | " call Decho('performing ftp -i -n') |
| 351 | norm 1Gdd |
| 352 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i -n") |
| 353 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n" |
| 354 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 355 | if getline(1) !~ "^$" |
| 356 | echoerr getline(1) |
| 357 | endif |
| 358 | bd! |
| 359 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 360 | let b:netrw_lastfile = choice |
| 361 | |
| 362 | "......................................... |
| 363 | " scp: NetRead Method #4 |
| 364 | elseif b:netrw_method == 4 " read with scp |
| 365 | " call Decho("read via scp (method #4)") |
| 366 | if exists("g:netrw_port") && g:netrw_port != "" |
| 367 | let useport= " -P ".g:netrw_port |
| 368 | else |
| 369 | let useport= "" |
| 370 | endif |
| 371 | if g:netrw_cygwin == 1 |
| 372 | let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e') |
| 373 | " call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile) |
| 374 | exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile |
| 375 | else |
| 376 | " call Decho("executing: !".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile) |
| 377 | exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile |
| 378 | endif |
| 379 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 380 | let b:netrw_lastfile = choice |
| 381 | |
| 382 | "......................................... |
| 383 | elseif b:netrw_method == 5 " read with http (wget) |
| 384 | " call Decho("read via http (method #5)") |
| 385 | if g:netrw_http_cmd == "" |
| 386 | echoerr "neither wget nor fetch command is available" |
| 387 | exit |
| 388 | endif |
| 389 | |
| 390 | if match(b:netrw_fname,"#") == -1 |
| 391 | " simple wget |
| 392 | " call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.escape(b:netrw_fname,' ?&')) |
| 393 | exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.escape(b:netrw_fname,' ?&') |
| 394 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 395 | |
| 396 | else |
| 397 | " wget plus a jump to an in-page marker (ie. http://abc/def.html#aMarker) |
| 398 | let netrw_html= substitute(b:netrw_fname,"#.*$","","") |
| 399 | let netrw_tag = substitute(b:netrw_fname,"^.*#","","") |
| 400 | " call Decho("netrw_html<".netrw_html.">") |
| 401 | " call Decho("netrw_tag <".netrw_tag.">") |
| 402 | " call Decho("executing: !".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html) |
| 403 | exe g:netrw_silentxfer."!".g:netrw_http_cmd." ".tmpfile." http://".g:netrw_machine.netrw_html |
| 404 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 405 | " call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/') |
| 406 | exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>" |
| 407 | endif |
| 408 | let b:netrw_lastfile = choice |
| 409 | |
| 410 | "......................................... |
| 411 | " cadaver: NetRead Method #6 |
| 412 | elseif b:netrw_method == 6 " read with cadaver |
| 413 | " call Decho("read via cadaver (method #6)") |
| 414 | |
| 415 | " Construct execution string (four lines) which will be passed through filter |
| 416 | let netrw_fname= b:netrw_fname |
| 417 | new |
| 418 | set ff=unix |
| 419 | if exists("g:netrw_port") && g:netrw_port != "" |
| 420 | put ='open '.g:netrw_machine.' '.g:netrw_port |
| 421 | else |
| 422 | put ='open '.g:netrw_machine |
| 423 | endif |
| 424 | put ='user '.g:netrw_uid.' '.g:netrw_passwd |
| 425 | |
| 426 | if g:netrw_cygwin == 1 |
| 427 | let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e') |
| 428 | put ='get '.netrw_fname.' '.cygtmpfile |
| 429 | else |
| 430 | put ='get '.netrw_fname.' '.tmpfile |
| 431 | endif |
| 432 | |
| 433 | " perform cadaver operation: |
| 434 | norm 1Gdd |
| 435 | " call Decho("executing: %!".g:netrw_dav_cmd) |
| 436 | exe g:netrw_silentxfer."%!".g:netrw_dav_cmd |
| 437 | bd! |
| 438 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 439 | let b:netrw_lastfile = choice |
| 440 | |
| 441 | "......................................... |
| 442 | " rsync: NetRead Method #7 |
| 443 | elseif b:netrw_method == 7 " read with rsync |
| 444 | " call Decho("read via rsync (method #7)") |
| 445 | if g:netrw_cygwin == 1 |
| 446 | let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e') |
| 447 | " call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile) |
| 448 | exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile |
| 449 | else |
| 450 | " call Decho("executing: !".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile) |
| 451 | exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile |
| 452 | endif |
| 453 | let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method) |
| 454 | let b:netrw_lastfile = choice |
| 455 | |
| 456 | "......................................... |
| 457 | " fetch: NetRead Method #8 |
| 458 | " fetch://[user@]host[:http]/path |
| 459 | elseif b:netrw_method == 8 " read with fetch |
| 460 | if g:netrw_fetch_cmd == "" |
| 461 | echoerr "fetch command not available" |
| 462 | exit |
| 463 | endif |
| 464 | if exists("g:netrw_option") && g:netrw_option == ":http" |
| 465 | let netrw_option= "http" |
| 466 | else |
| 467 | let netrw_option= "ftp" |
| 468 | endif |
| 469 | " call Decho("read via fetch for ".netrw_option) |
| 470 | |
| 471 | if exists("g:netrw_uid") && g:netrw_uid != "" && exists("g:netrw_passwd") && g:netrw_passwd != "" |
| 472 | " call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".escape(b:netrw_fname,' ?&')) |
| 473 | exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_uid.':'.g:netrw_passwd.'@'.g:netrw_machine."/".escape(b:netrw_fname,' ?&') |
| 474 | else |
| 475 | " call Decho("executing: !".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".escape(b:netrw_fname,' ?&')) |
| 476 | exe g:netrw_silentxfer."!".g:netrw_fetch_cmd." ".tmpfile." ".netrw_option."://".g:netrw_machine."/".escape(b:netrw_fname,' ?&') |
| 477 | endif |
| 478 | |
| 479 | let result = s:NetGetFile(readcmd,tmpfile, b:netrw_method) |
| 480 | let b:netrw_lastfile = choice |
| 481 | |
| 482 | "......................................... |
| 483 | " sftp: NetRead Method #9 |
| 484 | elseif b:netrw_method == 9 " read with sftp |
| 485 | " call Decho("read via sftp (method #4)") |
| 486 | if g:netrw_cygwin == 1 |
| 487 | let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e') |
| 488 | " call Decho("!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile) |
| 489 | " call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile) |
| 490 | exe "!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".cygtmpfile |
| 491 | else |
| 492 | " call Decho("executing: !".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile) |
| 493 | exe g:netrw_silentxfer."!".g:netrw_sftp_cmd." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')." ".tmpfile |
| 494 | endif |
| 495 | let result = s:NetGetFile(readcmd, tmpfile, b:netrw_method) |
| 496 | let b:netrw_lastfile = choice |
| 497 | |
| 498 | "......................................... |
| 499 | else " Complain |
| 500 | echo "***warning*** unable to comply with your request<" . choice . ">" |
| 501 | endif |
| 502 | endwhile |
| 503 | |
| 504 | " cleanup |
| 505 | " call Decho("cleanup") |
| 506 | if exists("b:netrw_method") |
| 507 | unlet b:netrw_method |
| 508 | unlet g:netrw_machine |
| 509 | unlet b:netrw_fname |
| 510 | endif |
| 511 | call s:NetOptionRestore() |
| 512 | |
| 513 | " call Dret("NetRead") |
| 514 | endfun |
| 515 | " end of NetRead |
| 516 | |
| 517 | " ------------------------------------------------------------------------ |
| 518 | " NetGetFile: Function to read file "fname" with command "readcmd". {{{1 |
| 519 | fun! s:NetGetFile(readcmd, fname, method) |
| 520 | " call Dfunc("NetGetFile(readcmd<".a:readcmd.">,fname<".a:fname."> method<".a:method.">)") |
| 521 | |
| 522 | if exists("*NetReadFixup") |
| 523 | " for the use of NetReadFixup (not otherwise used internally) |
| 524 | let line2= line("$") |
| 525 | endif |
| 526 | |
| 527 | " transform paths from / to \ for Windows, unless the shell is bash |
| 528 | if &term == "win32" |
| 529 | if &shell == "bash" |
| 530 | let fname=a:fname |
| 531 | " call Decho("(win32 && bash) fname<".fname.">") |
| 532 | else |
| 533 | let fname=substitute(a:fname,'/','\\\\','ge') |
| 534 | " call Decho("(win32 && !bash) fname<".fname.">") |
| 535 | endif |
| 536 | else |
| 537 | let fname= a:fname |
| 538 | " call Decho("(copied) fname<".fname.">") |
| 539 | endif |
| 540 | |
| 541 | " get the file, but disable undo when reading a new buffer |
| 542 | if a:readcmd[0] == '0' |
| 543 | let use_e_cmd = 0 " 1 when using ':edit' |
| 544 | let delline = 0 " 1 when have to delete empty last line |
| 545 | if line("$") == 1 && getline(1) == "" |
| 546 | " Now being asked to 0r a file into an empty file. |
| 547 | " Safe to :e it instead, unless there is another window on the same buffer. |
| 548 | let curbufnr = bufnr("%") |
| 549 | let use_e_cmd = 1 |
| 550 | let delline = 1 |
| 551 | " Loop over all windows, |
| 552 | " reset use_e_cmd when another one is editing the current buffer. |
| 553 | let i = 1 |
| 554 | while 1 |
| 555 | if i != winnr() && winbufnr(i) == curbufnr |
| 556 | let use_e_cmd = 0 |
| 557 | break |
| 558 | endif |
| 559 | let i = i + 1 |
| 560 | if winbufnr(i) < 0 |
| 561 | break |
| 562 | endif |
| 563 | endwhile |
| 564 | endif |
| 565 | |
| 566 | if use_e_cmd > 0 |
| 567 | " ':edit' the temp file, wipe out the old buffer and rename the buffer |
| 568 | let curfilename = expand("%") |
| 569 | |
| 570 | let binlocal = &l:bin |
| 571 | let binglobal = &g:bin |
| 572 | if binlocal |
| 573 | setglobal bin " Need to set 'bin' globally for ":e" command. |
| 574 | endif |
| 575 | silent exe "e! ".v:cmdarg." ".fname |
| 576 | if binlocal && !binglobal |
| 577 | setglobal nobin |
| 578 | setlocal bin |
| 579 | endif |
| 580 | |
| 581 | exe curbufnr . "bwipe!" |
| 582 | exe "f ".curfilename |
| 583 | " the ":f newname" apparently leaves the temporary file as the alternate |
| 584 | " file in the buffer list (see :ls!). The following command wipes it out. |
| 585 | exe bufnr("#")."bwipe!" |
| 586 | else |
| 587 | let oldul= &ul |
| 588 | set ul=-1 |
| 589 | exe a:readcmd." ".v:cmdarg." ".fname |
| 590 | if delline > 0 |
| 591 | " wipe out last line, which should be a blank line anyway |
| 592 | $del |
| 593 | endif |
| 594 | let &ul= oldul |
| 595 | endif |
| 596 | elseif filereadable(fname) |
| 597 | " call Decho("exe<".a:readcmd." ".v:cmdarg." ".fname.">") |
| 598 | exe a:readcmd." ".v:cmdarg." ".fname |
| 599 | else |
| 600 | " call Dret("NetGetFile") |
| 601 | return |
| 602 | endif |
| 603 | |
| 604 | " User-provided (ie. optional) fix-it-up command |
| 605 | if exists("*NetReadFixup") |
| 606 | let line1= line(".") |
| 607 | if a:readcmd == "r" |
| 608 | let line2= line("$") - line2 + line1 |
| 609 | else |
| 610 | let line2= line("$") - line2 |
| 611 | endif |
| 612 | " call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")") |
| 613 | call NetReadFixup(a:method, line1, line2) |
| 614 | endif |
| 615 | |
| 616 | " call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> fname<".a:fname."> readable=".filereadable(a:fname)) |
| 617 | |
| 618 | " insure that we have the right filetype and that its being displayed |
| 619 | filetype detect |
| 620 | redraw! |
| 621 | " call Dret("NetGetFile") |
| 622 | endfun |
| 623 | |
| 624 | " ------------------------------------------------------------------------ |
| 625 | " NetWrite: responsible for writing a file over the net {{{1 |
| 626 | fun! s:NetWrite(...) range |
| 627 | " call Dfunc("NetWrite(a:0=".a:0.")") |
| 628 | |
| 629 | " option handling |
| 630 | let mod= 0 |
| 631 | call s:NetOptionSave() |
| 632 | |
| 633 | " Get Temporary Filename |
| 634 | let tmpfile= tempname() |
| 635 | |
| 636 | if a:0 == 0 |
| 637 | let ichoice = 0 |
| 638 | else |
| 639 | let ichoice = 1 |
| 640 | endif |
| 641 | |
| 642 | " write (selected portion of) file to temporary |
| 643 | silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile |
| 644 | |
| 645 | while ichoice <= a:0 |
| 646 | |
| 647 | " attempt to repeat with previous host-file-etc |
| 648 | if exists("b:netrw_lastfile") && a:0 == 0 |
| 649 | " call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">") |
| 650 | let choice = b:netrw_lastfile |
| 651 | let ichoice= ichoice + 1 |
| 652 | else |
| 653 | exe "let choice= a:" . ichoice |
| 654 | |
| 655 | " Reconstruct Choice if choice starts with '"' |
| 656 | if match(choice,"?") == 0 |
| 657 | echo 'NetWrite Usage:"' |
| 658 | echo ':Nwrite machine:path uses rcp' |
| 659 | echo ':Nwrite "machine path" uses ftp with <.netrc>' |
| 660 | echo ':Nwrite "machine id password path" uses ftp' |
| 661 | echo ':Nwrite dav://[user@]machine/path uses cadaver' |
| 662 | echo ':Nwrite fetch://[user@]machine/path uses fetch' |
| 663 | echo ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)' |
| 664 | echo ':Nwrite rcp://machine/path uses rcp' |
| 665 | echo ':Nwrite rsync://[user@]machine/path uses rsync' |
| 666 | echo ':Nwrite scp://[user@]machine[[:#]port]/path uses scp' |
| 667 | echo ':Nwrite sftp://[user@]machine/path uses sftp' |
| 668 | break |
| 669 | |
| 670 | elseif match(choice,"^\"") != -1 |
| 671 | if match(choice,"\"$") != -1 |
| 672 | " case "..." |
| 673 | let choice=strpart(choice,1,strlen(choice)-2) |
| 674 | else |
| 675 | " case "... ... ..." |
| 676 | let choice = strpart(choice,1,strlen(choice)-1) |
| 677 | let wholechoice = "" |
| 678 | |
| 679 | while match(choice,"\"$") == -1 |
| 680 | let wholechoice= wholechoice . " " . choice |
| 681 | let ichoice = ichoice + 1 |
| 682 | if choice > a:0 |
| 683 | echoerr "Unbalanced string in filename '". wholechoice ."'" |
| 684 | " call Dret("NetWrite") |
| 685 | return |
| 686 | endif |
| 687 | let choice= a:{ichoice} |
| 688 | endwhile |
| 689 | let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1) |
| 690 | endif |
| 691 | endif |
| 692 | endif |
| 693 | " call Decho("choice<" . choice . ">") |
| 694 | let ichoice= ichoice + 1 |
| 695 | |
| 696 | " fix up windows urls |
| 697 | if has("win32") |
| 698 | let choice= substitute(choice,'\\','/','ge') |
| 699 | "ER: see NetRead() |
| 700 | exe 'lcd ' . fnamemodify(tmpfile,':h') |
| 701 | let tmpfile = fnamemodify(tmpfile,':t') |
| 702 | endif |
| 703 | |
| 704 | " Determine method of read (ftp, rcp, etc) |
| 705 | call s:NetMethod(choice) |
| 706 | |
| 707 | " ============= |
| 708 | " Perform Write |
| 709 | " ============= |
| 710 | |
| 711 | "......................................... |
| 712 | " rcp: NetWrite Method #1 |
| 713 | if b:netrw_method == 1 " write with rcp |
| 714 | " Decho "write via rcp (method #1)" |
| 715 | if s:netrw_has_nt_rcp == 1 |
| 716 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 717 | let uid_machine = g:netrw_machine .'.'. g:netrw_uid |
| 718 | else |
| 719 | let uid_machine = g:netrw_machine .'.'. $USERNAME |
| 720 | endif |
| 721 | else |
| 722 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 723 | let uid_machine = g:netrw_uid .'@'. g:netrw_machine |
| 724 | else |
| 725 | let uid_machine = g:netrw_machine |
| 726 | endif |
| 727 | endif |
| 728 | " call Decho("executing: !".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".escape(b:netrw_fname,' ?&')) |
| 729 | exe g:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".tmpfile." ".uid_machine.":".escape(b:netrw_fname,' ?&') |
| 730 | let b:netrw_lastfile = choice |
| 731 | |
| 732 | "......................................... |
| 733 | " ftp + <.netrc>: NetWrite Method #2 |
| 734 | elseif b:netrw_method == 2 " write with ftp + <.netrc> |
| 735 | let netrw_fname = b:netrw_fname |
| 736 | new |
| 737 | set ff=unix |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 738 | exe "put ='".g:netrw_ftpmode."'" |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 739 | " call Decho(" NetWrite: put ='".g:netrw_ftpmode."'") |
| 740 | exe "put ='put ".tmpfile." ".netrw_fname."'" |
| 741 | " call Decho("put ='put ".tmpfile." ".netrw_fname."'") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 742 | if exists("g:netrw_port") && g:netrw_port != "" |
| 743 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port) |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 744 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine." ".g:netrw_port |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 745 | else |
| 746 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i ".g:netrw_machine) |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 747 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i ".g:netrw_machine |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 748 | endif |
| 749 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 750 | if getline(1) !~ "^$" |
| 751 | echoerr getline(1) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 752 | let mod=1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 753 | endif |
| 754 | bd! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 755 | let b:netrw_lastfile = choice |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 756 | |
| 757 | "......................................... |
| 758 | " ftp + machine, id, passwd, filename: NetWrite Method #3 |
| 759 | elseif b:netrw_method == 3 " write with ftp + machine, id, passwd, and fname |
| 760 | let netrw_fname= b:netrw_fname |
| 761 | new |
| 762 | set ff=unix |
| 763 | if exists("g:netrw_port") && g:netrw_port != "" |
| 764 | put ='open '.g:netrw_machine.' '.g:netrw_port |
| 765 | else |
| 766 | put ='open '.g:netrw_machine |
| 767 | endif |
| 768 | if exists("g:netrw_ftp") && g:netrw_ftp == 1 |
| 769 | put =g:netrw_uid |
| 770 | put =g:netrw_passwd |
| 771 | else |
| 772 | put ='user '.g:netrw_uid.' '.g:netrw_passwd |
| 773 | endif |
| 774 | put ='put '.tmpfile.' '.netrw_fname |
| 775 | " save choice/id/password for future use |
| 776 | let b:netrw_lastfile = choice |
| 777 | |
| 778 | " perform ftp: |
| 779 | " -i : turns off interactive prompting from ftp |
| 780 | " -n unix : DON'T use <.netrc>, even though it exists |
| 781 | " -n win32: quit being obnoxious about password |
| 782 | " call Decho('performing ftp -i -n') |
| 783 | norm 1Gdd |
| 784 | " call Decho("executing: %!".g:netrw_ftp_cmd." -i -n") |
| 785 | exe g:netrw_silentxfer."%!".g:netrw_ftp_cmd." -i -n" |
| 786 | " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar) |
| 787 | if getline(1) !~ "^$" |
| 788 | echoerr getline(1) |
| 789 | let mod=1 |
| 790 | endif |
| 791 | bd! |
| 792 | |
| 793 | "......................................... |
| 794 | " scp: NetWrite Method #4 |
| 795 | elseif b:netrw_method == 4 " write with scp |
| 796 | if exists("g:netrw_port") && g:netrw_port != "" |
| 797 | let useport= " -P ".g:netrw_port |
| 798 | else |
| 799 | let useport= "" |
| 800 | endif |
| 801 | if g:netrw_cygwin == 1 |
| 802 | let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e') |
| 803 | " call Decho("executing: !".g:netrw_scp_cmd.useport." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')) |
| 804 | exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&') |
| 805 | else |
| 806 | " call Decho("executing: !".g:netrw_scp_cmd.useport." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')) |
| 807 | exe g:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&') |
| 808 | endif |
| 809 | let b:netrw_lastfile = choice |
| 810 | |
| 811 | "......................................... |
| 812 | " http: NetWrite Method #5 |
| 813 | elseif b:netrw_method == 5 |
| 814 | echoerr "***warning*** currently <netrw.vim> does not support writing using http:" |
| 815 | |
| 816 | "......................................... |
| 817 | " dav: NetWrite Method #6 |
| 818 | elseif b:netrw_method == 6 " write with cadaver |
| 819 | " call Decho("write via cadaver (method #6)") |
| 820 | |
| 821 | " Construct execution string (four lines) which will be passed through filter |
| 822 | let netrw_fname= b:netrw_fname |
| 823 | new |
| 824 | set ff=unix |
| 825 | if exists("g:netrw_port") && g:netrw_port != "" |
| 826 | put ='open '.g:netrw_machine.' '.g:netrw_port |
| 827 | else |
| 828 | put ='open '.g:netrw_machine |
| 829 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 830 | put ='user '.g:netrw_uid.' '.g:netrw_passwd |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 831 | |
| 832 | if g:netrw_cygwin == 1 |
| 833 | let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e') |
| 834 | put ='put '.cygtmpfile.' '.netrw_fname |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 835 | else |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 836 | put ='put '.tmpfile.' '.netrw_fname |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 837 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 838 | |
| 839 | " perform cadaver operation: |
| 840 | norm 1Gdd |
| 841 | " call Decho("executing: %!".g:netrw_dav_cmd) |
| 842 | exe g:netrw_silentxfer."%!".g:netrw_dav_cmd |
| 843 | bd! |
| 844 | let b:netrw_lastfile = choice |
| 845 | |
| 846 | "......................................... |
| 847 | " rsync: NetWrite Method #7 |
| 848 | elseif b:netrw_method == 7 " write with rsync |
| 849 | if g:netrw_cygwin == 1 |
| 850 | let cygtmpfile=substitute(tmpfile,'^\(\a\):','/cygdrive/\1/','e') |
| 851 | " call Decho("executing: !".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')) |
| 852 | exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".cygtmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 853 | else |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 854 | " call Decho("executing: !".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&')) |
| 855 | exe g:netrw_silentxfer."!".g:netrw_rsync_cmd." ".tmpfile." ".g:netrw_machine.":".escape(b:netrw_fname,' ?&') |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 856 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 857 | let b:netrw_lastfile = choice |
| 858 | |
| 859 | "......................................... |
| 860 | " scp: NetWrite Method #9 |
| 861 | elseif b:netrw_method == 9 " write with sftp |
| 862 | let netrw_fname= b:netrw_fname |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 863 | if exists("g:netrw_uid") && ( g:netrw_uid != "" ) |
| 864 | let uid_machine = g:netrw_uid .'@'. g:netrw_machine |
| 865 | else |
| 866 | let uid_machine = g:netrw_machine |
| 867 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 868 | new |
| 869 | set ff=unix |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 870 | put ='put '.tmpfile.' '.netrw_fname |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 871 | norm 1Gdd |
| 872 | " call Decho("executing: %!".g:netrw_sftp_cmd.' '.uid_machine) |
| 873 | exe g:netrw_silentxfer."%!".g:netrw_sftp_cmd.' '.uid_machine |
| 874 | bd! |
| 875 | let b:netrw_lastfile= choice |
| 876 | |
| 877 | "......................................... |
| 878 | else " Complain |
| 879 | echo "***warning*** unable to comply with your request<" . choice . ">" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 880 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 881 | endwhile |
| 882 | |
| 883 | " cleanup |
| 884 | " call Decho("cleanup") |
| 885 | let result=delete(tmpfile) |
| 886 | call s:NetOptionRestore() |
| 887 | |
| 888 | if a:firstline == 1 && a:lastline == line("$") |
| 889 | let &mod= mod " usually equivalent to set nomod |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 890 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 891 | |
| 892 | " call Dret("NetWrite") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 893 | endfun |
| 894 | " end of NetWrite |
| 895 | |
| 896 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 897 | " NetList: This function uses the command in g:netrw_list_cmd to get a list {{{1 |
| 898 | " of the contents of a remote directory. It is assumed that the |
| 899 | " g:netrw_list_cmd has a string, HOSTNAME, that needs to be substituted |
| 900 | " with the requested remote hostname first. |
| 901 | fun! <SID>NetList(dirname) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 902 | " call Dfunc("NetList(dirname<".a:dirname.">)") |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 903 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 904 | " make this buffer modifiable |
| 905 | setlocal ma |
| 906 | |
| 907 | " analyze a:dirname and g:netrw_list_cmd |
| 908 | let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$' |
| 909 | if a:dirname !~ dirpat |
| 910 | echoerr "NetList: I don't understand your dirname<".a:dirname.">" |
| 911 | " call Dret("NetList 0 : badly formatted dirname") |
| 912 | return 0 |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 913 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 914 | let method = substitute(a:dirname,dirpat,'\1','') |
| 915 | let user = substitute(a:dirname,dirpat,'\2','') |
| 916 | let machine = substitute(a:dirname,dirpat,'\3','') |
| 917 | let path = substitute(a:dirname,dirpat,'\4','') |
| 918 | let fname = substitute(a:dirname,'^.*/\ze.','','') |
| 919 | " call Decho("set up method <".method .">") |
| 920 | " call Decho("set up user <".user .">") |
| 921 | " call Decho("set up machine<".machine.">") |
| 922 | " call Decho("set up path <".path .">") |
| 923 | " call Decho("set up fname <".fname .">") |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 924 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 925 | let listcmd = substitute(g:netrw_list_cmd,'\<HOSTNAME\>',user.machine,'') |
| 926 | " call Decho("set up listcmd<".listcmd.">") |
| 927 | |
| 928 | if fname =~ '@$' && fname !~ '^"' |
| 929 | " call Decho("attempt transfer of symlink as file") |
| 930 | call s:NetList(substitute(a:dirname,'@$','','e')) |
| 931 | redraw! |
| 932 | " call Dret("NetList 0 : symlink") |
| 933 | return 0 |
| 934 | |
| 935 | elseif fname !~ '/$' && fname !~ '^"' |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 936 | " looks like a regular file, attempt transfer |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 937 | " call Decho("attempt transfer as regular file<".a:dirname.">") |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 938 | |
| 939 | " remove any filetype indicator from end of dirname, except for the |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 940 | " "this is a directory" indicator (/). There shouldn't be one of those, |
| 941 | " anyway. |
| 942 | let path= substitute(path,'[*=@|]$','','e') |
| 943 | " call Decho("new path<".path.">") |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 944 | |
| 945 | " remote-read the requested file into current buffer |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 946 | enew! |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 947 | exe "file ".method."://".machine."/".path |
| 948 | exe "silent doau BufReadPre ".fname |
| 949 | silent call s:NetRead(method."://".machine."/".path) |
| 950 | exe "silent doau BufReadPost ".fname |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 951 | 1d |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 952 | set nomod |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 953 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 954 | " call Dret("NetList 0 : file<".fname.">") |
| 955 | return 0 |
| 956 | endif |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 957 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 958 | " --------------------------------------------------------------------- |
| 959 | " Perform Directory Listing: |
| 960 | " call Decho("Perform directory listing...") |
| 961 | " set up new buffer and map |
| 962 | let bufname = method.'://'.user.machine.'/'.path |
| 963 | let bufnamenr = bufnr(bufname) |
| 964 | " call Decho("bufname<".bufname."> bufnamenr=".bufnamenr) |
| 965 | if bufnamenr != -1 |
| 966 | " buffer already exists, switch to it! |
| 967 | exe "b ".bufnamenr |
| 968 | if line("$") >= 5 |
| 969 | " call Dret("NetList 1") |
| 970 | return 1 |
| 971 | endif |
| 972 | else |
| 973 | enew! |
| 974 | endif |
| 975 | setlocal bt=nofile bh=wipe nobl |
| 976 | exe 'file '.bufname |
| 977 | set bt=nowrite bh=hide nobl |
| 978 | nnoremap <buffer> <cr> :exe "norm! 0"<bar>call <SID>NetList(<SID>NetListChgDir(expand("%")))<cr> |
| 979 | setlocal ma |
| 980 | |
| 981 | " call Decho("executing: r! ".listcmd." '".path."'") |
| 982 | keepjumps put ='\" ==============================' |
| 983 | keepjumps put ='\" Netrw Remote Directory Listing' |
| 984 | keepjumps put ='\" '.bufname |
| 985 | keepjumps put ='\" ==============================' |
| 986 | exe "silent r! ".listcmd." '".path."'" |
| 987 | keepjumps 1d |
| 988 | set ft=netrwlist |
| 989 | if line("$") >= 5 |
| 990 | keepjumps silent 5,$s/^\(.*\)\([/@]\)$/ \2\1/e |
| 991 | keepjumps silent 5,$call s:NetSort() |
| 992 | keepjumps silent 5,$s/^ \(.\)\(.*\)$/\2\1/e |
| 993 | keepjumps 5 |
| 994 | endif |
| 995 | let prvbuf= bufnr(bufname) |
| 996 | if prvbuf != -1 |
| 997 | exe "silent! b ".prvbuf |
| 998 | endif |
| 999 | |
| 1000 | setlocal noma nomod |
| 1001 | |
| 1002 | " call Dret("NetList 1") |
| 1003 | return 1 |
| 1004 | endfun |
| 1005 | |
| 1006 | " --------------------------------------------------------------------- |
| 1007 | " NetListCombine: |
| 1008 | fun! <SID>NetListChgDir(dirname) |
| 1009 | let newdir= expand("<cWORD>") |
| 1010 | " call Dfunc("NetListChgDir(dirname<".a:dirname.">) newdir<".newdir.">") |
| 1011 | |
| 1012 | let dirname= a:dirname |
| 1013 | |
| 1014 | if newdir !~ '/$' |
| 1015 | " handling a file |
| 1016 | let dirname= dirname.newdir |
| 1017 | " call Decho("handling a file: dirname<".dirname.">") |
| 1018 | |
| 1019 | elseif newdir == './' |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1020 | " refresh the directory list |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1021 | " call Decho("refresh directory listing") |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1022 | %d |
| 1023 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1024 | elseif newdir == '../' |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1025 | " go up one directory |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1026 | let trailer= substitute(a:dirname,'^\(\w\+://\%(\w\+@\)\=\w\+/\)\(.*\)$','\2','') |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1027 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1028 | if trailer =~ '^\%(\.\./\)*$' |
| 1029 | " tack on a ../" |
| 1030 | let dirname= dirname.'../' |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1031 | |
| 1032 | else |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1033 | " strip off a directory name from dirname |
| 1034 | let dirname= substitute(dirname,'^\(.*/\)[^/]\+/','\1','') |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1035 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1036 | " call Decho("go up one dir: dirname<".dirname."> trailer<".trailer.">") |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1037 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1038 | else |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1039 | " go down one directory |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1040 | let dirname= dirname.newdir |
| 1041 | " call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">") |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1042 | endif |
| 1043 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1044 | " call Dret("NetListChgDir <".dirname.">") |
| 1045 | return dirname |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1046 | endfun |
| 1047 | |
| 1048 | " ------------------------------------------------------------------------ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1049 | " NetMethod: determine method of transfer {{{1 |
| 1050 | " method == 1: rcp |
| 1051 | " 2: ftp + <.netrc> |
| 1052 | " 3: ftp + machine, id, password, and [path]filename |
| 1053 | " 4: scp |
| 1054 | " 5: http (wget) |
| 1055 | " 6: cadaver |
| 1056 | " 7: rsync |
| 1057 | " 8: fetch |
| 1058 | " 9: sftp |
| 1059 | fun! s:NetMethod(choice) " globals: method machine id passwd fname |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1060 | " call Dfunc("NetMethod(a:choice<".a:choice.">)") |
| 1061 | |
| 1062 | " initialization |
| 1063 | let b:netrw_method = 0 |
| 1064 | let g:netrw_machine = "" |
| 1065 | let b:netrw_fname = "" |
| 1066 | let g:netrw_port = "" |
| 1067 | |
| 1068 | " Patterns: |
| 1069 | " mipf : a:machine a:id password filename Use ftp |
| 1070 | " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd |
| 1071 | " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd |
| 1072 | " rcpurm : rcp://[user@]host/filename Use rcp |
| 1073 | " rcphf : [user@]host:filename Use rcp |
| 1074 | " scpurm : scp://[user@]host[[#:]port]/filename Use scp |
| 1075 | " httpurm : http://[user@]host/filename Use wget |
| 1076 | " davurm : dav://host[:port]/path Use cadaver |
| 1077 | " rsyncurm : rsync://host[:port]/path Use rsync |
| 1078 | " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http) |
| 1079 | " sftpurm : sftp://[user@]host/filename Use scp |
| 1080 | let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$' |
| 1081 | let mf = '^\(\S\+\)\s\+\(\S\+\)$' |
| 1082 | let ftpurm = '^ftp://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$' |
| 1083 | let rcpurm = '^rcp://\(\([^/@]\{-}\)@\)\=\([^/]\{-}\)/\(.*\)$' |
| 1084 | let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$' |
| 1085 | let scpurm = '^scp://\([^/]\{-}\)\([#:]\d\+\)\=/\(.*\)$' |
| 1086 | let httpurm = '^http://\([^/]\{-}\)\(/.*\)\=$' |
| 1087 | let davurm = '^dav://\([^/]\{-}\)/\(.*\)\=$' |
| 1088 | let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$' |
| 1089 | let fetchurm = '^fetch://\(\([^/@]\{-}\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$' |
| 1090 | let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$' |
| 1091 | |
| 1092 | " call Decho("determine method:") |
| 1093 | " Determine Method |
| 1094 | " rcp://user@hostname/...path-to-file |
| 1095 | if match(a:choice,rcpurm) == 0 |
| 1096 | " call Decho("rcp://...") |
| 1097 | let b:netrw_method = 1 |
| 1098 | let userid = substitute(a:choice,rcpurm,'\2',"") |
| 1099 | let g:netrw_machine= substitute(a:choice,rcpurm,'\3',"") |
| 1100 | let b:netrw_fname = substitute(a:choice,rcpurm,'\4',"") |
| 1101 | if userid != "" |
| 1102 | let g:netrw_uid= userid |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1103 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1104 | |
| 1105 | " scp://user@hostname/...path-to-file |
| 1106 | elseif match(a:choice,scpurm) == 0 |
| 1107 | " call Decho("scp://...") |
| 1108 | let b:netrw_method = 4 |
| 1109 | let g:netrw_machine= substitute(a:choice,scpurm,'\1',"") |
| 1110 | let b:netrw_port = substitute(a:choice,scpurm,'\2',"") |
| 1111 | let b:netrw_fname = substitute(a:choice,scpurm,'\3',"") |
| 1112 | |
| 1113 | " http://user@hostname/...path-to-file |
| 1114 | elseif match(a:choice,httpurm) == 0 |
| 1115 | " call Decho("http://...") |
| 1116 | let b:netrw_method = 5 |
| 1117 | let g:netrw_machine= substitute(a:choice,httpurm,'\1',"") |
| 1118 | let b:netrw_fname = substitute(a:choice,httpurm,'\2',"") |
| 1119 | |
| 1120 | " dav://hostname[:port]/..path-to-file.. |
| 1121 | elseif match(a:choice,davurm) == 0 |
| 1122 | " call Decho("dav://...") |
| 1123 | let b:netrw_method= 6 |
| 1124 | let g:netrw_machine= substitute(a:choice,davurm,'\1',"") |
| 1125 | let b:netrw_fname = substitute(a:choice,davurm,'\2',"") |
| 1126 | |
| 1127 | " rsync://user@hostname/...path-to-file |
| 1128 | elseif match(a:choice,rsyncurm) == 0 |
| 1129 | " call Decho("rsync://...") |
| 1130 | let b:netrw_method = 7 |
| 1131 | let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"") |
| 1132 | let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"") |
| 1133 | |
| 1134 | " ftp://[user@]hostname[[:#]port]/...path-to-file |
| 1135 | elseif match(a:choice,ftpurm) == 0 |
| 1136 | " call Decho("ftp://...") |
| 1137 | let userid = substitute(a:choice,ftpurm,'\2',"") |
| 1138 | let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"") |
| 1139 | let g:netrw_port = substitute(a:choice,ftpurm,'\4',"") |
| 1140 | let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"") |
| 1141 | if g:netrw_port != "" |
| 1142 | let g:netrw_port = substitute(g:netrw_port,"[#:]","","") |
| 1143 | endif |
| 1144 | if userid != "" |
| 1145 | let g:netrw_uid= userid |
| 1146 | endif |
| 1147 | if exists("g:netrw_uid") && exists("g:netrw_passwd") |
| 1148 | let b:netrw_method = 3 |
| 1149 | else |
| 1150 | if filereadable(expand("$HOME/.netrc")) && !exists("g:netrw_ignorenetrc") |
| 1151 | let b:netrw_method= 2 |
| 1152 | else |
| 1153 | if !exists("g:netrw_uid") || g:netrw_uid == "" |
| 1154 | call NetUserPass() |
| 1155 | elseif !exists("g:netrw_passwd") || g:netrw_passwd == "" |
| 1156 | call NetUserPass(g:netrw_uid) |
| 1157 | " else just use current g:netrw_uid and g:netrw_passwd |
| 1158 | endif |
| 1159 | let b:netrw_method= 3 |
| 1160 | endif |
| 1161 | endif |
| 1162 | |
| 1163 | elseif match(a:choice,fetchurm) == 0 |
| 1164 | " call Decho("fetch://...") |
| 1165 | let b:netrw_method = 8 |
| 1166 | let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"") |
| 1167 | let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"") |
| 1168 | let b:netrw_option = substitute(a:choice,fetchurm,'\4',"") |
| 1169 | let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"") |
| 1170 | |
| 1171 | " Issue an ftp : "machine id password [path/]filename" |
| 1172 | elseif match(a:choice,mipf) == 0 |
| 1173 | " call Decho("(ftp) host id pass file") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1174 | let b:netrw_method = 3 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1175 | let g:netrw_machine = substitute(a:choice,mipf,'\1',"") |
| 1176 | let g:netrw_uid = substitute(a:choice,mipf,'\2',"") |
| 1177 | let g:netrw_passwd = substitute(a:choice,mipf,'\3',"") |
| 1178 | let b:netrw_fname = substitute(a:choice,mipf,'\4',"") |
| 1179 | |
| 1180 | " Issue an ftp: "hostname [path/]filename" |
| 1181 | elseif match(a:choice,mf) == 0 |
| 1182 | " call Decho("(ftp) host file") |
| 1183 | if exists("g:netrw_uid") && exists("g:netrw_passwd") |
| 1184 | let b:netrw_method = 3 |
| 1185 | let g:netrw_machine = substitute(a:choice,mf,'\1',"") |
| 1186 | let b:netrw_fname = substitute(a:choice,mf,'\2',"") |
| 1187 | |
| 1188 | elseif filereadable(expand("$HOME/.netrc")) |
| 1189 | let b:netrw_method = 2 |
| 1190 | let g:netrw_machine = substitute(a:choice,mf,'\1',"") |
| 1191 | let b:netrw_fname = substitute(a:choice,mf,'\2',"") |
| 1192 | endif |
| 1193 | |
| 1194 | " sftp://user@hostname/...path-to-file |
| 1195 | elseif match(a:choice,sftpurm) == 0 |
| 1196 | " call Decho("sftp://...") |
| 1197 | let b:netrw_method = 9 |
| 1198 | let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"") |
| 1199 | let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"") |
| 1200 | |
| 1201 | " Issue an rcp: hostname:filename" (this one should be last) |
| 1202 | elseif match(a:choice,rcphf) == 0 |
| 1203 | " call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">") |
| 1204 | let b:netrw_method = 1 |
| 1205 | let userid = substitute(a:choice,rcphf,'\2',"") |
| 1206 | let g:netrw_machine= substitute(a:choice,rcphf,'\3',"") |
| 1207 | let b:netrw_fname = substitute(a:choice,rcphf,'\4',"") |
| 1208 | " call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">") |
| 1209 | " call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">") |
| 1210 | " call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">") |
| 1211 | " call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">") |
| 1212 | if userid != "" |
| 1213 | let g:netrw_uid= userid |
| 1214 | endif |
| 1215 | if has("win32") |
| 1216 | " don't let PCs try <.netrc> |
| 1217 | let b:netrw_method = 3 |
| 1218 | endif |
| 1219 | |
| 1220 | else |
| 1221 | echoerr "***error*** cannot determine method" |
| 1222 | let b:netrw_method = -1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1223 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1224 | |
| 1225 | " call Decho("a:choice <".a:choice.">") |
| 1226 | " call Decho("b:netrw_method <".b:netrw_method.">") |
| 1227 | " call Decho("g:netrw_machine<".g:netrw_machine.">") |
| 1228 | " call Decho("g:netrw_port <".g:netrw_port.">") |
| 1229 | " if exists("g:netrw_uid") "Decho |
| 1230 | " call Decho("g:netrw_uid <".g:netrw_uid.">") |
| 1231 | " endif "Decho |
| 1232 | " if exists("g:netrw_passwd") "Decho |
| 1233 | " call Decho("g:netrw_passwd <".g:netrw_passwd.">") |
| 1234 | " endif "Decho |
| 1235 | " call Decho("b:netrw_fname <".b:netrw_fname.">") |
| 1236 | " call Dret("NetMethod") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1237 | endfun |
| 1238 | " end of NetMethod |
| 1239 | |
| 1240 | " ------------------------------------------------------------------------ |
| 1241 | " NetUserPass: set username and password for subsequent ftp transfer {{{1 |
| 1242 | " Usage: :call NetUserPass() -- will prompt for userid and password |
| 1243 | " :call NetUserPass("uid") -- will prompt for password |
| 1244 | " :call NetUserPass("uid","password") -- sets global userid and password |
| 1245 | fun! NetUserPass(...) |
| 1246 | |
| 1247 | " get/set userid |
| 1248 | if a:0 == 0 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1249 | " call Dfunc("NetUserPass(a:0<".a:0.">)") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1250 | if !exists("g:netrw_uid") || g:netrw_uid == "" |
| 1251 | " via prompt |
| 1252 | let g:netrw_uid= input('Enter username: ') |
| 1253 | endif |
| 1254 | else " from command line |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1255 | " call Dfunc("NetUserPass(a:1<".a:1.">) {") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1256 | let g:netrw_uid= a:1 |
| 1257 | endif |
| 1258 | |
| 1259 | " get password |
| 1260 | if a:0 <= 1 " via prompt |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1261 | " call Decho("a:0=".a:0." case <=1:") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1262 | let g:netrw_passwd= inputsecret("Enter Password: ") |
| 1263 | else " from command line |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1264 | " call Decho("a:0=".a:0." case >1: a:2<".a:2.">") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1265 | let g:netrw_passwd=a:2 |
| 1266 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1267 | " call Dret("NetUserPass") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1268 | endfun |
| 1269 | " end NetUserPass |
| 1270 | |
| 1271 | " ------------------------------------------------------------------------ |
| 1272 | " NetOptionSave: save options and set to "standard" form {{{1 |
| 1273 | fun!s:NetOptionSave() |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1274 | " call Dfunc("NetOptionSave()") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1275 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1276 | " Get Temporary Filename |
| 1277 | let s:aikeep = &ai |
| 1278 | let s:cinkeep = &cin |
| 1279 | let s:cinokeep = &cino |
| 1280 | let s:comkeep = &com |
| 1281 | let s:cpokeep = &cpo |
| 1282 | let s:dirkeep = getcwd() |
| 1283 | let s:gdkeep = &gd |
| 1284 | let s:twkeep = &tw |
| 1285 | set cino = |
| 1286 | set com = |
| 1287 | set cpo -=aA |
| 1288 | set nocin noai |
| 1289 | set tw =0 |
| 1290 | if has("win32") && !has("win95") |
| 1291 | let s:swfkeep= &swf |
| 1292 | set noswf |
| 1293 | " call Decho("setting s:swfkeep to <".&swf.">") |
| 1294 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1295 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1296 | " call Dret("NetOptionSave") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1297 | endfun |
| 1298 | |
| 1299 | " ------------------------------------------------------------------------ |
| 1300 | " NetOptionRestore: restore options {{{1 |
| 1301 | fun! s:NetOptionRestore() |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1302 | " call Dfunc("NetOptionRestore()") |
| 1303 | |
| 1304 | let &ai = s:aikeep |
| 1305 | let &cin = s:cinkeep |
| 1306 | let &cino = s:cinokeep |
| 1307 | let &com = s:comkeep |
| 1308 | let &cpo = s:cpokeep |
| 1309 | exe "lcd ".s:dirkeep |
| 1310 | let &gd = s:gdkeep |
| 1311 | let &tw = s:twkeep |
| 1312 | if exists("s:swfkeep") |
| 1313 | let &swf= s:swfkeep |
| 1314 | unlet s:swfkeep |
| 1315 | endif |
| 1316 | unlet s:aikeep |
| 1317 | unlet s:cinkeep |
| 1318 | unlet s:cinokeep |
| 1319 | unlet s:comkeep |
| 1320 | unlet s:cpokeep |
| 1321 | unlet s:gdkeep |
| 1322 | unlet s:twkeep |
| 1323 | unlet s:dirkeep |
| 1324 | |
| 1325 | " call Dret("NetOptionRestore") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1326 | endfun |
| 1327 | |
| 1328 | " ------------------------------------------------------------------------ |
| 1329 | " NetReadFixup: this sort of function is typically written by the user {{{1 |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1330 | " to handle extra junk that their system's ftp dumps |
| 1331 | " into the transfer. This function is provided as an |
| 1332 | " example and as a fix for a Windows 95 problem: in my |
| 1333 | " experience, win95's ftp always dumped four blank lines |
| 1334 | " at the end of the transfer. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1335 | if has("win95") && g:netrw_win95ftp |
| 1336 | fun! NetReadFixup(method, line1, line2) |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1337 | " call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1338 | if method == 3 " ftp (no <.netrc>) |
| 1339 | let fourblanklines= line2 - 3 |
| 1340 | silent fourblanklines.",".line2."g/^\s*/d" |
| 1341 | endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1342 | " call Dret("NetReadFixup") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1343 | endfun |
| 1344 | endif |
| 1345 | |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1346 | " --------------------------------------------------------------------- |
| 1347 | " NetSort: Piet Delport's BISort2() function, modified to take a range |
| 1348 | fun! <SID>NetSort() range |
| 1349 | let i = a:firstline + 1 |
| 1350 | while i <= a:lastline |
| 1351 | " find insertion point via binary search |
| 1352 | let i_val = getline(i) |
| 1353 | let lo = a:firstline |
| 1354 | let hi = i |
| 1355 | while lo < hi |
| 1356 | let mid = (lo + hi) / 2 |
| 1357 | let mid_val = getline(mid) |
| 1358 | if i_val < mid_val |
| 1359 | let hi = mid |
| 1360 | else |
| 1361 | let lo = mid + 1 |
| 1362 | if i_val == mid_val | break | endif |
| 1363 | endif |
| 1364 | endwhile |
| 1365 | " do insert |
| 1366 | if lo < i |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame^] | 1367 | exe 'keepjumps '.i.'d_' |
| 1368 | keepjumps call append(lo - 1, i_val) |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1369 | endif |
| 1370 | let i = i + 1 |
| 1371 | endwhile |
| 1372 | endfun |
| 1373 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1374 | " ------------------------------------------------------------------------ |
| 1375 | " Restore {{{1 |
| 1376 | let &cpo= s:save_cpo |
| 1377 | unlet s:save_cpo |
| 1378 | " vim:ts=8 fdm=marker |