From 343c504bfa06494bc5fd7988ce37806353efccef Mon Sep 17 00:00:00 2001 From: Saul Pwanson Date: Thu, 19 Oct 2023 15:57:41 -0700 Subject: [PATCH] [zip] add Ctrl+O/sysopen-row to open file in $EDITOR #1708 --- visidata/loaders/archive.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/visidata/loaders/archive.py b/visidata/loaders/archive.py index 49ffea446..463c7d446 100644 --- a/visidata/loaders/archive.py +++ b/visidata/loaders/archive.py @@ -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.' @@ -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'),