From 655571296f03087ca57fcb17f7283a31ded974bd Mon Sep 17 00:00:00 2001 From: Guillaume Archambault Date: Fri, 29 Aug 2025 16:11:00 +0200 Subject: [PATCH] Fix duplicate tag lines in sshm edit function --- sshm.bash | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/sshm.bash b/sshm.bash index 0103c35..d412f64 100755 --- a/sshm.bash +++ b/sshm.bash @@ -26,7 +26,7 @@ readonly BLUE='\033[0;34m' readonly BOLD='\033[1m' readonly NC='\033[0m' # No Color -readonly VERSION="3.0.0" +readonly VERSION="3.0.1" readonly CONFIG_DIR="${HOME}/.config/sshm" readonly DEFAULT_CONFIG="${HOME}/.ssh/config" readonly CURRENT_CONTEXT_FILE="${CONFIG_DIR}/.current_context" @@ -723,8 +723,33 @@ sshm_edit() { local tmp_file tmp_file=$(mktemp) - # Delete the old configuration - sed '/^Host '"$host"'$/,/^$/d' "$config_file" > "$tmp_file" + # Delete the old configuration including tags (same logic as sshm_delete) + awk ' + /^# Tags:.*/ { + # Check if next non-empty line is the host we want to edit + tags_line = $0 + while ((getline next_line) > 0) { + if (next_line ~ /^$/) continue + if (next_line ~ /^Host '"$host"'$/) { + # Skip this host block entirely + while ((getline) > 0 && !/^$/) continue + next + } else { + # Not our host, keep the tags line and the next line + print tags_line + print next_line + break + } + } + next + } + /^Host '"$host"'$/ { + # Skip this host block + while ((getline) > 0 && !/^$/) continue + next + } + { print } + ' "$config_file" > "$tmp_file" # Check if the temporary file is not empty if [[ ! -s "$tmp_file" ]]; then