diff --git a/commands/apps/tailscale/tailscale-switch.sh b/commands/apps/tailscale/tailscale-switch.sh index ad40265e9..e174480c8 100755 --- a/commands/apps/tailscale/tailscale-switch.sh +++ b/commands/apps/tailscale/tailscale-switch.sh @@ -15,9 +15,15 @@ # @Documentation: # @raycast.description Switches Tailscale networks + +# Original author # @raycast.author Ross Zurowski # @raycast.authorURL https://github.com/rosszurowski +# Contributor +# @raycast.author Daniel Schoemer +# @raycast.authorURL https://github.com/quatauta + ts="" if command -v tailscale &> /dev/null; then @@ -29,12 +35,11 @@ else exit 1 fi -$ts logout -$ts up +"${ts}" switch --list | # List all Tailscale accounts " " +grep -vF -e 'ID' -e '*' | # Omit the header line and the current account marked with "*" +awk '{ print $1 }' | # Print only the account ID of not-connected accounts +head -n1 | # Print only the first not-connected account +xargs -r -n1 "${ts}" switch # Switch to the selected account -if command -v jq &> /dev/null; then - account=$($ts status --json | jq -r '.User[(.Self.UserID | tostring)].LoginName') - echo "Connected as $account" -else - echo "Connected" -fi +tailnet="$("${ts}" switch --list | awk '/\*/ { print $2 }')" +echo "Switched to ${tailnet}"