main
 1#!/usr/bin/env bash
 2# Copy the OATH code for the given account from the YubiKey to clipboard.
 3# Usage: yubikey-oath-copy <account>
 4set -euo pipefail
 5
 6account="${1:-}"
 7[[ -z "$account" ]] && exit 0
 8
 9if ! code=$(ykman oath accounts code --single "$account" 2>/dev/null | grep -oE '[0-9]{6,8}'); then
10    notify-send "YubiKey OATH" "Failed to get code for $account" --urgency=critical
11    exit 1
12fi
13
14if [[ -z "$code" ]]; then
15    notify-send "YubiKey OATH" "Failed to get code for $account" --urgency=critical
16    exit 1
17fi
18
19printf '%s' "$code" | pbcopy
20notify-send "YubiKey OATH" "Code for $account copied to clipboard" --urgency=normal