Created
February 28, 2023 10:03
-
-
Save alexpearce/41f3533b8acb9f6362db37ee5b103c2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tssh --description="SSH to a machine using its Tailscale IP." --argument-names=target_host | |
# Find the `tailscale` executable | |
set cmd '/Applications/Tailscale.app/Contents/MacOS/Tailscale' | |
if not test -x $cmd | |
set cmd (which tailscale) | |
if test $status != 0 | |
set_color red | |
printf "ERROR " | |
set_color normal | |
echo "Could not find Tailscale binary" >&2 | |
return 1 | |
end | |
end | |
# Resolve the hostname to a Tailscale IP | |
set host_ip ($cmd ip -4 $target_host 2>/dev/null) | |
if test $status != 0 | |
set_color red | |
printf "ERROR " | |
set_color normal | |
echo "Failed to resolve Tailscale IP for host '$target_host'" >&2 | |
return 1 | |
end | |
# TODO should all the arguments `ssh` does, including username overriding. | |
ssh ubuntu@$host_ip | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment