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 if [ -f ~/.local/zed$suffix.app/bin/zed ]; then
84 ln -sf ~/.local/zed$suffix.app/bin/zed "$HOME/.local/bin/zed"
85 else
86 # support for versions before 0.139.x.
87 ln -sf ~/.local/zed$suffix.app/bin/cli "$HOME/.local/bin/zed"
88 fi
89
90 # Copy .desktop file
91 desktop_file_path="$HOME/.local/share/applications/${appid}.desktop"
92 cp ~/.local/zed$suffix.app/share/applications/zed$suffix.desktop "${desktop_file_path}"
93 sed -i "s|Icon=zed|Icon=$HOME/.local/zed$suffix.app/share/icons/hicolor/512x512/apps/zed.png|g" "${desktop_file_path}"
94 sed -i "s|Exec=zed|Exec=$HOME/.local/zed$suffix.app/bin/zed|g" "${desktop_file_path}"
95
96 if which "zed" >/dev/null 2>&1; then
97 echo "Zed has been installed. Run with 'zed'"
98 else
99 echo "To run Zed from your terminal, you must add ~/.local/bin to your PATH"
100 echo "Run:"
101 echo " echo 'export PATH=\$HOME/.local/bin:\$PATH' >> ~/.bashrc"
102 echo " source ~/.bashrc"
103 echo "To run Zed now, '~/.local/bin/zed'"
104 fi
105}
106
107macos() {
108 echo "Downloading Zed"
109 curl "https://zed.dev/api/releases/$channel/latest/Zed-$arch.dmg" > "$temp/Zed-$arch.dmg"
110 hdiutil attach -quiet "$temp/Zed-$arch.dmg" -mountpoint "$temp/mount"
111 app="$(cd "$temp/mount/"; echo *.app)"
112 echo "Installing $app"
113 if [[ -d "/Applications/$app" ]]; then
114 echo "Removing existing $app"
115 rm -rf "/Applications/$app"
116 fi
117 ditto "$temp/mount/$app" "/Applications/$app"
118 hdiutil detach -quiet "$temp/mount"
119
120 mkdir -p "$HOME/.local/bin"
121 # Link the binary
122 ln -sf /Applications/$app/Contents/MacOS/cli "$HOME/.local/bin/zed"
123
124 if which "zed" >/dev/null 2>&1; then
125 echo "Zed has been installed. Run with 'zed'"
126 else
127 echo "To run Zed from your terminal, you must add ~/.local/bin to your PATH"
128 echo "Run:"
129 echo " echo 'export PATH=\$HOME/.local/bin:\$PATH' >> ~/.bashrc"
130 echo " source ~/.bashrc"
131 echo "To run Zed now, '~/.local/bin/zed'"
132 fi
133}
134
135main "$@"