1
0
Fork 0

Improve ssh-sign function

Add -h option, don't require argument
This commit is contained in:
tastytea 2022-04-08 22:26:12 +02:00
parent 151f91fb24
commit c2f45d5661
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 11 additions and 3 deletions

View File

@ -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:

8
.config/zsh/functions/ssh-sign Normal file → Executable file
View File

@ -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] <file> …"
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] <file> …"
return 0
fi
ssh-keygen -Y sign -f ${keyfile[2]} -n ${namespace[2]} ${@}