Commit 68878b3aaff0
Changed files (1)
pkgs
my
scripts
bin
pkgs/my/scripts/bin/yubikey-oath
@@ -3,30 +3,34 @@
set -euo pipefail
-# Check if fuzzel is available
-if ! command -v fuzzel &> /dev/null; then
- echo "Error: fuzzel not found" >&2
+# List all OATH accounts from YubiKey
+accounts=$(ykman oath accounts list 2>&1)
+exit_code=$?
+
+# Check if ykman failed
+if [ $exit_code -ne 0 ]; then
+ notify-send "YubiKey OATH" "Failed to connect to YubiKey. Make sure it's plugged in." --urgency=critical
exit 1
fi
-# Check if ykman is available
-if ! command -v ykman &> /dev/null; then
- echo "Error: ykman not found" >&2
- exit 1
+# Check if there are any accounts
+if [ -z "$accounts" ]; then
+ notify-send "YubiKey OATH" "No OATH accounts found on YubiKey" --urgency=normal
+ exit 0
fi
-# List all OATH accounts and let user select one with fuzzel
-selected=$(ykman oath accounts list 2>/dev/null | fuzzel --dmenu --prompt "OATH: " --lines 10 --width 40)
+# Let user select an account with fuzzel
+selected=$(echo "$accounts" | fuzzel --dmenu --prompt "OATH: " --lines 10 --width 40)
if [ -z "$selected" ]; then
exit 0
fi
# Get the code for the selected account
-code=$(ykman oath accounts code --single "$selected" 2>/dev/null | awk '{print $NF}')
+code=$(ykman oath accounts code --single "$selected" 2>&1 | awk '{print $NF}')
if [ -z "$code" ]; then
- notify-send "YubiKey OATH" "Failed to get code" --urgency=critical
+ notify-send "YubiKey OATH" "Failed to get code for $selected" --urgency=critical
exit 1
fi