forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailscale-switch.sh
executable file
·40 lines (32 loc) · 991 Bytes
/
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
#!/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
# @raycast.author Ross Zurowski
# @raycast.authorURL https://github.com/rosszurowski
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 logout
$ts up
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