-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
170 lines (145 loc) · 4.85 KB
/
install
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
set -eo pipefail
profile="default"
declare USE_SSH=0
declare -x TESTNVIM_BRANCH="${TESTNVIM_BRANCH:-"main"}"
declare -xr TESTNVIM_REMOTE="${TESTNVIM_REMOTE:-quantumfate/TestNvim.git}"
export TESTNVIM_APPNAME=${TESTNVIM_APPNAME:-"tvim"}
export NVIM_APPNAME="$TESTNVIM_APPNAME"
declare -a URLS=(
"https://raw.githubusercontent.com/quantumfate/TestNvim/${TESTNVIM_BRANCH}/scripts/vars"
"https://raw.githubusercontent.com/quantumfate/TestNvim/${TESTNVIM_BRANCH}/scripts/messages"
"https://raw.githubusercontent.com/quantumfate/TestNvim/${TESTNVIM_BRANCH}/scripts/functions"
)
export TESTNVIM_USER_PROFILE=${TESTNVIM_USER_PROFILE:-"$profile"}
OS=$(uname -s)
echo "Preparing to install TestNvim..."
# Create a temporary directory based on the operating system
if [ "$OS" == "Darwin" ]; then
# macOS
temp_dir=$(mktemp -d -t tmpdir)
else
# Assume Linux
temp_dir=$(mktemp -d)
fi
for VARS_URL in "${URLS[@]}"; do
file_name=$(basename "$VARS_URL")
temp_file="$temp_dir/$file_name"
if curl -LSs -o "$temp_file" "$VARS_URL"; then
sleep 3
# shellcheck disable=SC1090
source "$temp_file"
else
echo "Error: Failed to download from $VARS_URL"
rm -rf "$temp_dir"
exit 1
fi
done
function print_logo() {
cat <<'EOF'
____ ____ ____ ____ ____ ____ ____ ____
||T |||e |||s |||t |||N |||v |||i |||m ||
||__|||__|||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|/__\|/__\|
EOF
}
function usage() {
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --appname <name> Set the Neovim appname. Default is 'tvim'."
echo " --ssh Use SSH for git clone (default is HTTPS)."
echo " -h, --help Show this help message and exit."
}
function parse_arguments() {
while [ "$#" -gt 0 ]; do
case "$1" in
--appname)
NVIM_APPNAME="$2"
shift
;;
--ssh)
USE_SSH=1
;;
-h | --help)
usage
exit 0
;;
esac
shift
done
}
function clone_tvim() {
if [ -d "$TESTNVIM_STATE_DIR" ]; then
info_msg "An existing TestNvim instance was found in $TESTNVIM_STATE_DIR."
compact_info_msg "Would you like to backup and replace it? (y/n)"
read -r answer
if [[ "$answer" != "y" ]]; then
compact_error_msg "Aborting installation."
exit 1
else
__backup_dir "$TESTNVIM_STATE_DIR"
fi
fi
info_msg "[INFO]: Cloning plugin: ${TESTNVIM_APPNAME} into: ${TESTNVIM_STATE_DIR}"
local url=""
if [ "$USE_SSH" -eq 0 ]; then
url+="https://github.com/"
else
url+="git@github.com:"
fi
output=$(git clone --branch "${TESTNVIM_BRANCH}" "${url}${TESTNVIM_REMOTE}" "${TESTNVIM_STATE_DIR}" 2>&1)
if [ ! "$output" ]; then
echo "$output" | tail -n +2 | while IFS= read -r line; do
compact_error_msg "$line"
done
exit 1
fi
compact_success_msg "Successfully cloned TestNvim."
}
function generate_user_config() {
if [ -d "$TESTNVIM_CONFIG_PROFILE" ]; then
info_msg "An existing Neovim configuration was found in $TESTNVIM_CONFIG_PROFILE."
compact_info_msg "Would you like to backup and replace it? (y/n)"
read -r answer
if [[ "$answer" != "y" ]]; then
compact_error_msg "Aborting installation."
exit 1
else
__backup_dir "$TESTNVIM_CONFIG_PROFILE"
fi
rm -rf "${TESTNVIM_CONFIG_PROFILE:?}"
fi
mkdir -p "$TESTNVIM_CONFIG_PROFILE"
cp -r "$TESTNVIM_STATE_DIR/utils/conf"/* "$TESTNVIM_CONFIG_PROFILE"
compact_success_msg "Successfully generated user configuration."
}
function setup_tvim() {
info_msg "Installing TestNvim"
compact_info_msg "Preparing Lazy setup"
chmod +x "$TESTNVIM_STATE_DIR/scripts/tvim"
if [ -d "$HOME/.local/bin" ]; then
ln -s "$TESTNVIM_STATE_DIR/scripts/tvim" "$HOME/.local/bin/tvim"
tvim --headless -c 'quitall'
else
compact_warn_msg "Manually link the script '${TESTNVIM_STATE_DIR}/scripts/tvim' to your path"
fi
compact_success_msg "TestNvim intsallation complete."
}
function main() {
info_msg "TestNvim configuration:"
compact_info_msg " Profile: ${TESTNVIM_USER_PROFILE}"
compact_info_msg " Cache dir: $TESTNVIM_CACHE_PROFILE"
compact_info_msg " State dir: $TESTNVIM_STATE_DIR"
compact_info_msg " Data dir: $TESTNVIM_DATA_PROFILE"
compact_info_msg " Config dir: $TESTNVIM_CONFIG_PROFILE"
compact_info_msg " Log dir: $TESTNVIM_LOG_PROFILE\n"
parse_arguments "$@"
print_logo
clone_tvim
generate_user_config
setup_tvim
compact_info_msg "Thank you for installing TestNvim!!"
rm -rf "$temp_dir"
}
main "$@"