ssh-agent: add default keys if no zstyle identities were set (#7520)
Diff
1diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh
2index 1cc5630e1428d52638b7d18a1d87c01de3f3da75..0a204309e303886af9e831be40406a9c46acb2d7 100644
3--- a/plugins/ssh-agent/ssh-agent.plugin.zsh
4+++ b/plugins/ssh-agent/ssh-agent.plugin.zsh
5@@ -21,6 +21,16 @@ function _add_identities() {
6 return
7 fi
8 9+ # add default keys if no identities were set up via zstyle
10+ # this is to mimic the call to ssh-add with no identities
11+ if [[ ${#identities} -eq 0 ]]; then
12+ # key list found on `ssh-add` man page's DESCRIPTION section
13+ for id in id_rsa id_dsa id_ecdsa id_ed25519 identity; do
14+ # check if file exists
15+ [[ -f "$HOME/.ssh/$id" ]] && identities+=$id
16+ done
17+ fi
18+
19 # get list of loaded identities' signatures
20 for line in ${(f)"$(ssh-add -l)"}; do loaded+=${${(z)line}[2]}; done
2122@@ -36,7 +46,7 @@ function _add_identities() {
23 [[ ${loaded[(I)$sig]} -le 0 ]] && not_loaded+="$HOME/.ssh/$id"
24 done
2526- if [[ -n "$not_loaded" ]] && ssh-add ${^not_loaded}
27+ [[ -n "$not_loaded" ]] && ssh-add ${^not_loaded}
28 }
2930 # Get the filename to store/lookup the environment from