#!/bin/bash # SSH menu: the hosts in ~/.ssh/config as cards, rofi themed by udt. # Copyright (C) 2026 Danilo M. # Licensed under the GNU General Public License v2 only. # rofi's own ssh mode shows the alias only, so the config is read here. # ponytail: plain "Keyword value" lines in ~/.ssh/config only; Include and # Match are not followed, wildcard Host patterns are skipped. mapfile -t hosts < <(awk ' function flush() { if (name != "") print name "\t" user "\t" addr } tolower($1) == "host" { flush(); name = ($2 ~ /[*?]/) ? "" : $2; user = ""; addr = $2 } tolower($1) == "hostname" { addr = $2 } tolower($1) == "user" { user = $2 } END { flush() }' ~/.ssh/config) # Two lines a card: the alias, then "user · address" with the user only where # the config sets one. Entries are joined on "|" so each can hold a newline. entries=() for h in "${hosts[@]}"; do IFS=$'\t' read -r name user addr <<< "$h" entries+=("$name ${user:+$user · }$addr") done i=$(IFS='|'; printf '%s' "${entries[*]}" | rofi -dmenu -i -markup-rows \ -sep '|' -eh 2 -format i -p '󰆍 SSH:' -theme ~/.config/rofi/udt/ssh.rasi) || exit name=${hosts[i]%%$'\t'*} exec rofi-sensible-terminal -e ssh "$name"