2022-11-29 22:50:12 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [[ -z "$GITHUB_TOKEN" ]]; then
|
|
|
|
cat <<-MESSAGE
|
|
|
|
Missing \`GITHUB_TOKEN\` environment variable. This token is needed
|
|
|
|
for fetching your GitHub identity from the command-line.
|
|
|
|
|
|
|
|
Create an access token here: https://github.com/settings/tokens
|
|
|
|
Then edit your \`~/.zshrc\` (or other shell initialization script),
|
|
|
|
adding a line like this:
|
|
|
|
|
|
|
|
export GITHUB_TOKEN="(the token)"
|
|
|
|
|
|
|
|
MESSAGE
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-04-20 15:50:06 +00:00
|
|
|
# Install jq if it's not installed
|
|
|
|
if ! command -v jq &> /dev/null; then
|
|
|
|
echo "Installing jq..."
|
|
|
|
brew install jq
|
|
|
|
fi
|
|
|
|
|
2022-12-02 00:43:39 +00:00
|
|
|
# Start one Zed instance as the current user and a second instance with a different user.
|
|
|
|
username_1=$(curl -sH "Authorization: bearer $GITHUB_TOKEN" https://api.github.com/user | jq -r .login)
|
|
|
|
username_2=nathansobo
|
|
|
|
if [[ $username_1 == $username_2 ]]; then
|
|
|
|
username_2=as-cii
|
2022-11-29 22:50:12 +00:00
|
|
|
fi
|
|
|
|
|
2022-12-02 00:43:39 +00:00
|
|
|
# Make each Zed instance take up half of the screen.
|
2023-04-20 15:47:41 +00:00
|
|
|
output=$(system_profiler SPDisplaysDataType -json)
|
2023-04-21 14:18:01 +00:00
|
|
|
main_display=$(echo "$output" | jq '.SPDisplaysDataType[].spdisplays_ndrvs[] | select(.spdisplays_main == "spdisplays_yes")')
|
|
|
|
resolution=$(echo "$main_display" | jq -r '._spdisplays_resolution')
|
2023-04-20 17:06:33 +00:00
|
|
|
width=$(echo "$resolution" | jq -Rr 'match("(\\d+) x (\\d+)").captures[0].string')
|
2023-04-20 15:47:41 +00:00
|
|
|
half_width=$(($width / 2))
|
2023-04-20 17:06:33 +00:00
|
|
|
height=$(echo "$resolution" | jq -Rr 'match("(\\d+) x (\\d+)").captures[1].string')
|
2023-02-20 22:57:12 +00:00
|
|
|
y=0
|
2022-12-14 19:50:15 +00:00
|
|
|
|
2023-01-31 23:00:49 +00:00
|
|
|
position_1=0,${y}
|
2023-04-20 15:47:41 +00:00
|
|
|
position_2=${half_width},${y}
|
2023-04-20 15:35:35 +00:00
|
|
|
|
2022-12-02 00:43:39 +00:00
|
|
|
# Authenticate using the collab server's admin secret.
|
2022-12-17 20:03:51 +00:00
|
|
|
export ZED_STATELESS=1
|
2023-09-29 20:43:43 +00:00
|
|
|
export ZED_ALWAYS_ACTIVE=1
|
2022-11-29 22:50:12 +00:00
|
|
|
export ZED_ADMIN_API_TOKEN=secret
|
2023-07-18 16:43:27 +00:00
|
|
|
export ZED_SERVER_URL=http://localhost:8080
|
2023-04-20 15:47:41 +00:00
|
|
|
export ZED_WINDOW_SIZE=${half_width},${height}
|
2022-11-30 17:29:49 +00:00
|
|
|
|
|
|
|
cargo build
|
2022-12-14 19:50:15 +00:00
|
|
|
sleep 0.5
|
2022-11-29 22:50:12 +00:00
|
|
|
|
2022-12-02 00:43:39 +00:00
|
|
|
# Start the two Zed child processes. Open the given paths with the first instance.
|
2022-11-29 22:50:12 +00:00
|
|
|
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
|
2023-08-07 23:45:13 +00:00
|
|
|
ZED_IMPERSONATE=${ZED_IMPERSONATE:=${username_1}} ZED_WINDOW_POSITION=${position_1} target/debug/Zed $@ &
|
2023-06-28 02:19:08 +00:00
|
|
|
SECOND=true ZED_IMPERSONATE=${username_2} ZED_WINDOW_POSITION=${position_2} target/debug/Zed &
|
2022-11-29 22:50:12 +00:00
|
|
|
wait
|