···11#!/usr/bin/env bash
2233+# Workaround in cases where XDG_RUNTIME_DIR is undefined on login
44+if [[ ! -n "${XDG_RUNTIME_DIR}" ]]; then
55+ echo "warning: XDG_RUNTIME_DIR is possibly undefined, see https://github.com/swaywm/sway/issues/7202"
66+ echo "warning: for context and https://wiki.archlinux.org/title/XDG_Base_Directory for docs"
77+ echo "warning: setting it up for you using the default '/run/user/$(id -u)' value in 3s..."
88+ sleep 3
99+ export XDG_RUNTIME_DIR="/run/user/$(id -u)"
1010+fi
1111+312# do feature detection if keychain is installed
413if command -v keychain >> /dev/null; then
514 FF_KEYCHAIN=1
···1726 fi
1827}
19282929+# Ripped off NixOS-generated set-environment on my laptop for yubikey-agent setup
3030+try_yubikey_agent() {
3131+ if [[ -f "${XDG_RUNTIME_DIR}/yubikey-agent/yubikey-agent.sock" ]]; then
3232+ echo "[ssh-agent-loader::yubikey-agent] using YubiKey SSH Agent"
3333+ export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/yubikey-agent/yubikey-agent.sock"
3434+ fi
3535+}
3636+2037try_1password_ssh_agent() {
2138 export OP_SSH_AUTH_SOCK="$HOME/.1password/agent.sock"
2239 if [[ ! -S "$OP_SSH_AUTH_SOCK" ]]; then
···4865 return
4966 elif try_keychain_ssh_agent; then
5067 return
6868+ elif try_yubikey_agent; then
6969+ return
5170 else
5271 echo "[ssh-agent-loader] SSH agent seems to be failed to load at the moment"
5372 echo "[ssh-agent-loader] try again later by manually invoking the shell function"
···5877 try_1password_ssh_agent
5978 elif [[ $1 == "keychain" ]]; then
6079 try_keychain_ssh_agent
8080+ elif [[ $1 == "yubikey" ]]; then
8181+ try_yubikey_agent
6182 else
6262- echo "ssh-agent-loader [auto|[1password|op|1p]|keychain]"
8383+ echo "ssh-agent-loader [auto|[1password|op|1p]|keychain|yubikey]"
6384 return 1
6485 fi
6586}
66878888+# automatically detect things as we source this
6789ssh-agent-loader auto