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