aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorGravatar ath3 <ha05190@protonmail.com>2019-06-19 03:57:09 +0200
committerGravatar ath3 <ha05190@protonmail.com>2019-06-19 04:06:19 +0200
commit4757873d3a4f72664649f12c56aa7f593cd0cfa6 (patch)
tree385a790887c1c8f0315e7373085818931cc1079a /plugins
parent4679daa7619f397f6d4a2e352e53df16d4e3140b (diff)
downloadnnn-4757873d3a4f72664649f12c56aa7f593cd0cfa6.tar.gz
Added md5sum plugin
Diffstat (limited to 'plugins')
-rw-r--r--plugins/README.md1
-rwxr-xr-xplugins/md5sum36
2 files changed, 37 insertions, 0 deletions
diff --git a/plugins/README.md b/plugins/README.md
index 1d243da..3b8f550 100644
--- a/plugins/README.md
+++ b/plugins/README.md
@@ -9,6 +9,7 @@
| imgur | bash | - | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) |
| ipinfo | sh | curl, whois | Fetch external IP address and whois information |
| kdeconnect | sh | kdeconnect-cli | Send selected files to an Android device |
+| md5sum | sh | md5sum | Create and verify md5 checksums |
| mocplay | sh | [moc](http://moc.daper.net/) | Appends (and plays, see script) selection/dir/file in moc|
| ndiff | bash | vimdiff | Diff for selection (limited to 2 for directories) |
| nmount | sh | pmount, udisks2 | Toggle mount status of a device as normal user |
diff --git a/plugins/md5sum b/plugins/md5sum
new file mode 100755
index 0000000..0ba8a1b
--- /dev/null
+++ b/plugins/md5sum
@@ -0,0 +1,36 @@
+#!/usr/bin/env sh
+
+# Description: Create and verify md5 checksums
+#
+# If selection is used: it will generate one md5 file containing the checksums and file names
+# [with paths if they are in another directory]
+# If file is used: if the file is .md5 file, then it does the check
+# if the file is not .md5 file, it creates the md5 file from it
+#
+# Shell: POSIX compliant
+# Author: ath3
+
+selection=~/.config/nnn/.selection
+resp=f
+
+if [ -s "$selection" ]; then
+ echo -n "work with selection (s) or current file (f) [default=f]: "
+ read resp
+fi
+
+if [ "$resp" = "s" ]; then
+ arr=$(cat $selection | tr '\0' '\n')
+ { read -r file; } <<< "$arr"
+ file=$(basename "$file").md5
+ cat "$selection" | sed 's|'"$PWD/"'||g' | xargs -0 -i md5sum {} > "$file"
+else
+ if ! [ -z "$1" ] && [ -f "$1" ]; then
+ if [ $(echo $1 | grep \.md5$) ]; then
+ cat "$1" | md5sum -c
+ read
+ else
+ file=$(basename "$1").md5
+ md5sum "$1" > "$file"
+ fi
+ fi
+fi