-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·339 lines (293 loc) · 11.4 KB
/
install.sh
File metadata and controls
executable file
·339 lines (293 loc) · 11.4 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/bash
# Vimlantis Installation Script
# This script installs Vimlantis as a Neovim plugin
set -e
echo "🚢 Vimlantis Installation"
echo "=========================="
echo ""
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Attempt to install Node.js and npm on Debian/Ubuntu if missing
echo -e "${BLUE}Checking for Node.js...${NC}"
if ! command -v node &> /dev/null; then
echo -e "${YELLOW}Node.js not found. Attempting to install via apt-get (Debian/Ubuntu)...${NC}"
if command -v apt-get &> /dev/null; then
echo -e "${BLUE}Running: sudo apt-get update && sudo apt-get install -y nodejs npm${NC}"
sudo apt-get update
sudo apt-get install -y nodejs npm || {
echo -e "${RED}Failed to install Node.js/npm via apt-get.${NC}"
echo "Please install Node.js (v16 or higher) manually from https://nodejs.org and re-run this script."
exit 1
}
else
echo -e "${RED}apt-get not found.${NC}"
echo "Automatic install is only supported on Debian/Ubuntu via apt-get."
echo "Please install Node.js (v16 or higher) manually from https://nodejs.org and re-run this script."
exit 1
fi
else
echo -e "${GREEN}Node.js is already installed.${NC}"
fi
# Check for Neovim and Lazy.nvim, and offer installation options if missing
echo ""
echo -e "${BLUE}Checking for Neovim/Lazy.nvim...${NC}"
HAS_NVIM=false
HAS_LAZY=false
if command -v nvim &> /dev/null; then
HAS_NVIM=true
echo -e "${GREEN}Neovim is installed.${NC}"
# Detect Lazy.nvim by looking for lazy.lua or lazy.nvim directory in config
if [ -n "$XDG_CONFIG_HOME" ]; then
NVIM_CONFIG_DIR="$XDG_CONFIG_HOME/nvim"
else
NVIM_CONFIG_DIR="$HOME/.config/nvim"
fi
if [ -f "$NVIM_CONFIG_DIR/lua/lazy.lua" ] || [ -d "$NVIM_CONFIG_DIR/lazy/lazy.nvim" ] || [ -d "$NVIM_CONFIG_DIR/pack/lazy/start/lazy.nvim" ]; then
HAS_LAZY=true
echo -e "${GREEN}Lazy.nvim appears to be installed.${NC}"
fi
fi
if [ "$HAS_NVIM" = false ] && [ "$HAS_LAZY" = false ]; then
echo ""
echo -e "${YELLOW}Neovim and Lazy.nvim were not detected.${NC}"
echo "1) Install Neovim"
echo "2) Install LazyVim (requires Neovim)"
echo "3) Continue without installing"
echo ""
read -p "Enter choice [1-3]: " NVIM_LAZY_CHOICE
case $NVIM_LAZY_CHOICE in
1)
echo -e "${BLUE}Attempting to install Neovim...${NC}"
if command -v apt-get &> /dev/null; then
echo -e "${BLUE}Detected apt-get (Ubuntu/Mint and similar). Installing via apt-get...${NC}"
sudo apt-get update
sudo apt-get install -y neovim || {
echo -e "${RED}Failed to install Neovim automatically via apt-get.${NC}"
echo "Please install Neovim manually from https://neovim.io and re-run this script if needed."
}
elif command -v pacman &> /dev/null; then
echo -e "${BLUE}Detected pacman (Arch/Manjaro and similar). Installing via pacman...${NC}"
sudo pacman -Sy --noconfirm neovim || {
echo -e "${RED}Failed to install Neovim automatically via pacman.${NC}"
echo "Please install Neovim manually from https://neovim.io and re-run this script if needed."
}
else
echo -e "${RED}No supported package manager (apt-get or pacman) detected for automatic Neovim install.${NC}"
echo "Please install Neovim manually from https://neovim.io."
fi
;;
2)
echo -e "${BLUE}LazyVim installation not automated by this script yet.${NC}"
echo "Please follow LazyVim's installation instructions at: https://www.lazyvim.org/installation"
;;
3)
echo -e "${YELLOW}Continuing without installing Neovim/LazyVim.${NC}"
;;
*)
echo -e "${RED}Invalid choice, continuing without installing Neovim/LazyVim.${NC}"
;;
esac
fi
create_lazy_spec_file() {
local lazy_plugins_dir="$NVIM_CONFIG_DIR/lua/plugins"
local lazy_file="$lazy_plugins_dir/vimlantis.lua"
echo ""
echo -e "${BLUE}Configuring Lazy.nvim integration...${NC}"
read -p "Create or update Lazy.nvim spec at $lazy_file? [Y/n]: " create_lazy_spec
if [[ "$create_lazy_spec" =~ ^[Nn]$ ]]; then
echo -e "${YELLOW}Skipping Lazy.nvim spec creation${NC}"
return
fi
if [ ! -d "$lazy_plugins_dir" ]; then
echo "Creating $lazy_plugins_dir..."
mkdir -p "$lazy_plugins_dir"
fi
if [ -f "$lazy_file" ]; then
local backup_file="${lazy_file}.bak.$(date +%s)"
cp "$lazy_file" "$backup_file"
echo -e "${YELLOW}Existing vimlantis.lua backed up to $backup_file${NC}"
fi
local local_plugin_path="${SCRIPT_DIR/#$HOME/~}"
local escaped_path
escaped_path=$(printf '%s' "$local_plugin_path" | sed 's/\\/\\\\/g; s/"/\\"/g')
cat > "$lazy_file" << EOF
return {
{
-- Use the local path instead of cloning from GitHub
dir = vim.fn.expand("${escaped_path}"),
lazy = false, -- load immediately
config = function()
require("vimlantis").setup({
port = 3000,
auto_open_browser = true,
})
end,
keys = {
{ "<leader>vl", "<cmd>Vimlantis<cr>", desc = "Open Vimlantis" },
{ "<leader>vc", "<cmd>VimlantisClose<cr>", desc = "Close Vimlantis" },
},
},
}
EOF
echo -e "${GREEN}✓ Lazy.nvim spec created at $lazy_file${NC}"
echo "Run ':Lazy sync' in Neovim to ensure Vimlantis is loaded."
}
# Check prerequisites
echo -e "${BLUE}Checking prerequisites...${NC}"
if ! command -v node &> /dev/null; then
echo -e "${RED}Error: Node.js is not installed even after attempting automatic installation.${NC}"
echo "Please install Node.js (v16 or higher) from https://nodejs.org and re-run this script."
exit 1
fi
NODE_VERSION=$(node --version | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -lt 16 ]; then
echo -e "${RED}Error: Node.js version 16 or higher is required${NC}"
echo "Current version: $(node --version)"
exit 1
fi
if ! command -v nvim &> /dev/null; then
echo -e "${YELLOW}Warning: Neovim is not installed${NC}"
echo "You can still use Vimlantis standalone, but you'll need Neovim for plugin functionality"
fi
echo -e "${GREEN}✓ Prerequisites check passed${NC}"
echo ""
# Install npm dependencies
echo -e "${BLUE}Installing npm dependencies...${NC}"
cd "$SCRIPT_DIR"
npm install
echo -e "${GREEN}✓ Dependencies installed${NC}"
echo ""
# Determine Neovim config directory
if [ -n "$XDG_CONFIG_HOME" ]; then
NVIM_CONFIG_DIR="$XDG_CONFIG_HOME/nvim"
else
NVIM_CONFIG_DIR="$HOME/.config/nvim"
fi
# Ask about plugin installation method
echo -e "${BLUE}How would you like to install the Neovim plugin?${NC}"
echo "1) Automatic Install (Recommended - No config needed)"
echo "2) Manual Setup (I'll configure it myself)"
echo "3) Skip plugin installation (Standalone use only)"
echo ""
read -p "Enter choice [1-3]: " INSTALL_CHOICE
case $INSTALL_CHOICE in
1)
PLUGIN_DIR="$NVIM_CONFIG_DIR/pack/plugins/start/vimlantis"
echo ""
echo -e "${BLUE}Installing to: $PLUGIN_DIR${NC}"
# Create plugin directory
mkdir -p "$PLUGIN_DIR"
# Copy plugin files
echo "Copying plugin files..."
cp -r "$SCRIPT_DIR/lua" "$PLUGIN_DIR/"
cp -r "$SCRIPT_DIR/server" "$PLUGIN_DIR/"
cp -r "$SCRIPT_DIR/public" "$PLUGIN_DIR/"
cp -r "$SCRIPT_DIR/plugin" "$PLUGIN_DIR/"
cp "$SCRIPT_DIR/package.json" "$PLUGIN_DIR/"
cp "$SCRIPT_DIR/package-lock.json" "$PLUGIN_DIR/"
# Install npm dependencies in the plugin directory
echo "Installing dependencies in plugin directory..."
cd "$PLUGIN_DIR"
npm install --production
echo -e "${GREEN}✓ Plugin installed to $PLUGIN_DIR${NC}"
echo ""
echo -e "${GREEN}The plugin will automatically load when you start Neovim!${NC}"
echo "Just open Neovim and type: ${YELLOW}:Vimlantis${NC}"
echo ""
echo -e "${BLUE}Optional: Customize settings by adding this to your config:${NC}"
echo ""
echo -e "${YELLOW}require('vimlantis').setup({${NC}"
echo -e "${YELLOW} port = 3000,${NC}"
echo -e "${YELLOW} auto_open_browser = true,${NC}"
echo -e "${YELLOW}}${NC}"
echo ""
# Offer Lazy.nvim integration
if [ -d "$NVIM_CONFIG_DIR" ]; then
create_lazy_spec_file
fi
;;
2)
echo ""
echo -e "${GREEN}Manual Setup Instructions:${NC}"
echo ""
echo "Add this to your Neovim config (e.g., ~/.config/nvim/init.lua):"
echo ""
echo -e "${YELLOW}-- Add Vimlantis to runtime path${NC}"
echo "vim.opt.runtimepath:append('$SCRIPT_DIR')"
echo ""
echo -e "${YELLOW}-- Setup Vimlantis${NC}"
echo "require('vimlantis').setup({"
echo " port = 3000,"
echo " auto_open_browser = true,"
echo "})"
echo ""
echo -e "${YELLOW}-- Optional: Add keybindings${NC}"
echo "vim.keymap.set('n', '<leader>vl', '<cmd>Vimlantis<cr>', { desc = 'Open Vimlantis' })"
echo "vim.keymap.set('n', '<leader>vc', '<cmd>VimlantisClose<cr>', { desc = 'Close Vimlantis' })"
echo ""
;;
3)
echo ""
echo -e "${YELLOW}Skipping plugin installation${NC}"
echo "You can use Vimlantis in standalone mode with: npm run dev"
echo ""
;;
*)
echo -e "${RED}Invalid choice${NC}"
exit 1
;;
esac
# Ask about creating a global command
echo ""
read -p "Create a global 'vimlantis' command? [y/N]: " CREATE_COMMAND
if [[ "$CREATE_COMMAND" =~ ^[Yy]$ ]]; then
# Determine bin directory
if [ -d "$HOME/.local/bin" ]; then
BIN_DIR="$HOME/.local/bin"
elif [ -d "$HOME/bin" ]; then
BIN_DIR="$HOME/bin"
else
echo "Creating $HOME/.local/bin directory..."
mkdir -p "$HOME/.local/bin"
BIN_DIR="$HOME/.local/bin"
fi
COMMAND_PATH="$BIN_DIR/vimlantis"
# Create the command script
cat > "$COMMAND_PATH" << EOF
#!/bin/bash
# Vimlantis global command
# Save the current directory (where user runs the command)
CURRENT_DIR="\$(pwd)"
# Change to vimlantis directory to run the server
VIMLANTIS_DIR="$SCRIPT_DIR"
cd "\$VIMLANTIS_DIR"
# Run server with the user's current directory
node server/index.js --port 3000 --cwd "\$CURRENT_DIR" --open "\$@"
EOF
chmod +x "$COMMAND_PATH"
echo -e "${GREEN}✓ Created global command: $COMMAND_PATH${NC}"
echo ""
# Check if bin directory is in PATH
if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
echo -e "${YELLOW}Note: $BIN_DIR is not in your PATH${NC}"
echo "Add this to your ~/.bashrc or ~/.zshrc:"
echo ""
echo "export PATH=\"\$PATH:$BIN_DIR\""
echo ""
fi
echo "You can now run 'vimlantis' from any directory to start the server"
fi
echo ""
echo -e "${GREEN}🎉 Installation complete!${NC}"
echo ""
echo "Next steps:"
echo " • Test standalone: cd $SCRIPT_DIR && npm run dev"
echo " • Use in Neovim: Open nvim and run :Vimlantis"
echo " • Read the docs: cat $SCRIPT_DIR/README.md"
echo ""