#!/bin/sh
#
# sshmenu - parses ~/.ssh/{config,known_hosts}.
# fzf[0] takes over for fuzzy selection and passes argument to xargs.

gethosts() {
  # shellcheck disable=SC2312
  sed "/Host/s/Host //p;d" "${HOME}/.ssh/config" \
    | grep -v -E '^([[:blank:]]*#|$|\*)'
}

TARGET=$(gethosts | fzf)
test -n "${TARGET}" && exec ssh "${TARGET}"
