-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathastronvim.sh
executable file
·138 lines (115 loc) · 3.74 KB
/
astronvim.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
#!/usr/bin/env bash
set -o errexit -o errtrace -o pipefail -o nounset
function warn() {
>&2 echo "$@"
}
function die() {
local ec=$?; if (( ec == 0 )); then ec=1; fi
warn "$@"; warn "died. backtrace:"
local frame=0; while caller $frame; do ((++frame)); done
exit $ec
}
trap die ERR
function usage() {
cat <<EOF
Usage: $0 [options] [--] [ <DEST_DIR> ]
Install AstroNvim to <DEST_DIR>
<DEST_DIR> must not exist. Defaults to \$HOME/avim
options:
--help, -h
Print this message
--debug, -d
Enable debug tracing
--
Stop parsing options
EOF
}
function main() {
# MAIN
while (($#)); do
case $1 in
--help|-h) usage; exit 0
;;
--debug|-d) set -o xtrace
;;
--) shift; break
;;
-*) warn "Unrecognized argument: $1"; exit 1
;;
*) break
;;
esac; shift
done
for cmd in curl tar git ; do
if ! command -v $cmd >/dev/null 2>&1; then
die "ERROR: '$cmd' not found in path"
fi
done
if (( $# == 0 )); then
DEST_DIR="$HOME/avim"
else
DEST_DIR=$1; shift
fi
[[ -e "$DEST_DIR" ]] && die "Destination directory already exists: $DEST_DIR"
mkdir -p "$DEST_DIR"
DEST_DIR="$( cd "$DEST_DIR" && pwd )"
OS=$(uname -s); readonly OS
ARCH=$(uname -m); readonly ARCH
# https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz (glibc >= 2.31), nvim-linux64/bin/nvim
# https://github.com/neovim/neovim-releases/releases/download/stable/nvim-linux64.tar.gz (glibc >= 2.17), nvim-linux64/bin/nvim
# https://github.com/neovim/neovim/releases/download/stable/nvim-macos-arm64.tar.gz, nvim-macos-arm64/bin/nvim
# https://github.com/neovim/neovim/releases/download/stable/nvim-macos-x86_64.tar.gz, nvim-macos-x86_64/bin/nvim
case $OS in
Linux)
# use the more portable version linked with glibc 2.17
REPO=neovim/neovim-releases
case $ARCH in
x86_64)
PKG=nvim-linux64
;;
*) die "ERROR: unsupported ARCH: $ARCH" ;;
esac
;;
Darwin)
REPO=neovim/neovim
case $ARCH in
x86_64)
PKG=nvim-macos-x86_64
;;
arm64)
PKG=nvim-macos-arm64
;;
*) die "ERROR: unsupported ARCH: $ARCH" ;;
esac
;;
*) die "ERROR: unsupported OS: $OS" ;;
esac
NEOVIM_PKG_URL="https://github.com/$REPO/releases/download/stable/$PKG.tar.gz"
mkdir -p "$DEST_DIR/.cache"
mkdir -p "$DEST_DIR/.config"
mkdir -p "$DEST_DIR/.config/nvim"
mkdir -p "$DEST_DIR/.local/share"
mkdir -p "$DEST_DIR/.local/state"
mkdir -p "$HOME/.local/bin"
echo
echo "Downloading Neovim from $NEOVIM_PKG_URL and extracting to $DEST_DIR"
echo
curl -fsSL https://github.com/$REPO/releases/download/stable/$PKG.tar.gz | tar xzC "$DEST_DIR"
echo
echo "Downloading AstroNvim and extracting to $DEST_DIR/.config/nvim"
echo
curl -fsSL https://github.com/AstroNvim/template/archive/refs/heads/main.tar.gz | tar xzC "$DEST_DIR/.config/nvim" --strip-components=1
cat > "$HOME/.local/bin/avim" <<EOF
#!/bin/bash
XDG_CONFIG_HOME="$DEST_DIR/.config" \
XDG_DATA_HOME="$DEST_DIR/.local/share" \
XDG_STATE_HOME="$DEST_DIR/.local/state" \
XDG_CACHE_HOME="$DEST_DIR/.cache" \
exec "$DEST_DIR/$PKG/bin/nvim" "\$@"
EOF
chmod +x "$HOME/.local/bin/avim"
echo
echo "AstroNvim installed to $DEST_DIR, start with $HOME/.local/bin/avim"
}
main "$@"
# vim:ft=bash:sw=4:ts=4:expandtab