aboutsummaryrefslogtreecommitdiff
path: root/files/.config/nnn/plugins/organize
diff options
context:
space:
mode:
Diffstat (limited to 'files/.config/nnn/plugins/organize')
-rwxr-xr-xfiles/.config/nnn/plugins/organize62
1 files changed, 62 insertions, 0 deletions
diff --git a/files/.config/nnn/plugins/organize b/files/.config/nnn/plugins/organize
new file mode 100755
index 0000000..fb70aaf
--- /dev/null
+++ b/files/.config/nnn/plugins/organize
@@ -0,0 +1,62 @@
+#!/usr/bin/env sh
+
+# Description: Organize files in directories by category
+#
+# Note: This plugin clears the selection as it changes the contents of the current dir
+#
+# Shell: POSIX compliant
+# Author: th3lusive
+
+sel=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
+
+organize() {
+ case "$(file -biL "$1")" in
+ *video*)
+ [ ! -d "Videos" ] && mkdir "Videos"
+ mv "$1" "Videos/$1"
+ printf "Moved %s to Videos\n" "$1" ;;
+
+ *audio*) [ ! -d "Audio" ] && mkdir "Audio"
+ mv "$1" "Audio/$1"
+ printf "Moved %s to Audio\n" "$1" ;;
+
+ *image*)
+ [ ! -d "Images" ] && mkdir "Images"
+ mv "$1" "Images/$1"
+ printf "Moved %s to Images\n" "$1" ;;
+
+ *pdf*|*document*|*epub*|*djvu*|*cb*)
+ [ ! -d "Documents" ] && mkdir "Documents"
+ mv "$1" "Documents/$1"
+ printf "Moved %s to Documents\n" "$1" ;;
+
+ *text*)
+ [ ! -d "Plaintext" ] && mkdir "Plaintext"
+ mv "$1" "Plaintext/$1"
+ printf "Moved %s to Plaintext\n" "$1" ;;
+
+ *tar*|*xz*|*compress*|*7z*|*rar*|*zip*)
+ [ ! -d "Archives" ] && mkdir "Archives"
+ mv "$1" "Archives/$1"
+ printf "Moved %s to Archives\n" "$1" ;;
+
+ *binary*)
+ [ ! -d "Binaries" ] && mkdir "Binaries"
+ mv "$1" "Binaries/$1"
+ printf "Moved %s to Binaries\n" "$1" ;;
+ esac
+}
+
+main() {
+ for file in *
+ do
+ [ -f "$file" ] && organize "$file"
+ done
+
+ # Clear selection
+ if [ -s "$sel" ] && [ -p "$NNN_PIPE" ]; then
+ printf "-" > "$NNN_PIPE"
+ fi
+}
+
+main "$@"