commit 0a8927ff09e121a46434b45a427fea896dd4422b
parent 1afef3939f479adc1e738438ad478427963acbab
Author: St John Karp <contact@stjo.hn>
Date: Sat, 26 Nov 2022 08:25:23 -0500
Implement the ls command
Implement the ls command. `tree` isn't a POSIX utility so I'm just
using `find`. If no command is specified, it will default to `show`
if the password file exists, and `ls` if it doesn't.
Diffstat:
M | balrog | | | 20 | ++++++++++++++++++++ |
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/balrog b/balrog
@@ -27,6 +27,10 @@ case "$1" in
ACTION='generate'
shift
;;
+ ls)
+ ACTION='ls'
+ shift
+ ;;
otp)
OTP=1
shift
@@ -35,6 +39,9 @@ case "$1" in
ACTION='show'
shift
;;
+ *)
+ ACTION='ls'
+ ;;
esac
# Loop through all the arguments and set flags/options.
@@ -125,6 +132,19 @@ while [ -n "$ACTION" ] ; do
# Fall through to the "show" logic.
ACTION='show'
;;
+ ls)
+ if [ -e "$KEY_FILE" ] ; then
+ # Show the password if the key file exists.
+ ACTION='show'
+ else
+ # Otherwise find all files in the path specified.
+ # `tree` is not a POSIX utility so I'm just using `find` here.
+ find "$STORE/$KEY" -type f |
+ sed "s|$STORE/||"
+ ACTION=''
+ fi
+
+ ;;
show)
# Decrypt, extract the secret from the otpauth line, and pass it to oathtool.
if [ "$OTP" -eq 1 ] ; then