Skip to content

Commit

Permalink
Merge pull request #957 from quatauta/feature/commands-apps-tailscale…
Browse files Browse the repository at this point in the history
…-switch-really-switch

[script] Tailscale Switch: Make it switch account without logout
  • Loading branch information
adilrc authored Aug 30, 2024
2 parents d6efbd9 + 1d6845d commit 70ed227
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions commands/apps/tailscale/tailscale-switch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,12 +35,11 @@ else
exit 1
fi

$ts logout
$ts up
"${ts}" switch --list | # List all Tailscale accounts "<ID> <Tailnet name> <User account name>"
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}"

0 comments on commit 70ed227

Please sign in to comment.