main
1#!/usr/bin/env bash
2# List SSH hosts from ~/.ssh/config for raffi script filter.
3# Outputs Alfred Script Filter JSON format.
4# Usage: ssh-raffi [query]
5set -euo pipefail
6
7query="${1:-}"
8
9items="[]"
10while IFS= read -r host; do
11 [[ -z "$host" ]] && continue
12 # Skip wildcards, patterns, and git forges
13 [[ "$host" == *"*"* ]] && continue
14 [[ "$host" == *"/"* ]] && continue
15 echo "$host" | grep -qE '^(github\.com|gitlab\.com|codeberg\.org|git\.sr\.ht)$' && continue
16
17 if [[ -n "$query" ]] && ! echo "$host" | grep -qi "$query"; then
18 continue
19 fi
20 items=$(jq --arg h "$host" \
21 '. + [{"title": $h, "subtitle": "SSH to \($h) in Kitty", "arg": $h}]' <<< "$items")
22done < <(grep "^Host " ~/.ssh/config 2>/dev/null | awk '{print $2}' | sort -u)
23
24jq -n --argjson items "$items" '{"items": $items}'