From 47400ebc285edaf81003eb98e3cac30dd2c1e7dc Mon Sep 17 00:00:00 2001 From: Pandu POLUAN Date: Thu, 28 Dec 2017 12:35:19 +0700 Subject: [PATCH] yubikey-plugin Enhancement * Update the README.md file * Add key listing logic (auto-truncating if too long) * Some output cosmetics --- plugins/yubikey/README.md | 11 +++++++++++ plugins/yubikey/yubikey.plugin.zsh | 22 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/plugins/yubikey/README.md b/plugins/yubikey/README.md index 85066c253..ef8312dd8 100644 --- a/plugins/yubikey/README.md +++ b/plugins/yubikey/README.md @@ -9,3 +9,14 @@ This plugin will first try to detect location of the 'opensc-pkcs11.so' library, 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 + diff --git a/plugins/yubikey/yubikey.plugin.zsh b/plugins/yubikey/yubikey.plugin.zsh index 4c9b5f895..11ccf48a1 100644 --- a/plugins/yubikey/yubikey.plugin.zsh +++ b/plugins/yubikey/yubikey.plugin.zsh @@ -4,6 +4,7 @@ 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 @@ -26,20 +27,33 @@ alias yubi-insert="ssh-add -s $OPENSC" alias yubi-eject="ssh-add -e $OPENSC" if [[ -r $_sshpath ]]; then - echo "Common SSH Agent detected." + echo -n "Common SSH Agent detected. " source $_sshpath else - echo -n "Common SSH Agent not detected." + echo -n "Common SSH Agent not detected. " case "${(U)YUBI_SSHAGENT_AUTOINIT}" in 1|Y|YES) - echo -n " Auto-initializing... " + echo -n "Auto-initializing... " yubi-init echo "done." ;; *) - echo " Autoinit not enabled. Use 'yubi-init' to manually init." + 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 :