aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2018-09-06 04:12:42 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2018-09-06 04:12:42 +0530
commit655461a3f2ee7ff5daf83a86029f40ad286c788a (patch)
treed5368d8afb7f64de61c6e1a59f127c757a8aeac1 /scripts
parentad7c6442904296a9f71c7917abaec31b0f6d1367 (diff)
downloadnnn-655461a3f2ee7ff5daf83a86029f40ad286c788a.tar.gz
Add wrapper script for patool integration
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/natool/natool40
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/natool/natool b/scripts/natool/natool
new file mode 100755
index 0000000..dd08d54
--- /dev/null
+++ b/scripts/natool/natool
@@ -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())