]> Sergey Matveev's repositories - nnn.git/commitdiff
Add wrapper script for patool integration
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 5 Sep 2018 22:42:42 +0000 (04:12 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 5 Sep 2018 22:42:42 +0000 (04:12 +0530)
README.md
scripts/natool/natool [new file with mode: 0755]

index a672cead5a47f4a7418fbcdbaab2609ae1c70cce..ad6652e10b9924045efdc022f42dd8650e0ffdc8 100644 (file)
--- a/README.md
+++ b/README.md
@@ -66,6 +66,7 @@ Have fun with it! Missing a feature? Want to contribute? Head to the rolling [To
   - [dual-pane or multi-pane](#dual-pane-or-multi-pane)
   - [change dir color](#change-dir-color)
   - [file copy, move, delete](#file-copy-move-delete)
+  - [integrate patool](#integrate-patool)
   - [work faster at rename prompt](#work-faster-at-rename-prompt)
   - [set idle timeout](#set-idle-timeout)
   - [show hot plugged drives](#show-hot-plugged-drives)
@@ -480,6 +481,10 @@ Any other value disables colored directories.
 
 In addition, `nnn` integrates with vidir. vidir supports batch file move and delete.
 
+#### integrate patool
+
+On systems where `atool` is not available but `patool` is, drop two copies of the Python3 script [natool](https://github.com/jarun/nnn/blob/master/scripts/natool) as `atool` and `apack` somewhere in `$PATH`.
+
 #### work faster at rename prompt
 
 The rename prompt supports some bash-like command-line shortcuts - <kbd>^A</kbd>, <kbd>^E</kbd>, <kbd>^U</kbd>. <kbd>^L</kbd> clears the name.
diff --git a/scripts/natool/natool b/scripts/natool/natool
new file mode 100755 (executable)
index 0000000..dd08d54
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+# #############################################################################
+# natool: a wrapper script to patool to list, extract and create archives
+#
+# usage: natool [-l] [-x] [archive] [file/dir]
+#
+# Examples:
+# - list archive   : natool -l archive.7z
+# - extract archive: natool -x archive.7z
+# - create archive : natool archive.7z archive_dir
+#
+# Brief:
+# natool is written to integrate patool (instead of the default atool) with nnn
+# Two copies of this file should be dropped somewhere in $PATH - atool, apack
+#
+# Author: Arun Prakash Jana
+# Email: engineerarun@gmail.com
+# Homepage: https://github.com/jarun/nnn
+# Copyright © 2018 Arun Prakash Jana
+# #############################################################################
+
+import sys
+from subprocess import Popen, PIPE, DEVNULL
+
+if len(sys.argv) != 3:
+    print('usage: natool [-l] [-x] [archive] [file/dir]')
+    sys.exit(0)
+
+if sys.argv[1] == '-x':
+    cmd = ['patool', '--non-interactive', 'extract', sys.argv[2]]
+elif sys.argv[1] == '-l':
+    cmd = ['patool', '--non-interactive', 'list', sys.argv[2]]
+else:
+    cmd = ['patool', '--non-interactive', 'create', sys.argv[1], sys.argv[2]]
+
+pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+out, err = pipe.communicate()
+print(out.decode())
+print(err.decode())