blob: 1092b83efc8d2f335fb7c0cc3008408a2d3a0805 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#!/bin/bash
# blackpearl-sshmenu.sh - the hosts in ~/.ssh/config as rofi cards
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# 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+=("<b>$name</b>
<span size='small' fgalpha='65%'>${user:+$user · }$addr</span>")
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'*}
# A tab in the running kitty, through the socket kitty.conf's listen_on opens;
# a new terminal when no kitty is up.
# ponytail: first socket wins when several kitty instances run.
sockets=("$XDG_RUNTIME_DIR"/kitty-*)
if [[ -S ${sockets[0]} ]] && kitten @ --to "unix:${sockets[0]}" launch \
--type=tab --tab-title "$name" ssh "$name" >/dev/null; then
exec hyprctl dispatch 'hl.dsp.focus({ window = "class:kitty" })' >/dev/null
fi
exec rofi-sensible-terminal -e ssh "$name"
|