Commit edb48c546180
Changed files (3)
dots
config
raffi
dots/config/raffi/scripts/yubikey-oath-copy
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+# Copy the OATH code for the given account from the YubiKey to clipboard.
+# Usage: yubikey-oath-copy <account>
+set -euo pipefail
+
+account="${1:-}"
+[[ -z "$account" ]] && exit 0
+
+if ! code=$(ykman oath accounts code --single "$account" 2>/dev/null | grep -oE '[0-9]{6,8}'); then
+ notify-send "YubiKey OATH" "Failed to get code for $account" --urgency=critical
+ exit 1
+fi
+
+if [[ -z "$code" ]]; then
+ notify-send "YubiKey OATH" "Failed to get code for $account" --urgency=critical
+ exit 1
+fi
+
+printf '%s' "$code" | pbcopy
+notify-send "YubiKey OATH" "Code for $account copied to clipboard" --urgency=normal
dots/config/raffi/scripts/yubikey-oath-raffi
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+# List YubiKey OATH accounts for raffi script filter.
+# Outputs Alfred Script Filter JSON format.
+# The selected account name is copied/coded by the raffi action.
+# Usage: yubikey-oath-raffi [query]
+set -euo pipefail
+
+query="${1:-}"
+
+if ! accounts=$(ykman oath accounts list 2>/dev/null); then
+ jq -n '{"items": [{"title": "YubiKey error", "subtitle": "Failed to connect to YubiKey — is it plugged in?", "valid": false}]}'
+ exit 0
+fi
+
+if [[ -z "$accounts" ]]; then
+ jq -n '{"items": [{"title": "No accounts", "subtitle": "No OATH accounts found on YubiKey", "valid": false}]}'
+ exit 0
+fi
+
+items="[]"
+while IFS= read -r account; do
+ [[ -z "$account" ]] && continue
+ if [[ -n "$query" ]] && ! echo "$account" | grep -qi "$query"; then
+ continue
+ fi
+ items=$(jq --arg a "$account" \
+ '. + [{"title": $a, "subtitle": "Copy OATH code for \($a)", "arg": $a}]' <<< "$items")
+done <<< "$accounts"
+
+jq -n --argjson items "$items" '{"items": $items}'
dots/config/raffi/raffi.yaml
@@ -101,6 +101,11 @@ addons:
keyword: uid
command: ~/.config/raffi/scripts/uid-raffi
icon: clock
+ - name: YubiKey OATH
+ keyword: otp
+ command: ~/.config/raffi/scripts/yubikey-oath-raffi
+ icon: security-high
+ action: ~/.config/raffi/scripts/yubikey-oath-copy {value}
- name: GitHub Pull Requests
keyword: pr
command: ~/.config/raffi/scripts/pr-raffi
@@ -379,7 +384,3 @@ launchers:
description: Disconnect Red Hat VPN
icon: network-vpn
ifexist: redhat-vpn-disconnect
- yubikey-oath:
- binary: yubikey-oath
- description: YubiKey OATH Codes
- icon: security-high