58 lines · 1.9 KB · Text
RawDownload
#!/bin/bash set -e if [[ -z "$GITHUB_TOKEN" ]]; then  cat <<-MESSAGEMissing \`GITHUB_TOKEN\` environment variable. This token is neededfor fetching your GitHub identity from the command-line. Create an access token here: https://github.com/settings/tokensThen edit your \`~/.zshrc\` (or other shell initialization script),adding a line like this:     export GITHUB_TOKEN="(the token)" MESSAGE  exit 1fi # Install jq if it's not installedif ! command -v jq &> /dev/null; then    echo "Installing jq..."    brew install jqfi # 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=nathansoboif [[ $username_1 == $username_2 ]]; then  username_2=as-ciifi # Make each Zed instance take up half of the screen.output=$(system_profiler SPDisplaysDataType -json)main_display=$(echo "$output" | jq '.SPDisplaysDataType[].spdisplays_ndrvs[] | select(.spdisplays_main == "spdisplays_yes")')resolution=$(echo "$main_display" | jq -r '._spdisplays_resolution')width=$(echo "$resolution" | jq -Rr 'match("(\\d+) x (\\d+)").captures[0].string')half_width=$(($width / 2))height=$(echo "$resolution" | jq -Rr 'match("(\\d+) x (\\d+)").captures[1].string')y=0 position_1=0,${y}position_2=${half_width},${y} # Authenticate using the collab server's admin secret.export ZED_STATELESS=1export ZED_ADMIN_API_TOKEN=secretexport ZED_SERVER_URL=http://localhost:8080export ZED_WINDOW_SIZE=${half_width},${height} cargo buildsleep 0.5 # Start the two Zed child processes. Open the given paths with the first instance.trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXITZED_IMPERSONATE=${ZED_IMPERSONATE:=${username_1}} ZED_WINDOW_POSITION=${position_1} target/debug/Zed $@ &SECOND=true ZED_IMPERSONATE=${username_2} ZED_WINDOW_POSITION=${position_2} target/debug/Zed &wait