start-local-collaboration

 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.
28resolution_line=$(system_profiler SPDisplaysDataType | grep Resolution | head -n1)
29screen_size=($(echo $resolution_line | egrep -o '[0-9]+'))
30scale_factor=1
31if [[ $resolution_line =~ Retina ]]; then scale_factor=2; fi
32width=$(expr ${screen_size[0]} / 2 / $scale_factor)
33height=${screen_size[1] / $scale_factor}
34y=0
35
36position_1=0,${y}
37position_2=${width},${y}
38
39# Authenticate using the collab server's admin secret.
40export ZED_STATELESS=1
41export ZED_ADMIN_API_TOKEN=secret
42export ZED_SERVER_URL=http://localhost:8080
43export ZED_WINDOW_SIZE=${width},${height}
44
45cargo build
46sleep 0.5
47
48# Start the two Zed child processes. Open the given paths with the first instance.
49trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
50ZED_IMPERSONATE=${username_1} ZED_WINDOW_POSITION=${position_1} target/debug/Zed $@ &
51ZED_IMPERSONATE=${username_2} ZED_WINDOW_POSITION=${position_2} target/debug/Zed &
52wait