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