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