]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #1333: plugin openall to open selection
authorArun Prakash Jana <engineerarun@gmail.com>
Thu, 31 Mar 2022 13:43:54 +0000 (19:13 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Thu, 31 Mar 2022 13:59:30 +0000 (19:29 +0530)
plugins/README.md
plugins/openall [new file with mode: 0755]

index 05f0351c5ef33d8dea2df90e8b1247a928a903bb..c13bf10ee6877aa98387a8c2ca41fda08c676594 100644 (file)
@@ -48,6 +48,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
 | [nmount](nmount) | Toggle mount status of a device as normal user | sh | pmount, udisks2 |
 | [nuke](nuke) | Sample file opener (CLI-only by default) | sh | _see in-file docs_ |
 | [oldbigfile](oldbigfile) | List large files by access time | sh | find, sort |
+| [openall](openall) | Open selected files together or one by one [✓] | bash | - |
 | [organize](organize) | Auto-organize files in directories by file type [✓] | sh | file |
 | [pdfread](pdfread) | Read a PDF or text file aloud | sh | pdftotext, mpv,<br>pico2wave |
 | [preview-tabbed](preview-tabbed) | Preview files with Tabbed/xembed | bash | _see in-file docs_ |
diff --git a/plugins/openall b/plugins/openall
new file mode 100755 (executable)
index 0000000..fe382a4
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+
+# Description: Open selected files in nuke one by one or in oneshot
+#              Tip: keep pressing "Enter" to open files one by one
+#
+# Note: Uses nuke by default, easy to replace with preferred opener
+#       nuke is invoked once for each file in a loop
+#
+# Shell: bash
+# Author: Arun Prakash Jana
+
+sel=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
+nuke="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke"
+
+printf "open [A]ll? "
+read -r all
+
+if [ -s "$sel" ]; then
+    targets=()
+    while IFS= read -r -d '' entry || [ -n "$entry" ]; do
+        targets+=( "$entry" )
+    done < "$sel"
+fi
+
+last=${targets[${#targets[@]}-1]}
+
+for entry in "${targets[@]}"; do
+    # replace nuke with your preferred opened below
+    "$nuke" "$entry"
+    if [ "$all" != "A" ] && [ "$entry" != "$last" ]; then
+        printf "press Enter to open next\n"
+        read -r -s -n 1 key
+        if [[ $key != "" ]]; then
+            break
+        fi
+    fi
+done
+
+# Clear selection
+if [ -s "$sel" ] && [ -p "$NNN_PIPE" ]; then
+    printf "-" > "$NNN_PIPE"
+fi