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 if [[ -n "${ZED_BUNDLE_PATH:-}" ]]; then
47 cp "$ZED_BUNDLE_PATH" "$temp/zed-linux-$arch.tar.gz"
48 else
49 echo "Downloading Zed"
50 curl "https://zed.dev/api/releases/$channel/latest/zed-linux-$arch.tar.gz" > "$temp/zed-linux-$arch.tar.gz"
51 fi
52
53 suffix=""
54 if [[ $channel != "stable" ]]; then
55 suffix="-$channel"
56 fi
57
58 appid=""
59 case "$channel" in
60 stable)
61 appid="dev.zed.Zed"
62 ;;
63 nightly)
64 appid="dev.zed.Zed-Nightly"
65 ;;
66 preview)
67 appid="dev.zed.Zed-Preview"
68 ;;
69 dev)
70 appid="dev.zed.Zed-Dev"
71 ;;
72 *)
73 echo "Unknown release channel: ${channel}. Using stable app ID."
74 appid="dev.zed.Zed"
75 ;;
76 esac
77
78 # Unpack
79 rm -rf "$HOME/.local/zed$suffix.app"
80 mkdir -p "$HOME/.local/zed$suffix.app"
81 tar -xzf "$temp/zed-linux-$arch.tar.gz" -C "$HOME/.local/"
82
83 # Setup ~/.local directories
84 mkdir -p "$HOME/.local/bin" "$HOME/.local/share/applications"
85
86 # Link the binary
87 if [ -f ~/.local/zed$suffix.app/bin/zed ]; then
88 ln -sf ~/.local/zed$suffix.app/bin/zed "$HOME/.local/bin/zed"
89 else
90 # support for versions before 0.139.x.
91 ln -sf ~/.local/zed$suffix.app/bin/cli "$HOME/.local/bin/zed"
92 fi
93
94 # Copy .desktop file
95 desktop_file_path="$HOME/.local/share/applications/${appid}.desktop"
96 cp ~/.local/zed$suffix.app/share/applications/zed$suffix.desktop "${desktop_file_path}"
97 sed -i "s|Icon=zed|Icon=$HOME/.local/zed$suffix.app/share/icons/hicolor/512x512/apps/zed.png|g" "${desktop_file_path}"
98 sed -i "s|Exec=zed|Exec=$HOME/.local/zed$suffix.app/libexec/zed-editor|g" "${desktop_file_path}"
99
100 if which "zed" >/dev/null 2>&1; then
101 echo "Zed has been installed. Run with 'zed'"
102 else
103 echo "To run Zed from your terminal, you must add ~/.local/bin to your PATH"
104 echo "Run:"
105 echo " echo 'export PATH=\$HOME/.local/bin:\$PATH' >> ~/.bashrc"
106 echo " source ~/.bashrc"
107 echo "To run Zed now, '~/.local/bin/zed'"
108 fi
109}
110
111macos() {
112 echo "Downloading Zed"
113 curl "https://zed.dev/api/releases/$channel/latest/Zed-$arch.dmg" > "$temp/Zed-$arch.dmg"
114 hdiutil attach -quiet "$temp/Zed-$arch.dmg" -mountpoint "$temp/mount"
115 app="$(cd "$temp/mount/"; echo *.app)"
116 echo "Installing $app"
117 if [[ -d "/Applications/$app" ]]; then
118 echo "Removing existing $app"
119 rm -rf "/Applications/$app"
120 fi
121 ditto "$temp/mount/$app" "/Applications/$app"
122 hdiutil detach -quiet "$temp/mount"
123
124 mkdir -p "$HOME/.local/bin"
125 # Link the binary
126 ln -sf /Applications/$app/Contents/MacOS/cli "$HOME/.local/bin/zed"
127
128 if which "zed" >/dev/null 2>&1; then
129 echo "Zed has been installed. Run with 'zed'"
130 else
131 echo "To run Zed from your terminal, you must add ~/.local/bin to your PATH"
132 echo "Run:"
133 echo " echo 'export PATH=\$HOME/.local/bin:\$PATH' >> ~/.bashrc"
134 echo " source ~/.bashrc"
135 echo "To run Zed now, '~/.local/bin/zed'"
136 fi
137}
138
139main "$@"