From 1e1abdfb31d5df93e1304fb9e388742fa129548f Mon Sep 17 00:00:00 2001 From: "supritsj@Arch" Date: Tue, 26 Nov 2024 15:14:43 +0530 Subject: [PATCH 1/2] added plugins gpgs and gpgv --- plugins/README.md | 2 ++ plugins/gpgs | 39 +++++++++++++++++++++++++++++++++++++++ plugins/gpgv | 28 ++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100755 plugins/gpgs create mode 100755 plugins/gpgv diff --git a/plugins/README.md b/plugins/README.md index 377071dd..8201028b 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -33,6 +33,8 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | [getplugs](getplugs) | Update plugins to installed `nnn` version | sh | curl | | [gitroot](gitroot) | Cd to the root of current git repo | sh | git | | [gpge](gpge) | Encrypt/decrypt files using GPG [✓] | sh | gpg | +| [gpgs](gpgs) | Digitally sign files using GPG [✓] | sh | gpg | +| [gpgv](gpgv) | Verify signature files using GPG [✓] | sh | gpg | | [gutenread](gutenread) | Browse, download, read from Project Gutenberg | sh | curl, unzip, w3m
[epr](https://github.com/wustho/epr) (optional) | | [gsconnect](gsconnect) | GNOME's implementation of kdeconnect [✓] | sh | gsconnect | | [imgresize](imgresize) | Batch resize images in dir to screen resolution | sh | [imgp](https://github.com/jarun/imgp) | diff --git a/plugins/gpgs b/plugins/gpgs new file mode 100755 index 00000000..16e1750a --- /dev/null +++ b/plugins/gpgs @@ -0,0 +1,39 @@ +#!/usr/bin/env sh + +# Description: signs selected files using gpg. +# includes options for clearsigning and +# detached signing documents as well +# +# signed and detach signed files are stored with extension .sig +# whereas clearsigned one are stored as .asc [by default by gpg] +# +# Note: The chosen method of signing is applied to all selected files [if selection is chosen] +# +# Shell: POSIX compliant +# Author: wassup05 + +selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} + +printf "(s)election/(c)urrent? [default=c] " +read -r file_resp +printf "(s)ign/(c)learsign/(d)etach-sig? [default=s] " +read -r sig_resp + +if [ "$file_resp" = "s" ]; then + files=$(tr '\0' '\n' < "$selection") +else + files=$1 +fi + +if [ "$sig_resp" = "c" ]; then + printf "%s" "$files" | xargs -I{} gpg --clearsign {} +elif [ "$sig_resp" = "d" ]; then + printf "%s" "$files" | xargs -I{} gpg --detach-sig --output "{}.sig" +else + printf "%s" "$files" | xargs -I{} gpg --sign --output "{}.sig" {} +fi + +# Clear selection +if [ "$file_resp" = "s" ] && [ -p "$NNN_PIPE" ]; then + printf "-" > "$NNN_PIPE" +fi diff --git a/plugins/gpgv b/plugins/gpgv new file mode 100755 index 00000000..23e52e70 --- /dev/null +++ b/plugins/gpgv @@ -0,0 +1,28 @@ +#!/usr/bin/env sh + +# Description: verifies signed files using gpg. +# includes options for detached signing +# (in which case it asks for a document to verify) +# as well as normal signing +# +# Note: Uses the current file only [selections not supported] +# +# Shell: POSIX compliant +# Author: wassup05 + +file=$1 + +printf "(s)ign/(d)etach-sig [default=s] " +read -r sig_resp + +if [ "$sig_resp" = "d" ]; then + printf "Enter document name: " + read -r doc_name + command gpg --verify "$file" "$doc_name" +else + command gpg --verify "$file" +fi + +printf "\n" +# shellcheck disable=SC2034 +read -r resp # Waiting for input to go back to nnn From 3c4356418238157e80135b41af892c6bcfd2b060 Mon Sep 17 00:00:00 2001 From: "supritsj@Arch" Date: Tue, 26 Nov 2024 19:29:10 +0530 Subject: [PATCH 2/2] use "xarg -0" instead of trim --- plugins/gpgs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/plugins/gpgs b/plugins/gpgs index 16e1750a..3d434c37 100755 --- a/plugins/gpgs +++ b/plugins/gpgs @@ -12,6 +12,7 @@ # Shell: POSIX compliant # Author: wassup05 +file=$1 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} printf "(s)election/(c)urrent? [default=c] " @@ -19,18 +20,20 @@ read -r file_resp printf "(s)ign/(c)learsign/(d)etach-sig? [default=s] " read -r sig_resp -if [ "$file_resp" = "s" ]; then - files=$(tr '\0' '\n' < "$selection") -else - files=$1 -fi +getfiles(){ + if [ "$file_resp" = "s" ]; then + cat "$selection" + else + printf "%s\0" "$file" + fi +} if [ "$sig_resp" = "c" ]; then - printf "%s" "$files" | xargs -I{} gpg --clearsign {} + getfiles | xargs -0 -I{} gpg --clearsign {} elif [ "$sig_resp" = "d" ]; then - printf "%s" "$files" | xargs -I{} gpg --detach-sig --output "{}.sig" + getfiles | xargs -0 -I{} gpg --detach-sig --output "{}.sig" else - printf "%s" "$files" | xargs -I{} gpg --sign --output "{}.sig" {} + getfiles | xargs -0 -I{} gpg --sign --output "{}.sig" {} fi # Clear selection