From 1f93e5f7c8cf384803690891232ddd5be0720962 Mon Sep 17 00:00:00 2001 From: Solninja A Date: Wed, 1 Jan 2025 16:33:34 +1000 Subject: [PATCH] First commit --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++-- rofi-yubikey.sh | 20 ++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100755 rofi-yubikey.sh diff --git a/README.md b/README.md index 8202777..854767c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,55 @@ -# rofi-yubikey +# Rofi-YubiKey -A no-bloat script for getting OATH codes from a YubiKey. \ No newline at end of file +A no-bloat script for getting OATH codes from a YubiKey. + +# Usage +Either only download `rofi-yubikey.sh`, or clone the entire repository (`git clone https://git.solomon.tech/solomon/rofi-yubikey.git`). + +Once you have the script on your computer, move it to wherever you desire. I personally use, and recommend `~/.local/bin/rofi-yubikey.sh`. + +After that, simply execute the script. For example, if you placed the script in `~/.local/bin/rofi-yubikey.sh`, you could run any of the below commands: +- `sh ~/.local/bin/rofi-yubikey.sh` +- `bash ~/.local/bin/rofi-yubikey.sh` +- `~/.local/bin/rofi-yubikey.sh` +(only pick one!) + +# Integration with Window Managers +**Note: I will only be documenting XMonad, because I cannot guarantee the validity of my advice regarding different window managers.** + +If you are using XMonad, you likely already know how to set custom keybinds. Simply make a keybind run the script. +However, if you are unfamiliar, this is how I do it: + +1. Import `EZConfig`: +Import the following: +``` haskell +import XMonad.Util.EZConfig +``` + +2. Add `additionalKeysP` to your defaults variable. +``` haskell +defaults = def { + -- REST OF CONFIG HERE + } `additionalKeysP` myAddKeys +``` + +2.a. Make sure `defaults` is being used +Add `defaults` to `main = ...` +For example: + +``` haskell +main :: IO() +main = xmonad . $ defaults +``` + +3. Define `myAddKeys` + +``` haskell +-- Add custom keys +myAddKeys = + -- This firefox keybinding is here to show you how to add multiple keybindings + [ ("M-b", spawn "firefox") + , ("M-", spawn "/home/USERNAME/.local/bin/rofi-yubikey.sh") + ] +``` + +*PR requests are open if anyone would like to add documentation for other window managers, etc* diff --git a/rofi-yubikey.sh b/rofi-yubikey.sh new file mode 100755 index 0000000..49882e1 --- /dev/null +++ b/rofi-yubikey.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Get full list of account codes +output=$(/usr/bin/ykman oath accounts code) + +# Get account names +accounts=$(echo "$output" | awk 'BEGIN{FS=OFS=" "}{$NF=""; NF--; print}') + +# Get selected +selected=$(echo "$accounts"| \ + rofi -no-show-icons -dmenu -i -p "YubiKey OATH Codes"); + +# If the user selects an entry +if [[ ! -z $selected ]]; then + # Copy code to the user's clipboard + echo "$output" | grep "$selected" | awk '{print $NF}' | xclip -selection clipboard; +fi + +# Exit Rofi +exit 0