15
15
" 2025 Mar 02 by Vim Project: determine the compression using readblob()
16
16
" instead of shelling out to file(1)
17
17
" 2025 Apr 16 by Vim Project: decouple from netrw by adding s:WinPath()
18
+ " 2025 May 19 by Vim Project: restore working directory after read/write
18
19
"
19
20
" Contains many ideas from Michael Toren's <tar.vim>
20
21
"
@@ -306,10 +307,10 @@ fun! tar#Read(fname,mode)
306
307
307
308
" attempt to change to the indicated directory
308
309
try
309
- exe " cd " .fnameescape (tmpdir)
310
+ exe " lcd " .fnameescape (tmpdir)
310
311
catch /^Vim\%((\a\+)\)\=:E344/
311
312
redraw !
312
- echohl Error | echo " ***error*** (tar#Write) cannot cd to temporary directory" | Echohl None
313
+ echohl Error | echo " ***error*** (tar#Write) cannot lcd to temporary directory" | Echohl None
313
314
let &report = repkeep
314
315
return
315
316
endtry
@@ -319,7 +320,7 @@ fun! tar#Read(fname,mode)
319
320
call s: Rmdir (" _ZIPVIM_" )
320
321
endif
321
322
call mkdir (" _ZIPVIM_" )
322
- cd _ZIPVIM_
323
+ lcd _ZIPVIM_
323
324
324
325
if has (" win32unix" ) && executable (" cygpath" )
325
326
" assuming cygwin
@@ -413,9 +414,9 @@ fun! tar#Read(fname,mode)
413
414
redraw !
414
415
415
416
if v: shell_error != 0
416
- cd ..
417
+ lcd ..
417
418
call s: Rmdir (" _ZIPVIM_" )
418
- exe " cd " .fnameescape (curdir)
419
+ exe " lcd " .fnameescape (curdir)
419
420
echohl Error | echo " ***error*** (tar#Read) sorry, unable to open or extract " .tarfile." with " .fname | echohl None
420
421
endif
421
422
@@ -432,14 +433,16 @@ if v:shell_error != 0
432
433
set nomod
433
434
434
435
let &report = repkeep
436
+ exe " lcd " .fnameescape (curdir)
437
+ silent exe " file tarfile::" .escape_file
435
438
endfun
436
439
437
440
" ---------------------------------------------------------------------
438
441
" tar#Write: {{{2
439
442
fun ! tar#Write (fname)
443
+ let pwdkeep= getcwd ()
440
444
let repkeep= &report
441
445
set report = 10
442
- " temporary buffer variable workaround because too fucking tired. but it works now
443
446
let curdir= b: curdir
444
447
let tmpdir= b: tmpdir
445
448
@@ -563,9 +566,9 @@ fun! tar#Write(fname)
563
566
endif
564
567
565
568
" cleanup and restore current directory
566
- cd ..
569
+ lcd ..
567
570
call s: Rmdir (" _ZIPVIM_" )
568
- exe " cd " .fnameescape (curdir )
571
+ exe " lcd " .fnameescape (pwdkeep )
569
572
setlocal nomod
570
573
571
574
let &report = repkeep
@@ -807,7 +810,7 @@ fun! tar#Vimuntar(...)
807
810
if simplify (curdir) != simplify (vimhome)
808
811
" copy (possibly compressed) tarball to .vim/vimfiles
809
812
call system (s: WinPath (g: tar_copycmd )." " .shellescape (tartail)." " .shellescape (vimhome))
810
- exe " cd " .fnameescape (vimhome)
813
+ exe " lcd " .fnameescape (vimhome)
811
814
endif
812
815
813
816
" if necessary, decompress the tarball; then, extract it
@@ -821,7 +824,7 @@ fun! tar#Vimuntar(...)
821
824
if simplify (curdir) != simplify (tarhome)
822
825
" remove decompressed tarball, restore directory
823
826
call delete (tartail." .tar" )
824
- exe " cd " .fnameescape (curdir)
827
+ exe " lcd " .fnameescape (curdir)
825
828
endif
826
829
return
827
830
endif
@@ -839,7 +842,7 @@ fun! tar#Vimuntar(...)
839
842
if simplify (tarhome) != simplify (vimhome)
840
843
" remove decompressed tarball, restore directory
841
844
call delete (vimhome." /" .tarbase." .tar" )
842
- exe " cd " .fnameescape (curdir)
845
+ exe " lcd " .fnameescape (curdir)
843
846
endif
844
847
endfun
845
848
0 commit comments