diff --git a/gpgtool b/gpgtool index 1e30589..945c361 100755 --- a/gpgtool +++ b/gpgtool @@ -80,6 +80,8 @@ EOF echo -n "${tempdir}" > /tmp/gpgtool.tempdir echo "GPGtool initialized. Temporary working directory: ${tempdir}, key path ${keypath}." + echo "" + echo "Try \`${0} list\` next." } # Cleans up GPGtool. Clears the temp directory and closes the mounted volume. @@ -88,9 +90,9 @@ clear () { [[ ! -f "${_tempdir}" ]] && echo "GPGtool not currently initialized, aborting …" && exit 1 local tempdir="$(cat /tmp/gpgtool.tempdir)" + source "${tempdir}/env" # Unmount device: - source "${tempdir}/env" if [[ ! -z "${mountdev}" ]]; then echo "Unmounting ${mountdev} …" udisksctl unmount -b "${mountdev}" @@ -107,6 +109,35 @@ clear () { rm -f "${_tempdir}" } +# Lists all keys stored in the key path. +list () { + # Abort if not currently initialized: + [[ ! -f "${_tempdir}" ]] && echo "GPGtool not currently initialized, aborting …" && exit 1 + + local tempdir="$(cat /tmp/gpgtool.tempdir)" + source "${tempdir}/env" + + # Abort if no keys found: + [[ -z "$(ls ${keypath})" ]] && + echo "No keys found in key path. Try \`gpgtool create\`" && exit 0 + + echo -e "Key Fingerprint\t\t\t\t\tDescription" + perl -E 'say "-" x 82' + for key in $(ls ${keypath} | sort -k 1.9 | grep -v old) + do + echo -e "${key}\t$(cat ${keypath}/${key}/info)" + done + echo + + if [[ -z "$(ls -l ${_pkdir} | grep ^l)" ]] + then + echo "No open keys. Try \`gpgtool open FINGERPRINT\`." + else + echo "Currently Opened Keys:" + ls -l ${_pkdir} | grep ^l | awk {'print $NF'} + fi +} + # Prints usage information. usage () { echo FIXXME @@ -132,7 +163,7 @@ for dir in "$(dirname $0)" "${HOME}/.config/gpgtool" "${XDG_CONFIG_HOME}"; do done # Handle Subcommands: -[[ "$(type -w $1)" =~ "(.+\s+)?function" ]] \ +[[ "$(type -w $1)" =~ "(.+\s+)?function" && ! "$1" =~ "_.*" ]] \ && $@ \ || echo "Invalid command: $1. See \`$0 --help\`." >&2 && exit 64 @@ -227,21 +258,3 @@ send () { gpg --send-keys --keyserver hkps://keyserver.ubuntu.com ${id} done } - -# gpgtools list -list () { - echo -e "Key ID\t\tDescription" - perl -E 'say "-" x 40' - for key in $(ls ${_dir} | sort -k 1.9 | grep -v old) - do - echo -e "${key:0:8}\t${key:9}" - done - echo - if [ -z "$(ls -l ${_pkdir} | grep ^l)" ] - then - echo "No open keys." - else - echo "Currently Opened Keys:" - ls -l ${_pkdir} | grep ^l | awk {'print $NF'} - fi -}