mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-29 04:53:17 +02:00
Merge 2c5d15c01a into 62b8a70a7c
This commit is contained in:
commit
d841746166
4 changed files with 311 additions and 0 deletions
22
plugins/yubikey/README.md
Normal file
22
plugins/yubikey/README.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# YubiKey Plugin
|
||||
|
||||
YubiKey plugin -- Provides aliases to help use YubiKey tokens comfortably
|
||||
|
||||
## Usage
|
||||
|
||||
This plugin will first try to detect location of the 'opensc-pkcs11.so' library, unless already specified in the $OPENSC env var.
|
||||
|
||||
Afterwards, it will try to detect if a 'shared ssh-agent' is already running, through a file in /run (preferred, but must be pre-created with the proper permissions), or in /tmp (fallback).
|
||||
|
||||
Then it will define several aliases.
|
||||
|
||||
## Optional Parameters
|
||||
|
||||
These parameters can be set before source-ing oh-my-zsh to customize the settings:
|
||||
|
||||
`YUBI_SHOWKEYS`
|
||||
> If set to '1' or 'y' or 'yes', will list the keys contained in the 'shared ssh-agent'
|
||||
|
||||
`YUBI_SSHAGENT_AUTOINIT`
|
||||
> If set to '1' or 'y' or 'yes', will automatically initialize the 'shared ssh-agent' if one is not found
|
||||
|
||||
59
plugins/yubikey/yubikey.plugin.zsh
Normal file
59
plugins/yubikey/yubikey.plugin.zsh
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
|
||||
local _libname='opensc-pkcs11.so'
|
||||
local _sshfiledir="/run/user/$UID"
|
||||
local _sshfile='ssh_agent'
|
||||
local _sshpath=''
|
||||
local _ellipsis='......'
|
||||
|
||||
if [[ -z $OPENSC ]]; then
|
||||
for f in $(locate "/${_libname}"); do
|
||||
[[ -L $f ]] && continue # Is a sublink
|
||||
OPENSC="$f"
|
||||
break
|
||||
done
|
||||
fi
|
||||
export OPENSC
|
||||
|
||||
if [[ -w $_sshfiledir ]]; then
|
||||
_sshpath="$_sshfiledir/$_sshfile"
|
||||
else
|
||||
_sshpath="/tmp/$_sshfile"
|
||||
fi
|
||||
|
||||
|
||||
alias yubi-init="pkill ssh-agent; pkill gpg-agent; ssh-agent -s > $_sshpath; source $_sshpath"
|
||||
alias yubi-insert="ssh-add -s $OPENSC && ssh-add -L"
|
||||
alias yubi-eject="ssh-add -e $OPENSC && ssh-add -L"
|
||||
|
||||
if [[ -r $_sshpath ]]; then
|
||||
echo -n "Common SSH Agent detected. "
|
||||
source $_sshpath
|
||||
else
|
||||
echo -n "Common SSH Agent not detected. "
|
||||
case "${(U)YUBI_SSHAGENT_AUTOINIT}" in
|
||||
1|Y|YES)
|
||||
echo -n "Auto-initializing... "
|
||||
yubi-init
|
||||
echo "done."
|
||||
;;
|
||||
*)
|
||||
echo "Autoinit not enabled. Use 'yubi-init' to manually init."
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
case "${(U)YUBI_SHOWKEYS}" in
|
||||
1|Y|YES)
|
||||
ssh-add -L | while read ln; do
|
||||
if (( ${#ln} >= COLUMNS )); then
|
||||
newlen=$(( COLUMNS - ${#_ellipsis} - 1 ))
|
||||
halflen=$(( newlen / 2 ))
|
||||
ln="${ln:0:$halflen}${_ellipsis}${ln: -$halflen}"
|
||||
fi
|
||||
echo "$ln"
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
||||
# vim: set ft=zsh ts=4 sts=4 et ai :
|
||||
Loading…
Add table
Add a link
Reference in a new issue