Skip to content

Commit 70ed227

Browse files
authored
Merge pull request #957 from quatauta/feature/commands-apps-tailscale-switch-really-switch
[script] Tailscale Switch: Make it switch account without logout
2 parents d6efbd9 + 1d6845d commit 70ed227

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

commands/apps/tailscale/tailscale-switch.sh

+13-8
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515

1616
# @Documentation:
1717
# @raycast.description Switches Tailscale networks
18+
19+
# Original author
1820
# @raycast.author Ross Zurowski
1921
# @raycast.authorURL https://github.com/rosszurowski
2022

23+
# Contributor
24+
# @raycast.author Daniel Schoemer
25+
# @raycast.authorURL https://github.com/quatauta
26+
2127
ts=""
2228

2329
if command -v tailscale &> /dev/null; then
@@ -29,12 +35,11 @@ else
2935
exit 1
3036
fi
3137

32-
$ts logout
33-
$ts up
38+
"${ts}" switch --list | # List all Tailscale accounts "<ID> <Tailnet name> <User account name>"
39+
grep -vF -e 'ID' -e '*' | # Omit the header line and the current account marked with "*"
40+
awk '{ print $1 }' | # Print only the account ID of not-connected accounts
41+
head -n1 | # Print only the first not-connected account
42+
xargs -r -n1 "${ts}" switch # Switch to the selected account
3443

35-
if command -v jq &> /dev/null; then
36-
account=$($ts status --json | jq -r '.User[(.Self.UserID | tostring)].LoginName')
37-
echo "Connected as $account"
38-
else
39-
echo "Connected"
40-
fi
44+
tailnet="$("${ts}" switch --list | awk '/\*/ { print $2 }')"
45+
echo "Switched to ${tailnet}"

0 commit comments

Comments
 (0)