aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/splitjoin
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-06-06 23:27:57 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-06-06 23:27:57 +0530
commita96ad1dab0e23335c670cc18014d096a5cba018e (patch)
tree1508794496f8893223bcee1088317f12308c4281 /plugins/splitjoin
parent40afe7ca4dba0160d814bf43f18d6aa78551eeba (diff)
downloadnnn-a96ad1dab0e23335c670cc18014d096a5cba018e.tar.gz
Add plugin to split or join files
Diffstat (limited to 'plugins/splitjoin')
-rwxr-xr-xplugins/splitjoin35
1 files changed, 35 insertions, 0 deletions
diff --git a/plugins/splitjoin b/plugins/splitjoin
new file mode 100755
index 0000000..cbb573e
--- /dev/null
+++ b/plugins/splitjoin
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+
+# Description: Splits the file passed as argument or joins selection
+#
+# Note: Adds numeric suffix to split files
+# Adds '.join' suffix to the first file to be joined and saves as output file for join
+#
+# Shell: Bash
+# Author: Arun Prakash Jana
+
+selection=~/.config/nnn/.selection
+
+echo -n "press 's' (split current file) or 'j' (join selection): "
+read resp
+
+if [ "$resp" = "j" ]; then
+ if [ -s "$selection" ]; then
+ arr=$(cat $selection | tr '\0' '\n')
+ { read -r file; } <<< "$arr"
+
+ file=$(basename "$file").out
+
+ cat "$selection" | sort -z | xargs -0 -i cat {} > "$file"
+ fi
+elif [ "$resp" = "s" ]; then
+ if ! [ -z "$1" ] && [ -f "$1" ] ; then
+ # a single file is passed
+ echo -n "split size in MB: "
+ read size
+
+ if ! [ -z "$size" ]; then
+ split -d -b "$size"M "$1" "$1"
+ fi
+ fi
+fi