This commit is contained in:
Peder Bergebakken Sundt 2025-03-16 23:54:40 +01:00
parent 47a02be2cd
commit e0429c9081

@ -35,14 +35,17 @@ zeditor-remote() {
if [[ -r /etc/resolv.conf && -r "$HOME"/.ssh/known_hosts ]]; then
local -a hosts
readarray -d $'\n' -t hosts < <(
cut <"$HOME"/.ssh/known_hosts -d' ' -f1 | sort -u \
| grep -E "(\\.$(hostname --domain)|^[^.]*)$"
cut <"$HOME"/.ssh/known_hosts -d' ' -f1 | sort -u \
| grep -Ev '^([0-9]{0,3}\.){3}[0-9]{0,3}$' \
| grep -Ev '^([0-9a-fA-F]{0,4}:){0,7}:?([0-9a-fA-F]{0,4}:){0,6}[0-9a-fA-F]{0,4}$'
)
local -a domains
readarray -d ' ' -t domains < <(
grep </etc/resolv.conf '^search ' | cut -d' ' -f2-
)
printf '%s\n' "${hosts[@]}" | sed -E "s/\\.($(IFS='|'; printf "%s" "${domains[*]}"))\$//g"
printf '%s\n' "${hosts[@]}" \
| sed -E "s/\\.($(IFS='|'; printf "%s" "${domains[*]}"))\$//g" \
| grep -v '\.'
fi
} | grep -v '^localhost$' | sort -u
} | fzf --multi --reverse --bind 'ctrl-a:toggle-all' --height=25 --cycle \
@ -63,11 +66,11 @@ zeditor-remote() {
sshargs=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null)
if [[ "$host" = localhost ]]; then
cd "$HOME"
fd "^\.git$" repos/ "${fdargs[@]}" -x printf '~/%q\n' "{//}"
fd "^\.git$" repos/ "${fdargs[@]}" -L -x printf '~/%q\n' "{//}"
else
# TODO: report timeouts?
timeout 5 ssh "${sshargs[@]}" 2>/dev/null "$host" \
fd "^\.git$" repos/ "${fdargs[@]}" -x printf "'ssh://%s/~/%q\n'" "'$host'" "'{//}'"
fd "^\.git$" repos/ "${fdargs[@]}" -L -x printf "'ssh://%s/~/%q\n'" "'$host'" "'{//}'"
fi
}
$spin xe <<<"$host" -j"$(wc -l <<<"$host")" -s "$(declare -f worker); worker \"\$@\"" 2>/dev/null ||: