2024-11-26 09:44:43 +00:00
|
|
|
#!/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
|
|
|
|
|
2024-11-26 13:59:10 +00:00
|
|
|
file=$1
|
2024-11-26 09:44:43 +00:00
|
|
|
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
|
|
|
|
|
2024-11-26 13:59:10 +00:00
|
|
|
getfiles(){
|
|
|
|
if [ "$file_resp" = "s" ]; then
|
|
|
|
cat "$selection"
|
|
|
|
else
|
|
|
|
printf "%s\0" "$file"
|
|
|
|
fi
|
|
|
|
}
|
2024-11-26 09:44:43 +00:00
|
|
|
|
|
|
|
if [ "$sig_resp" = "c" ]; then
|
2024-11-26 13:59:10 +00:00
|
|
|
getfiles | xargs -0 -I{} gpg --clearsign {}
|
2024-11-26 09:44:43 +00:00
|
|
|
elif [ "$sig_resp" = "d" ]; then
|
2024-11-26 13:59:10 +00:00
|
|
|
getfiles | xargs -0 -I{} gpg --detach-sig --output "{}.sig"
|
2024-11-26 09:44:43 +00:00
|
|
|
else
|
2024-11-26 13:59:10 +00:00
|
|
|
getfiles | xargs -0 -I{} gpg --sign --output "{}.sig" {}
|
2024-11-26 09:44:43 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Clear selection
|
|
|
|
if [ "$file_resp" = "s" ] && [ -p "$NNN_PIPE" ]; then
|
|
|
|
printf "-" > "$NNN_PIPE"
|
|
|
|
fi
|