Commit 1db1cd90e6a8

Vincent Demeester <vincent@sbr.pm>
2026-02-25 16:55:18
feat(raffi): shpool remote sessions, split signatures, fix currency trigger
- Rewrite shpool-raffi script: lists SSH hosts first, then sessions on selected host via shpool-remote. Action uses ssh host/session. - Split sig snippets: email signatures (file, synced) vs git trailers (inline) - Add git trailer snippets: /lgtm, /approve, /lgtm+/approve, /retest - Remove custom currency trigger (€), use default ($) with EUR base - Add email signatures to ~/sync/raffi-snippets/signatures.yaml
1 parent a5421ee
Changed files (2)
dots
config
pkgs
my
scripts
dots/config/raffi/raffi.yaml
@@ -170,7 +170,7 @@ addons:
       keyword: sp
       command: shpool-raffi
       icon: utilities-terminal
-      action: "kitty --title shpool:{value} shpool attach {value}"
+      action: "kitty --title shpool:{value} ssh {value}"
     - name: IDs & Timestamps
       keyword: uid
       command: uid-raffi
@@ -233,7 +233,15 @@ addons:
           value: "Tested-by: Vincent Demeester <vincent@sbr.pm>"
         - name: "Co-authored-by"
           value: "Co-authored-by: Vincent Demeester <vincent@sbr.pm>"
-        - name: "LGTM"
+        - name: "/lgtm"
+          value: "/lgtm"
+        - name: "/approve"
+          value: "/approve"
+        - name: "/lgtm + /approve"
+          value: "/lgtm\n/approve"
+        - name: "/retest"
+          value: "/retest"
+        - name: "LGTM message"
           value: "Thanks for the contribution! LGTM."
         - name: "WIP"
           value: "[WIP] This is a work in progress, please do not merge yet."
pkgs/my/scripts/bin/shpool-raffi
@@ -1,38 +1,86 @@
 #!/usr/bin/env bash
-# List shpool sessions for raffi script filter.
+# List SSH hosts and shpool sessions for raffi script filter.
 # Outputs Alfred Script Filter JSON format.
+#
 # Usage: shpool-raffi [query]
 #
-# Always includes a "new session" item. If a query is given that doesn't
-# match any existing session, the new session item uses the query as name.
-
+# Without query or partial host match: lists SSH hosts from ~/.ssh/config
+# With "host" or "host query": lists shpool sessions on that host
+#
+# The action should be: ssh {value}
+# Values are formatted as host/session for direct ssh attach.
 set -euo pipefail
 
 query="${1:-}"
+host="${query%% *}"
+session_query=""
+if [[ "$query" == *" "* ]]; then
+    session_query="${query#* }"
+fi
 
-items="[]"
+# Get SSH hosts (skip wildcards, patterns, git forges)
+get_hosts() {
+    grep "^Host " ~/.ssh/config 2>/dev/null \
+        | awk '{print $2}' \
+        | grep -v '\*' \
+        | grep -v '/' \
+        | grep -v -E '^(github\.com|gitlab\.com|codeberg\.org|git\.sr\.ht)$' \
+        | sort -u
+}
 
-# Parse existing sessions
-while IFS=$'\t' read -r name started_at status; do
-    [[ "$name" == "NAME" ]] && continue  # skip header
-    [[ -z "$name" ]] && continue
-    items=$(jq --arg n "$name" --arg s "$status" --arg t "$started_at" \
-        '. + [{"title": $n, "subtitle": "\($s) since \($t)", "arg": $n}]' <<< "$items")
-done < <(shpool list 2>/dev/null)
+# Check if the query matches exactly one host
+match_host() {
+    local q="$1"
+    local exact
+    exact=$(get_hosts | grep -x "$q" 2>/dev/null || true)
+    echo "$exact"
+}
 
-# Add "new session" entry
-if [[ -n "$query" ]]; then
-    new_name="$query"
+# List sessions on a remote host
+list_sessions() {
+    local h="$1"
+    local sq="$2"
+    local items="[]"
+
+    # Try to get sessions from remote host (timeout 3s)
+    local output
+    if output=$(ssh -o ConnectTimeout=3 "$h" shpool list 2>/dev/null); then
+        while IFS=$'\t' read -r name started_at status; do
+            [[ "$name" == "NAME" ]] && continue
+            [[ -z "$name" ]] && continue
+            if [[ -z "$sq" ]] || echo "$name" | grep -qi "$sq"; then
+                items=$(jq --arg n "$name" --arg h "$h" --arg s "$status" --arg t "$started_at" \
+                    '. + [{"title": $n, "subtitle": "\($h) — \($s) since \($t)", "arg": "\($h)/\($n)"}]' <<< "$items")
+            fi
+        done <<< "$output"
+    fi
+
+    # Add "new session" entry
+    local new_name="${sq:-main}"
+    items=$(jq --arg n "$new_name" --arg h "$h" \
+        '. + [{"title": "➕ New: \($n)", "subtitle": "Create or attach to \($n) on \($h)", "arg": "\($h)/\($n)"}]' <<< "$items")
+
+    jq -n --argjson items "$items" '{"items": $items}'
+}
+
+# List hosts
+list_hosts() {
+    local q="$1"
+    local items="[]"
+
+    while IFS= read -r h; do
+        if [[ -z "$q" ]] || echo "$h" | grep -qi "$q"; then
+            items=$(jq --arg h "$h" \
+                '. + [{"title": $h, "subtitle": "Connect to shpool on \($h)", "arg": $h}]' <<< "$items")
+        fi
+    done < <(get_hosts)
+
+    jq -n --argjson items "$items" '{"items": $items}'
+}
+
+# If host matches exactly, list sessions on that host
+if [[ -n "$host" ]] && [[ -n "$(match_host "$host")" ]]; then
+    list_sessions "$host" "$session_query"
 else
-    new_name="main"
+    list_hosts "$query"
 fi
-items=$(jq --arg n "$new_name" \
-    '. + [{"title": "➕ New: \($n)", "subtitle": "Create or attach to session \($n)", "arg": $n}]' <<< "$items")
-
-# Filter by query
-if [[ -n "$query" ]]; then
-    items=$(jq --arg q "$query" \
-        '[.[] | select(.title | ascii_downcase | contains($q | ascii_downcase))]' <<< "$items")
-fi
-
-jq -n --argjson items "$items" '{"items": $items}'