aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/rofi/.local/bin/rofi-ykman
blob: 3d4ca99039ad44da3b5dff85d21b1d79ad9f56f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash

# rofi-ykman
# Yubikey oath utility

#2019 nukeop

if [ ! "$(ykman info)" ]; then
	notify-send "rofi-ykman" "Yubikey not detected." -a "rofi-ykman"
	exit 1
fi

OPTIONS=$(ykman oath accounts list)
LAUNCHER="rofi -dmenu -i -p YubikeyOATH"

option=$(echo "${OPTIONS/, TOTP/\n}" | $LAUNCHER)
code=$(ykman oath accounts code "$option")
IFS=', ' read -r -a code <<<"$code"
if [ "$XDG_SESSION_TYPE" == "wayland" ]; then
	cliptool=wl-copy
	typer="wtype -"
else
	cliptool="xclip -selection clipboard"
	typer="xargs xdotool type"
fi
if [ "$1" == "type" ]; then
	action=$typer
else
	action=$cliptool
fi

notify-send "rofi-ykman" "Touch Yubikey..." -a "rofi-ykman"
echo "${code[-1]}" | $action