dotfiles/.config/scripts/otp.sh

48 lines
1.3 KiB
Bash
Raw Normal View History

2025-08-20 05:22:01 -05:00
#!/bin/bash
YUBIKEY_5C_IDENTIFIER="28854922"
YUBIKEY_NANO_IDENTIFIER="33923085"
YUBIKEY_SERIAL=$(ykman list | sed -n 's/.*Serial: //p')
# Check for connected YubiKeys
if echo "$YUBIKEY_SERIAL" | grep -q "$YUBIKEY_5C_IDENTIFIER"; then
YUBIKEY_SERIAL=$YUBIKEY_5C_IDENTIFIER
elif echo "$YUBIKEY_SERIAL" | grep -q "$YUBIKEY_NANO_IDENTIFIER"; then
YUBIKEY_SERIAL=$YUBIKEY_NANO_IDENTIFIER
else
echo "No YubiKey detected!"
exit 1
fi
# Prompt for the password using zenity
password=$(zenity --password --title="Password Required" --text="Enter your password:")
# Check if the user pressed Cancel
if [ $? -ne 0 ]; then
echo "Password dialog was cancelled."
exit 1
fi
2025-08-24 07:41:17 -05:00
accounts=$(ykman -d $YUBIKEY_SERIAL oath accounts list -p $password | sort -f)
2025-08-20 05:22:01 -05:00
# Create an array to hold the keys
declare -a keys
# Read the input line by line
while IFS= read -r line; do
# Extract the part before the colon and store it in the array
key="${line%%:*}"
keys+=("$key")
done <<<"$accounts"
2026-01-06 15:36:54 -06:00
selection=$(printf "%s\n" "${keys[@]}" | wofi --dmenu -i -p "New Session" --columns 1)
2025-08-20 05:22:01 -05:00
2025-08-24 07:41:17 -05:00
if [[ $selection == "" ]]; then
echo "Selection dialog was cancelled."
exit 1
fi
2025-08-20 05:22:01 -05:00
ykman -d $YUBIKEY_SERIAL oath accounts code $selection -p $password | cut -d' ' -f3 | wl-copy
2025-08-24 07:41:17 -05:00
2025-09-27 07:13:57 -05:00
notify-send "copied $selection to Clipboard" -t 5000