gpge (1340B)
1 #!/usr/bin/env sh 2 3 # Description: Encrypts selected files using gpg. Can encrypt 4 # asymmetrically (key) or symmetrically (passphrase). 5 # If asymmetric encryption is chosen a key can be 6 # chosen from the list of capable public keys using fzf. 7 # 8 # Note: Symmetric encryption only works for a single (current) file as per gpg limitations 9 # 10 # Shell: POSIX compliant 11 # Author: KlzXS 12 13 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} 14 15 printf "(s)ymmetric, (a)symmetric? [default=a] " 16 read -r symmetry 17 18 if [ "$symmetry" = "s" ]; then 19 gpg --symmetric "$1" 20 else 21 printf "(s)election/(c)urrent? [default=c] " 22 read -r resp 23 24 if [ "$resp" = "s" ]; then 25 files=$(tr '\0' '\n' < "$selection") 26 else 27 files=$1 28 fi 29 30 keyids=$(gpg --list-public-keys --with-colons | grep -E "pub:(.*:){10}.*[eE].*:" | awk -F ":" '{print $5}') 31 32 #awk needs literal $10 33 #shellcheck disable=SC2016 34 keyuids=$(printf "%s" "$keyids" | xargs -n1 -I{} sh -c 'gpg --list-key --with-colons "{}" | grep "uid" | awk -F ":" '\''{printf "%s %s\n", "{}", $10}'\''') 35 36 recipient=$(printf "%s" "$keyuids" | fzf | awk '{print $1}') 37 38 printf "%s" "$files" | xargs -n1 gpg --encrypt --recipient "$recipient" 39 40 # Clear selection 41 if [ "$resp" = "s" ] && [ -p "$NNN_PIPE" ]; then 42 printf "-" > "$NNN_PIPE" 43 fi 44 fi