Skip to content

Commit

Permalink
[zip] add Ctrl+O/sysopen-row to open file in $EDITOR #1708
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Oct 19, 2023
1 parent 9feb5e0 commit 343c504
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions visidata/loaders/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ def extract(self, *rows, path=None):
vd.confirm(f'{r.filename} exists, overwrite? ') #1452
self.extract_async(row)

def sysopen_row(self, row):
'Extract file in row to tempdir and launch $EDITOR. Modifications will be discarded.'
import tempfile
with tempfile.TemporaryDirectory() as tempdir:
self.zfp.extract(member=row[0], path=tempdir)
vd.launchExternalEditorPath(Path(tempdir)/row[0].filename)

@asyncthread
def extract_async(self, *rows, path=None):
'Extract rows to *path*, without confirmation.'
Expand Down Expand Up @@ -138,6 +145,7 @@ def iterload(self):
ZipSheet.addCommand('gx', 'extract-selected', 'extract(*onlySelectedRows)', 'extract selected files to current directory')
ZipSheet.addCommand('zx', 'extract-file-to', 'extract(cursorRow, path=inputPath("extract to: "))', 'extract current file to given pathname')
ZipSheet.addCommand('gzx', 'extract-selected-to', 'extract(*onlySelectedRows, path=inputPath("extract %d files to: " % nSelectedRows))', 'extract selected files to given directory')
ZipSheet.addCommand('Ctrl+O', 'sysopen-row', 'sysopen_row(cursorRow)', 'open $EDITOR with current file (modifications will be discarded)')

vd.addMenu(Menu('File', Menu('Extract',
Menu('current file', 'extract-file'),
Expand Down

0 comments on commit 343c504

Please sign in to comment.