From 59ef4d56d50d0749426865ecf112d3170e671cd8 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Mon, 26 Oct 2020 10:22:36 +0100 Subject: [PATCH] Move ssh and gpg from aliases to functions --- zshrc | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/zshrc b/zshrc index 230f58e..a68338f 100644 --- a/zshrc +++ b/zshrc @@ -310,11 +310,31 @@ alias ping6="ping6 -c 3" ## JOSM alias josm="java -jar -Xmx2048M /opt/josm-tested.jar" -## Keychain -# For SSH: If keychain doesn't exist, load it then source the file-sh -alias ssh="[[ ! -f ~/.keychain/$HOST-sh ]] && keychain --agents ssh id_rsa; source ~/.keychain/$HOST-sh; ssh " -# For GPG: If keychain doesn't exist, load it then source the file-sh-gpg -alias gpg="[[ ! -f ~/.keychain/$HOST-sh-gpg ]] && keychain --noask --systemd --agents gpg; source ~/.keychain/$HOST-sh-gpg; gpg " +# Keychain +## For SSH {{{ +function ssh() { + ## If keychain exists, run ssh from default $PATH as usual + if [ -f ~/.keychain/"${HOST}"-sh ]; then + command -p ssh "${*}" + else ## Otherwise, reload keychain and run ssh + keychain --agents ssh + source ~/.keychain/"${HOST}"-sh + command -p ssh "${*}" + fi +} +## }}} +## For GPG {{{ +function gpg() { + ## If keychain exists, run gpg from default $PATH as usual + if [ -f ~/.keychain/"${HOST}"-sh-gpg ]; then + command -p gpg ${*} + else ## Otherwise, reload keychain and run gpg + keychain --agents gpg + source ~/.keychain/"${HOST}"-sh-gpg + command -p gpg ${*} + fi +} +## }}} # ssh alias sshdev='ssh -o UserKnownHostsFile=/dev/null'