diff options
| author | Щанников Михаил <79425045+mikhailde@users.noreply.github.com> | 2024-10-10 14:39:07 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-10 13:39:07 +0200 |
| commit | d2d5155d41cbe183ef172fef1e83a29d116a5af6 (patch) | |
| tree | 55f6d567896572cf83d970df38edb4ec96333dc2 /plugins/ssh-agent/ssh-agent.plugin.zsh | |
| parent | 61bacd95b285a9792a05d1c818d9cee15ebe53c6 (diff) | |
| download | zsh-d2d5155d41cbe183ef172fef1e83a29d116a5af6.tar.gz zsh-d2d5155d41cbe183ef172fef1e83a29d116a5af6.tar.bz2 zsh-d2d5155d41cbe183ef172fef1e83a29d116a5af6.zip | |
feat(ssh-agent): add keys regardless of filename (#12741)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Diffstat (limited to 'plugins/ssh-agent/ssh-agent.plugin.zsh')
| -rw-r--r-- | plugins/ssh-agent/ssh-agent.plugin.zsh | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh index 83548648b..becd5ea17 100644 --- a/plugins/ssh-agent/ssh-agent.plugin.zsh +++ b/plugins/ssh-agent/ssh-agent.plugin.zsh @@ -39,13 +39,16 @@ function _add_identities() { return fi - # add default keys if no identities were set up via zstyle - # this is to mimic the call to ssh-add with no identities - if [[ ${#identities} -eq 0 ]]; then - # key list found on `ssh-add` man page's DESCRIPTION section - for id in id_rsa id_dsa id_ecdsa id_ed25519 id_ed25519_sk identity; do - # check if file exists - [[ -f "$HOME/.ssh/$id" ]] && identities+=($id) + # If no keys specified in zstyle, add default keys. + # Mimics calling ssh-add with no arguments. + if [[ ${#identities[@]} -eq 0 ]]; then + # Iterate over files in .ssh folder. + for file in "$HOME/.ssh"/*; do + # Check if file is a regular file and starts with "-----BEGIN OPENSSH PRIVATE KEY-----". + if [[ -f "$file" && $(command head -n 1 "$file") =~ ^-----BEGIN\ OPENSSH\ PRIVATE\ KEY----- ]]; then + # Add filename (without path) to identities array. + identities+=("${file##*/}") + fi done fi |
