From 20990ef9706ecacaaf6a7fc82b85663832bb03ab Mon Sep 17 00:00:00 2001 From: Gu1llaum-3 Date: Sat, 15 Mar 2025 15:42:20 +0100 Subject: [PATCH] Detect default SSH key automatically in sshm_add() --- sshm.bash | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sshm.bash b/sshm.bash index 03d5c3c..2fb3e93 100755 --- a/sshm.bash +++ b/sshm.bash @@ -162,7 +162,9 @@ sshm_add() { local port local identity_file - # Request necessary information + default_identity_file=$(find ~/.ssh -maxdepth 1 -type f \( -name "id_rsa" -o -name "id_ed25519" -o -name "id_ecdsa" -o -name "id_dsa" \) | head -n 1) + default_identity_file=${default_identity_file:-~/.ssh/id_rsa} + if [[ -z "$host" ]]; then read -p "Enter host name: " host if [[ -z "$host" ]]; then @@ -183,10 +185,9 @@ sshm_add() { read -p "Enter SSH port (default: 22): " port port=${port:-22} - read -p "Enter path to SSH key (default: ~/.ssh/id_rsa): " identity_file - identity_file=${identity_file:-~/.ssh/id_rsa} + read -p "Enter path to SSH key (default: $default_identity_file): " identity_file + identity_file=${identity_file:-$default_identity_file} - # Add the new configuration to the file { echo "" echo "Host $host" @@ -195,7 +196,7 @@ sshm_add() { if [[ "$port" -ne 22 ]]; then echo " Port $port" fi - if [[ "$identity_file" != ~/.ssh/id_rsa ]]; then + if [[ "$identity_file" != "$default_identity_file" ]]; then echo " IdentityFile $identity_file" fi } >> "$config_file"