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