mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 03:41:27 +00:00
Plugin organize
This commit is contained in:
parent
80c2c469da
commit
b9530a5ce0
|
@ -19,6 +19,7 @@ The currently available plugins are listed below.
|
||||||
| ndiff | sh | vimdiff | Diff for selection (limited to 2 for directories) |
|
| ndiff | sh | vimdiff | Diff for selection (limited to 2 for directories) |
|
||||||
| nmount | sh | pmount, udisks2 | Toggle mount status of a device as normal user |
|
| nmount | sh | pmount, udisks2 | Toggle mount status of a device as normal user |
|
||||||
| nwal | sh | nitrogen | Set the selected image as wallpaper using nitrogen |
|
| nwal | sh | nitrogen | Set the selected image as wallpaper using nitrogen |
|
||||||
|
| organize | sh | file | Auto-organize files in directories by file type |
|
||||||
| pastebin | sh | [pastebinit](https://launchpad.net/pastebinit) | Paste contents of (text) file to paste.ubuntu.com |
|
| pastebin | sh | [pastebinit](https://launchpad.net/pastebinit) | Paste contents of (text) file to paste.ubuntu.com |
|
||||||
| pdfview | sh | pdftotext/<br>mupdf-tools | View PDF file in `$PAGER` |
|
| pdfview | sh | pdftotext/<br>mupdf-tools | View PDF file in `$PAGER` |
|
||||||
| picker | sh | nnn | Pick files and pipe the newline-separated list to another utility |
|
| picker | sh | nnn | Pick files and pipe the newline-separated list to another utility |
|
||||||
|
|
53
plugins/organize
Executable file
53
plugins/organize
Executable file
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# Description: Organize files in directories by category
|
||||||
|
#
|
||||||
|
# Shell: POSIX compliant
|
||||||
|
# Author: th3lusive
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
Loading…
Reference in a new issue