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# Start one Zed instance as the current user and a second instance with a different user.
21username_1=$(curl -sH "Authorization: bearer $GITHUB_TOKEN" https://api.github.com/user | jq -r .login)
22username_2=nathansobo
23if [[ $username_1 == $username_2 ]]; then
24 username_2=as-cii
25fi
26
27# Make each Zed instance take up half of the screen.
28
29output=$(system_profiler SPDisplaysDataType -json)
30resolution=$(echo "$output" | jq -r '.SPDisplaysDataType[0].spdisplays_ndrvs[] | select(.spdisplays_online == "spdisplays_yes") | ._spdisplays_resolution')
31width=$(echo "$resolution" | jq -Rr 'split(" x ")[0]')
32half_width=$(($width / 2))
33height=$(echo "$resolution" | jq -Rr 'split(" x ")[1]')
34y=0
35
36echo "Width: $width"
37echo "Half-width: $half_width"
38echo "Height: $height"
39
40position_1=0,${y}
41position_2=${half_width},${y}
42
43# Authenticate using the collab server's admin secret.
44export ZED_STATELESS=1
45export ZED_ADMIN_API_TOKEN=secret
46export ZED_SERVER_URL=http://localhost:8080
47export ZED_WINDOW_SIZE=${half_width},${height}
48
49cargo build
50sleep 0.5
51
52# Start the two Zed child processes. Open the given paths with the first instance.
53trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
54ZED_IMPERSONATE=${username_1} ZED_WINDOW_POSITION=${position_1} target/debug/Zed $@ &
55ZED_IMPERSONATE=${username_2} ZED_WINDOW_POSITION=${position_2} target/debug/Zed &
56wait