From c2f45d5661a1c1e35bab09d5898c8e56c9948562 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 8 Apr 2022 22:26:12 +0200 Subject: [PATCH] Improve ssh-sign function Add -h option, don't require argument --- .config/zsh/completions/_ssh-sign | 6 +++++- .config/zsh/functions/ssh-sign | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) mode change 100644 => 100755 .config/zsh/functions/ssh-sign diff --git a/.config/zsh/completions/_ssh-sign b/.config/zsh/completions/_ssh-sign index 8406e5f..f79a3fd 100644 --- a/.config/zsh/completions/_ssh-sign +++ b/.config/zsh/completions/_ssh-sign @@ -1,9 +1,13 @@ #compdef ssh-sign -_arguments '-f[keyfile]:filename:_files' '-n[namespace]:namespace:_ssh-sign_namespaces' '*:file:_files' +_arguments '-f[key file]:filename:_files' '-n[namespace]:namespace:_ssh-sign_namespaces' '*:file:_files' '-h[short help text]' function _ssh-sign_namespaces() { local -a namespaces=(file email git "@$(dnsdomainname)") _values "namespace" ${namespaces} } + +# Local Variables: +# mode: shell-script +# End: diff --git a/.config/zsh/functions/ssh-sign b/.config/zsh/functions/ssh-sign old mode 100644 new mode 100755 index e0c6ac4..b2205ac --- a/.config/zsh/functions/ssh-sign +++ b/.config/zsh/functions/ssh-sign @@ -4,11 +4,15 @@ setopt LOCAL_OPTIONS ERR_RETURN NO_UNSET PIPE_FAIL autoload -U die -[[ ${ARGC} -eq 0 ]] && die 1 "Usage: ${0} [-f KEYFILE] [-n NAMESPACE] …" zmodload zsh/zutil local -a keyfile=(-f ~/.ssh/id_ed25519) local -a namespace=(-n file) -zparseopts -D -K -- f:=keyfile n:=namespace +local -a help=() +zparseopts -D -K -- f:=keyfile n:=namespace h=help +if [[ ${#help} -ne 0 ]]; then + print "Usage: ${0} [-h] [-f KEYFILE] [-n NAMESPACE] …" + return 0 +fi ssh-keygen -Y sign -f ${keyfile[2]} -n ${namespace[2]} ${@}