Merge pull request #286 from ath3/plugin-md5sum

Added md5sum plugin
This commit is contained in:
Mischievous Meerkat 2019-06-20 18:36:07 +05:30 committed by GitHub
commit bccc2a0921
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 108 additions and 29 deletions

View file

@ -9,15 +9,16 @@
| imgur | bash | - | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) | | 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 | | ipinfo | sh | curl, whois | Fetch external IP address and whois information |
| kdeconnect | sh | kdeconnect-cli | Send selected files to an Android device | | kdeconnect | sh | kdeconnect-cli | Send selected files to an Android device |
| checksum | sh | md5sum, sha256sum | Create and verify checksums |
| mocplay | sh | [moc](http://moc.daper.net/) | Appends (and plays, see script) selection/dir/file in moc| | 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) | | 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 |
| 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/mupdf-tools | View PDF file in `$PAGER` | | pdfview | sh | pdftotext/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 |
| pywal | sh | pywal | Set selected image as wallpaper, change terminal color scheme | | pywal | sh | pywal | Set selected image as wallpaper, change terminal color scheme |
| splitjoin | bash | split, cat | Split file or join selection | | splitjoin | sh | split, cat | Split file or join selection |
| sxiv | sh | sxiv | Browse images in a dir in sxiv, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts))| | sxiv | sh | sxiv | Browse images in a dir in sxiv, set wallpaper, copy path ([config](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts))|
| transfer | sh | curl | Upload file to transfer.sh | | transfer | sh | curl | Upload file to transfer.sh |
| upgrade | sh | wget | Upgrade to latest nnn version manually on Debian 9 Stretch | | upgrade | sh | wget | Upgrade to latest nnn version manually on Debian 9 Stretch |

64
plugins/checksum Executable file
View file

@ -0,0 +1,64 @@
#!/usr/bin/env sh
# Description: Create and verify checksums
#
# If selection is used: it will generate one file containing the checksums with file names
# [and with paths if they are in another directory]
# The filename will be checksum_timestamp.checksum_type
# If file is used: if the file is a checksum, it does the verification
# if the file is not a checksum, it will be created from it
# The filename will be filename.checksum_type
#
# Shell: POSIX compliant
# Author: ath3
selection=~/.config/nnn/.selection
resp=f
chsum=md5
ischksum=0
checksum_type()
{
echo "possible checksums: md5, sha1, sha224, sha256, sha384, sha512"
echo -n "create md5 (m), sha256 (s), sha512 (S) (or type one of the above checksums) [default=m]: "
read chsum_resp
for chks in md5 sha1 sha224 sha256 sha384 sha512
do
if [ "$chsum_resp" = "$chks" ]; then
chsum=$chsum_resp
return
fi
done
if [ "$chsum_resp" = "s" ]; then
chsum=sha256
elif [ "$chsum_resp" = "S" ]; then
chsum=sha512
fi
}
if [ -s "$selection" ]; then
echo -n "work with selection (s) or current file (f) [default=f]: "
read resp
fi
if [ "$resp" = "s" ]; then
checksum_type
sed 's|'"$PWD/"'||g' < "$selection" | xargs -0 -i ${chsum}sum {} > "checksum_$(date '+%Y%m%d%H%M').$chsum"
else
if [ -n "$1" ] && [ -f "$1" ]; then
for chks in md5 sha1 sha224 sha256 sha384 sha512
do
if [ "$(echo "$1" | grep \.${chks}$)" ]; then
ischksum=1
${chks}sum -c < "$1"
read
exit
fi
done
if [ $ischksum -eq 0 ]; then
checksum_type
file=$(basename "$1").$chsum
${chsum}sum "$1" > "$file"
fi
fi
fi

View file

@ -1,26 +1,28 @@
#!/usr/bin/env bash #!/usr/bin/env sh
# Description: Show diff of 2 directories or multiple files in vimdiff # Description: Show diff of 2 directories or multiple files in vimdiff
# #
# Shell: Bash # Shell: POSIX compliant
# Author: Arun Prakash Jana # Author: Arun Prakash Jana
selection=~/.config/nnn/.selection selection=~/.config/nnn/.selection
if [ -s $selection ]; then if [ -s $selection ]; then
arr=$(cat $selection | tr '\0' '\n') arr=$(tr '\0' '\n' < "$selection")
{ read -r f1; read -r f2; } <<< "$arr" if [ "$(echo "$arr" | wc -l)" -gt 1 ]; then
f1="$(echo "$arr" | sed -n '1p')"
if [ -z "$f2" ]; then f2="$(echo "$arr" | sed -n '2p')"
exit if [ -d "$f1" ] && [ -d "$f2" ]; then
fi dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-$(basename "$f1").XXXXXXXX)
dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-$(basename "$f2").XXXXXXXX)
if [ -d "$f1" ] && [ -d "$f2" ]; then ls -A1 "$f1" > "$dir1"
vimdiff <(cd "$f1" && find | sort) <(cd "$f2" && find | sort) ls -A1 "$f2" > "$dir2"
vimdiff "$dir1" "$dir2"
rm "$dir1" "$dir2"
else
cat $selection | xargs -0 vimdiff
fi
else else
cat $selection | xargs -0 -o vimdiff echo "needs at least 2 files or directories selected for comparison"
# For GNU xargs (note: ignoreme takes up $0)
# cat $selection | xargs -0 bash -c '</dev/tty vimdiff "$@"' ignoreme
fi fi
fi fi

View file

@ -1,34 +1,46 @@
#!/usr/bin/env bash #!/usr/bin/env sh
# Description: Splits the file passed as argument or joins selection # Description: Splits the file passed as argument or joins selection
# #
# Note: Adds numeric suffix to split files # Note: Adds numeric suffix to split files
# Adds '.join' suffix to the first file to be joined and saves as output file for join # Adds '.out suffix to the first file to be joined and saves as output file for join
# #
# Shell: Bash # Shell: POSIX compliant
# Author: Arun Prakash Jana # Author: Arun Prakash Jana
selection=~/.config/nnn/.selection selection=~/.config/nnn/.selection
resp=s
echo -n "press 's' (split current file) or 'j' (join selection): " if [ -s "$selection" ]; then
read resp echo -n "press 's' (split current file) or 'j' (join selection): "
read resp
fi
if [ "$resp" = "j" ]; then if [ "$resp" = "j" ]; then
if [ -s "$selection" ]; then if [ -s "$selection" ]; then
arr=$(cat $selection | tr '\0' '\n') arr=$(tr '\0' '\n' < "$selection")
{ read -r file; } <<< "$arr" if [ "$(echo "$arr" | wc -l)" -lt 2 ]; then
echo "joining needs at least 2 files"
exit
fi
for entry in $arr
do
if [ -d "$entry" ]; then
echo "cant join directories"
exit
fi
done
file=$(basename "$file").out file="$(basename "$(echo "$arr" | sed -n '1p' | sed -e 's/[0-9][0-9]$//')")"
sort -z < "$selection" | xargs -0 -I{} cat {} > "${file}.out"
cat "$selection" | sort -z | xargs -0 -i cat {} > "$file"
fi fi
elif [ "$resp" = "s" ]; then elif [ "$resp" = "s" ]; then
if ! [ -z "$1" ] && [ -f "$1" ] ; then if [ -n "$1" ] && [ -f "$1" ]; then
# a single file is passed # a single file is passed
echo -n "split size in MB: " echo -n "split size in MB: "
read size read size
if ! [ -z "$size" ]; then if [ -n "$size" ]; then
split -d -b "$size"M "$1" "$1" split -d -b "$size"M "$1" "$1"
fi fi
fi fi