Commit 68878b3aaff0

Vincent Demeester <vincent@sbr.pm>
2026-01-15 10:18:50
fix(yubikey-oath): improve error handling and show helpful notifications
- Capture ykman errors instead of suppressing with 2>/dev/null - Show notification if YubiKey can't be connected - Show notification if no accounts found - Better error messages for debugging This fixes the issue where fuzzel would show an empty list if the YubiKey wasn't ready.
1 parent 44fb2b7
Changed files (1)
pkgs
my
scripts
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