1#!/usr/bin/env bash
2set -euo pipefail
3
4main() {
5 platform="$(uname -s)"
6 arch="$(uname -m)"
7 channel="${ZED_CHANNEL:-stable}"
8 temp="$(mktemp -d "/tmp/zed-XXXXX")"
9
10 if [[ $platform == "Darwin" ]]; then
11 platform="macos"
12 elif [[ $platform == "Linux" ]]; then
13 platform="linux"
14 channel="${ZED_CHANNEL:-preview}"
15 else
16 echo "Unsupported platform $platform"
17 exit 1
18 fi
19
20 if [[ $platform == "macos" ]] && [[ $arch == arm64* ]]; then
21 arch="aarch64"
22 elif [[ $arch = x86* || $arch == i686* ]]; then
23 arch="x86_64"
24 else
25 echo "Unsupported architecture $arch"
26 exit 1
27 fi
28
29 if which curl >/dev/null 2>&1; then
30 curl () {
31 command curl -fL "$@"
32 }
33 elif which wget >/dev/null 2>&1; then
34 curl () {
35 wget -O- "$@"
36 }
37 else
38 echo "Could not find 'curl' or 'wget' in your path"
39 exit 1
40 fi
41
42 "$platform" "$@"
43}
44
45linux() {
46 echo "Downloading Zed"
47 curl "https://zed.dev/api/releases/$channel/latest/zed-linux-$arch.tar.gz" > "$temp/zed-linux-$arch.tar.gz"
48
49 suffix=""
50 if [[ $channel != "stable" ]]; then
51 suffix="-$channel"
52 fi
53
54 appid=""
55 case "$channel" in
56 stable)
57 appid="dev.zed.Zed"
58 ;;
59 nightly)
60 appid="dev.zed.Zed-Nightly"
61 ;;
62 preview)
63 appid="dev.zed.Zed-Preview"
64 ;;
65 dev)
66 appid="dev.zed.Zed-Dev"
67 ;;
68 *)
69 echo "Unknown release channel: ${channel}. Using stable app ID."
70 appid="dev.zed.Zed"
71 ;;
72 esac
73
74 # Unpack
75 rm -rf "$HOME/.local/zed$suffix.app"
76 mkdir -p "$HOME/.local/zed$suffix.app"
77 tar -xzf "$temp/zed-linux-$arch.tar.gz" -C "$HOME/.local/"
78
79 # Setup ~/.local directories
80 mkdir -p "$HOME/.local/bin" "$HOME/.local/share/applications"
81
82 # Link the binary
83 ln -sf ~/.local/zed$suffix.app/bin/cli "$HOME/.local/bin/zed"
84
85 # Copy .desktop file
86 desktop_file_path="$HOME/.local/share/applications/${appid}.desktop"
87 cp ~/.local/zed$suffix.app/share/applications/zed$suffix.desktop "${desktop_file_path}"
88 sed -i "s|Icon=zed|Icon=$HOME/.local/zed$suffix.app/share/icons/hicolor/512x512/apps/zed.png|g" "${desktop_file_path}"
89 sed -i "s|Exec=zed|Exec=$HOME/.local/zed$suffix.app/bin/zed|g" "${desktop_file_path}"
90
91 if which "zed" >/dev/null 2>&1; then
92 echo "Zed has been installed. Run with 'zed'"
93 else
94 echo "To run Zed from your terminal, you must add ~/.local/bin to your PATH"
95 echo "Run:"
96 echo " echo 'export PATH=\$HOME/.local/bin:\$PATH' >> ~/.bashrc"
97 echo " source ~/.bashrc"
98 echo "To run Zed now, '~/.local/bin/zed'"
99 fi
100}
101
102macos() {
103 echo "Downloading Zed"
104 curl "https://zed.dev/api/releases/$channel/latest/Zed-$arch.dmg" > "$temp/Zed-$arch.dmg"
105 hdiutil attach -quiet "$temp/Zed-$arch.dmg" -mountpoint "$temp/mount"
106 app="$(cd "$temp/mount/"; echo *.app)"
107 echo "Installing $app"
108 if [[ -d "/Applications/$app" ]]; then
109 echo "Removing existing $app"
110 rm -rf "/Applications/$app"
111 fi
112 ditto "$temp/mount/$app" "/Applications/$app"
113 hdiutil detach -quiet "$temp/mount"
114
115 mkdir -p "$HOME/.local/bin"
116 # Link the binary
117 ln -sf /Applications/$app/Contents/MacOS/cli "$HOME/.local/bin/zed"
118
119 if which "zed" >/dev/null 2>&1; then
120 echo "Zed has been installed. Run with 'zed'"
121 else
122 echo "To run Zed from your terminal, you must add ~/.local/bin to your PATH"
123 echo "Run:"
124 echo " echo 'export PATH=\$HOME/.local/bin:\$PATH' >> ~/.bashrc"
125 echo " source ~/.bashrc"
126 echo "To run Zed now, '~/.local/bin/zed'"
127 fi
128}
129
130main "$@"