summaryrefslogtreecommitdiff
path: root/utils/installer
diff options
context:
space:
mode:
Diffstat (limited to 'utils/installer')
-rw-r--r--utils/installer/config.example.lua2
-rw-r--r--utils/installer/install.ps180
-rwxr-xr-xutils/installer/install.sh104
-rwxr-xr-xutils/installer/uninstall.sh26
4 files changed, 123 insertions, 89 deletions
diff --git a/utils/installer/config.example.lua b/utils/installer/config.example.lua
index 8f124ad3..03906ada 100644
--- a/utils/installer/config.example.lua
+++ b/utils/installer/config.example.lua
@@ -18,7 +18,7 @@ lvim.leader = "space"
-- add your own keymapping
lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
-- unmap a default keymapping
--- lvim.keys.normal_mode["<C-Up>"] = ""
+-- lvim.keys.normal_mode["<C-Up>"] = false
-- edit a default keymapping
-- lvim.keys.normal_mode["<C-q>"] = ":q<cr>"
diff --git a/utils/installer/install.ps1 b/utils/installer/install.ps1
index c46bbfc2..0823032a 100644
--- a/utils/installer/install.ps1
+++ b/utils/installer/install.ps1
@@ -64,20 +64,8 @@ function main($cliargs) {
backup_old_config
__add_separator "80"
-
- if ($cliargs.Contains("--overwrite")) {
- Write-Output "!!Warning!! -> Removing all lunarvim related config because of the --overwrite flag"
- $answer = Read-Host "Would you like to continue? [y]es or [n]o "
- if ("$answer" -ne "y" -and "$answer" -ne "Y") {
- exit 1
- }
-
- foreach ($dir in $__lvim_dirs) {
- if (Test-Path "$dir") {
- Remove-Item -Force -Recurse "$dir"
- }
- }
- }
+
+ verify_lvim_dirs
if (Test-Path "$env:LUNARVIM_RUNTIME_DIR\site\pack\packer\start\packer.nvim") {
Write-Output "Packer already installed"
@@ -153,7 +141,7 @@ function check_system_deps() {
function install_nodejs_deps() {
try {
check_system_dep "node"
- Invoke-Command npm install -g neovim tree-sitter-cli -ErrorAction Break
+ Invoke-Command npm install -g neovim tree-sitter-cli -ErrorAction Break
}
catch {
print_missing_dep_msg "$dep"
@@ -211,6 +199,29 @@ function setup_shim() {
Copy-Item "$env:LUNARVIM_RUNTIME_DIR\lvim\utils\bin\lvim.ps1" -Destination "$INSTALL_PREFIX\bin\lvim.ps1" -Force
}
+function verify_lvim_dirs() {
+ if ($cliargs.Contains("--overwrite")) {
+ Write-Output "!!Warning!! -> Removing all lunarvim related config because of the --overwrite flag"
+ $answer = Read-Host "Would you like to continue? [y]es or [n]o "
+ if ("$answer" -ne "y" -and "$answer" -ne "Y") {
+ exit 1
+ }
+
+ foreach ($dir in $__lvim_dirs) {
+ if (Test-Path "$dir") {
+ Remove-Item -Force -Recurse "$dir"
+ }
+ }
+ }
+
+ foreach ($dir in $__lvim_dirs) {
+ if ((Test-Path "$dir") -eq $false) {
+ New-Item "$dir" -ItemType Directory
+ }
+ }
+
+}
+
function setup_lvim() {
Write-Output "Installing LunarVim shim"
@@ -218,30 +229,26 @@ function setup_lvim() {
Write-Output "Preparing Packer setup"
- if ((Test-Path "$env:LUNARVIM_CONFIG_DIR") -eq $false) {
- New-Item "$env:LUNARVIM_CONFIG_DIR" -ItemType Directory
- }
-
if (Test-Path "$env:LUNARVIM_CONFIG_DIR\config.lua") {
Remove-Item -Force "$env:LUNARVIM_CONFIG_DIR\config.lua"
}
Out-File -FilePath "$env:LUNARVIM_CONFIG_DIR\config.lua"
- Write-Output "Packer setup complete"
+ Write-Output "Packer setup complete"
- __add_separator "80"
+ __add_separator "80"
- Copy-Item "$env:LUNARVIM_RUNTIME_DIR\lvim\utils\installer\config.example.lua" "$env:LUNARVIM_CONFIG_DIR\config.lua"
+ Copy-Item "$env:LUNARVIM_RUNTIME_DIR\lvim\utils\installer\config.example.lua" "$env:LUNARVIM_CONFIG_DIR\config.lua"
- $answer = Read-Host $(`
- "Would you like to create an alias inside your Powershell profile?`n" +`
- "(This enables you to start lvim with the command 'lvim') [y]es or [n]o (default: no)" )
- if ("$answer" -eq "y" -and "$answer" -eq "Y") {
- create_alias
- }
+ $answer = Read-Host $(`
+ "Would you like to create an alias inside your Powershell profile?`n" + `
+ "(This enables you to start lvim with the command 'lvim') [y]es or [n]o (default: no)" )
+ if ("$answer" -eq "y" -and "$answer" -eq "Y") {
+ create_alias
+ }
- __add_separator "80"
+ __add_separator "80"
Write-Output "Thank you for installing LunarVim!!"
Write-Output "You can start it by running: $INSTALL_PREFIX\bin\lvim.ps1"
@@ -267,15 +274,16 @@ function __add_separator($div_width) {
}
function create_alias {
- if($null -eq $(Get-Alias | Select-String "lvim")){
- Add-Content -Path $PROFILE -Value $(-join @('Set-Alias lvim "', "$INSTALL_PREFIX", '\bin\lvim.ps1"'))
+ if ($null -eq $(Get-Alias | Select-String "lvim")) {
+ Add-Content -Path $PROFILE -Value $( -join @('Set-Alias lvim "', "$INSTALL_PREFIX", '\bin\lvim.ps1"'))
- Write-Output ""
- Write-Host 'To use the new alias in this window reload your profile with ". $PROFILE".' -ForegroundColor Yellow
+ Write-Output ""
+ Write-Host 'To use the new alias in this window reload your profile with ". $PROFILE".' -ForegroundColor Yellow
- }else {
- Write-Output "Alias is already set and will not be reset."
- }
+ }
+ else {
+ Write-Output "Alias is already set and will not be reset."
+ }
}
main "$args"
diff --git a/utils/installer/install.sh b/utils/installer/install.sh
index e7631999..d420baed 100755
--- a/utils/installer/install.sh
+++ b/utils/installer/install.sh
@@ -12,9 +12,10 @@ declare -r XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}"
declare -r LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$XDG_DATA_HOME/lunarvim"}"
declare -r LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/lvim"}"
+declare -r LUNARVIM_BASE_DIR="${LUNARVIM_BASE_DIR:-"$LUNARVIM_RUNTIME_DIR/lvim"}"
+
# TODO: Use a dedicated cache directory #1256
declare -r LUNARVIM_CACHE_DIR="$XDG_CACHE_HOME/nvim"
-declare -r LUNARVIM_PACK_DIR="$LUNARVIM_RUNTIME_DIR/site/pack"
declare BASEDIR
BASEDIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
@@ -105,28 +106,20 @@ function main() {
[ "$answer" != "${answer#[Yy]}" ] && install_rust_deps
fi
- msg "Backing up old LunarVim configuration"
backup_old_config
- if [ "$ARGS_OVERWRITE" -eq 1 ]; then
- for dir in "${__lvim_dirs[@]}"; do
- [ -d "$dir" ] && rm -rf "$dir"
- done
- fi
-
- install_packer
+ verify_lvim_dirs
- if [ -e "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" ]; then
- update_lvim
+ if [ "$ARGS_LOCAL" -eq 1 ]; then
+ link_local_lvim
+ elif [ -d "$LUNARVIM_BASE_DIR" ]; then
+ validate_lunarvim_files
else
- if [ "$ARGS_LOCAL" -eq 1 ]; then
- link_local_lvim
- else
- clone_lvim
- fi
- setup_lvim
+ clone_lvim
fi
+ setup_lvim
+
msg "Thank you for installing LunarVim!!"
echo "You can start it by running: $INSTALL_PREFIX/bin/lvim"
echo "Do not forget to use a font with glyphs (icons) support [https://github.com/ryanoasis/nerd-fonts]"
@@ -177,6 +170,26 @@ function print_missing_dep_msg() {
fi
}
+function check_neovim_min_version() {
+ # TODO: consider locking the requirement to 0.6+
+ local verify_version_cmd='if !has("nvim-0.5.1") | cquit | else | quit | endif'
+
+ # exit with an error if min_version not found
+ if ! nvim --headless -u NONE -c "$verify_version_cmd"; then
+ echo "[ERROR]: LunarVim requires at least Neovim v0.5.1 or higher"
+ exit 1
+ fi
+}
+
+function validate_lunarvim_files() {
+ local verify_version_cmd='if v:errmsg != "" | cquit | else | quit | endif'
+ if ! "$INSTALL_PREFIX/bin/lvim" --headless -c 'LvimUpdate' -c "$verify_version_cmd" &>/dev/null; then
+ msg "Removing old installation files"
+ rm -rf "$LUNARVIM_BASE_DIR"
+ clone_lvim
+ fi
+}
+
function check_system_deps() {
if ! command -v git &>/dev/null; then
print_missing_dep_msg "git"
@@ -186,6 +199,7 @@ function check_system_deps() {
print_missing_dep_msg "neovim"
exit 1
fi
+ check_neovim_min_version
}
function __install_nodejs_deps_npm() {
@@ -253,15 +267,28 @@ function install_rust_deps() {
echo "All Rust dependencies are successfully installed"
}
+function verify_lvim_dirs() {
+ if [ "$ARGS_OVERWRITE" -eq 1 ]; then
+ for dir in "${__lvim_dirs[@]}"; do
+ [ -d "$dir" ] && rm -rf "$dir"
+ done
+ fi
+
+ for dir in "${__lvim_dirs[@]}"; do
+ mkdir -p "$dir"
+ done
+}
+
function backup_old_config() {
for dir in "${__lvim_dirs[@]}"; do
- # we create an empty folder for subsequent commands \
- # that require an existing directory
- mkdir -p "$dir" "$dir.bak"
+ if [ ! -d "$dir" ]; then
+ continue
+ fi
+ mkdir -p "$dir.bak"
touch "$dir/ignore"
+ msg "Backing up old $dir to $dir.bak"
if command -v rsync &>/dev/null; then
- rsync --archive -hh --partial --progress --cvs-exclude \
- --modify-window=1 "$dir"/ "$dir.bak"
+ rsync --archive -hh --stats --partial --cvs-exclude "$dir"/ "$dir.bak"
else
OS="$(uname -s)"
case "$OS" in
@@ -277,25 +304,13 @@ function backup_old_config() {
esac
fi
done
- echo "Backup operation complete"
-}
-
-function install_packer() {
- if [ -e "$LUNARVIM_PACK_DIR/packer/start/packer.nvim" ]; then
- msg "Packer already installed"
- else
- if ! git clone --depth 1 "https://github.com/wbthomason/packer.nvim" \
- "$LUNARVIM_PACK_DIR/packer/start/packer.nvim"; then
- msg "Failed to clone Packer. Installation failed."
- exit 1
- fi
- fi
+ msg "Backup operation complete"
}
function clone_lvim() {
msg "Cloning LunarVim configuration"
if ! git clone --branch "$LV_BRANCH" \
- --depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_RUNTIME_DIR/lvim"; then
+ --depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_BASE_DIR"; then
echo "Failed to clone repository. Installation failed."
exit 1
fi
@@ -305,14 +320,13 @@ function link_local_lvim() {
echo "Linking local LunarVim repo"
# Detect whether it's a symlink or a folder
- if [ -d "$LUNARVIM_RUNTIME_DIR/lvim" ]; then
+ if [ -d "$LUNARVIM_BASE_DIR" ]; then
echo "Removing old installation files"
- rm -rf "$LUNARVIM_RUNTIME_DIR/lvim"
+ rm -rf "$LUNARVIM_BASE_DIR"
fi
- mkdir -p "$LUNARVIM_RUNTIME_DIR"
- echo " - $BASEDIR -> $LUNARVIM_RUNTIME_DIR/lvim"
- ln -s -f "$BASEDIR" "$LUNARVIM_RUNTIME_DIR/lvim"
+ echo " - $BASEDIR -> $LUNARVIM_BASE_DIR"
+ ln -s -f "$BASEDIR" "$LUNARVIM_BASE_DIR"
}
function setup_shim() {
@@ -351,9 +365,9 @@ function setup_lvim() {
setup_shim
- echo "Preparing Packer setup"
+ cp "$LUNARVIM_BASE_DIR/utils/installer/config.example.lua" "$LUNARVIM_CONFIG_DIR/config.lua"
- cp "$LUNARVIM_RUNTIME_DIR/lvim/utils/installer/config.example.lua" "$LUNARVIM_CONFIG_DIR/config.lua"
+ echo "Preparing Packer setup"
"$INSTALL_PREFIX/bin/lvim" --headless \
-c 'autocmd User PackerComplete quitall' \
@@ -362,10 +376,6 @@ function setup_lvim() {
echo "Packer setup complete"
}
-function update_lvim() {
- "$INSTALL_PREFIX/bin/lvim" --headless +'LvimUpdate' +q
-}
-
function print_logo() {
cat <<'EOF'
diff --git a/utils/installer/uninstall.sh b/utils/installer/uninstall.sh
index 31007984..236d657f 100755
--- a/utils/installer/uninstall.sh
+++ b/utils/installer/uninstall.sh
@@ -13,8 +13,6 @@ declare -r LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/lvim"}"
# TODO: Use a dedicated cache directory #1256
declare -r LUNARVIM_CACHE_DIR="$XDG_CACHE_HOME/nvim"
-LVIM_BIN="$(which lvim 2>/dev/null)"
-
declare -a __lvim_dirs=(
"$LUNARVIM_CONFIG_DIR"
"$LUNARVIM_RUNTIME_DIR"
@@ -44,15 +42,33 @@ function parse_arguments() {
done
}
-function main() {
- parse_arguments "$@"
+function remove_lvim_dirs() {
for dir in "${__lvim_dirs[@]}"; do
rm -rf "$dir"
if [ "$ARGS_REMOVE_BACKUPS" -eq 1 ]; then
rm -rf "$dir.bak"
fi
done
- rm -f "$LVIM_BIN"
+}
+
+function remove_lvim_bin() {
+ local legacy_bin="/usr/local/bin/lvim "
+ if [ -x "$legacy_bin" ]; then
+ echo "Error! Unable to remove $legacy_bin without elevation. Please remove manually."
+ exit 1
+ fi
+
+ lvim_bin="$(command -v lvim 2>/dev/null)"
+ rm -f "$lvim_bin"
+}
+
+function main() {
+ parse_arguments "$@"
+ echo "Removing LunarVim binary..."
+ remove_lvim_bin
+ echo "Removing LunarVim directories..."
+ remove_lvim_dirs
+ echo "Uninstalled LunarVim!"
}
main "$@"