forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailscale-switch.sh
executable file
·45 lines (35 loc) · 1.38 KB
/
tailscale-switch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Note: Tailscale v1.8.0 required
# Install via https://tailscale.com/download
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Switch Account
# @raycast.mode silent
# Optional parameters:
# @raycast.icon ./images/tailscale-icon.png
# @raycast.iconDark ./images/tailscale-iconDark.png
# @raycast.packageName Tailscale
# @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
ts=$(which tailscale)
elif [ -f /Applications/Tailscale.app/Contents/MacOS/Tailscale ]; then
ts="/Applications/Tailscale.app/Contents/MacOS/Tailscale"
else
echo "Tailscale is not installed. See tailscale.com/download"
exit 1
fi
"${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
tailnet="$("${ts}" switch --list | awk '/\*/ { print $2 }')"
echo "Switched to ${tailnet}"