diff options
Diffstat (limited to 'mac/.config/LunarVim/utils/installer')
9 files changed, 1136 insertions, 0 deletions
diff --git a/mac/.config/LunarVim/utils/installer/config.example.lua b/mac/.config/LunarVim/utils/installer/config.example.lua new file mode 100644 index 0000000..9776f64 --- /dev/null +++ b/mac/.config/LunarVim/utils/installer/config.example.lua @@ -0,0 +1,5 @@ +-- Read the docs: https://www.lunarvim.org/docs/configuration +-- Example configs: https://github.com/LunarVim/starter.lvim +-- Video Tutorials: https://www.youtube.com/watch?v=sFA9kX-Ud_c&list=PLhoH5vyxr6QqGu0i7tt_XoVK9v-KvZ3m6 +-- Forum: https://www.reddit.com/r/lunarvim/ +-- Discord: https://discord.com/invite/Xb9B4Ny diff --git a/mac/.config/LunarVim/utils/installer/config_win.example.lua b/mac/.config/LunarVim/utils/installer/config_win.example.lua new file mode 100644 index 0000000..1fccb5a --- /dev/null +++ b/mac/.config/LunarVim/utils/installer/config_win.example.lua @@ -0,0 +1,27 @@ +-- Read the docs: https://www.lunarvim.org/docs/configuration +-- Example configs: https://github.com/LunarVim/starter.lvim +-- Video Tutorials: https://www.youtube.com/watch?v=sFA9kX-Ud_c&list=PLhoH5vyxr6QqGu0i7tt_XoVK9v-KvZ3m6 +-- Forum: https://www.reddit.com/r/lunarvim/ +-- Discord: https://discord.com/invite/Xb9B4Ny + +-- Enable powershell as your default shell +vim.opt.shell = "pwsh.exe" +vim.opt.shellcmdflag = + "-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;" +vim.cmd [[ + let &shellredir = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode' + let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode' + set shellquote= shellxquote= + ]] + +-- Set a compatible clipboard manager +vim.g.clipboard = { + copy = { + ["+"] = "win32yank.exe -i --crlf", + ["*"] = "win32yank.exe -i --crlf", + }, + paste = { + ["+"] = "win32yank.exe -o --lf", + ["*"] = "win32yank.exe -o --lf", + }, +} diff --git a/mac/.config/LunarVim/utils/installer/install-neovim-from-release b/mac/.config/LunarVim/utils/installer/install-neovim-from-release new file mode 100755 index 0000000..f041f77 --- /dev/null +++ b/mac/.config/LunarVim/utils/installer/install-neovim-from-release @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +set -eu pipefall + +declare -r LV_INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local"}" +declare -r RELEASE_VER="${RELEASE_VER:-latest}" # can be set to nightly + +declare ARCHIVE_NAME +declare OS + +OS="$(uname -s)" + +if [ "$OS" == "Linux" ]; then + ARCHIVE_NAME="nvim-linux64" +elif [ "$OS" == "Darwin" ]; then + ARCHIVE_NAME="nvim-macos-x86_64" +else + echo "$OS platform is not supported currently" + exit 1 +fi + +if [[ "${RELEASE_VER}" == "latest" ]]; then + declare -r RELEASE_URL="https://github.com/neovim/neovim/releases/${RELEASE_VER}/download/${ARCHIVE_NAME}.tar.gz" +else + declare -r RELEASE_URL="https://github.com/neovim/neovim/releases/download/${RELEASE_VER}/${ARCHIVE_NAME}.tar.gz" +fi +declare -r CHECKSUM_URL="$RELEASE_URL.sha256sum" + +DOWNLOAD_DIR="$(mktemp -d)" +readonly DOWNLOAD_DIR + +RELEASE_SHA="$(curl -Ls "$CHECKSUM_URL" | awk '{print $1}')" +readonly RELEASE_SHA + +function main() { + if [ ! -d "$LV_INSTALL_PREFIX" ]; then + mkdir -p "$LV_INSTALL_PREFIX" || __invalid__prefix__handler + fi + download_neovim + verify_neovim + install_neovim +} + +function download_neovim() { + echo "Downloading Neovim's binary from $RELEASE_VER release.." + if ! curl --progress-bar --fail -L "$RELEASE_URL" -o "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz"; then + echo "Download failed. Check that the release/filename are correct." + exit 1 + fi + echo "Download complete!" +} + +function verify_neovim() { + echo "Verifying the installation.." + DOWNLOADED_SHA="$(openssl dgst -sha256 "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz" | awk '{print $2}')" + + if [ "$RELEASE_SHA" != "$DOWNLOADED_SHA" ]; then + echo "Error! checksum mismatch." + echo "Expected: $RELEASE_SHA but got: $DOWNLOADED_SHA" + exit 1 + fi + echo "Verification complete!" +} + +function install_neovim() { + + echo "Installing Neovim.." + pushd "$DOWNLOAD_DIR" + tar -xzf "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz" + popd + # https://dev.to/ackshaey/macos-vs-linux-the-cp-command-will-trip-you-up-2p00 + cp -r "$DOWNLOAD_DIR/$ARCHIVE_NAME/." "$LV_INSTALL_PREFIX" + echo "Installation complete!" + echo "Now you can run $LV_INSTALL_PREFIX/bin/nvim" +} + +function __invalid__prefix__handler() { + echo "Error! Invalid value for LV_INSTALL_PREFIX: [$INSTALL_PREFIX]" + echo "Please verify that the folder exists and re-run the installer!" + exit 1 +} + +main "$@" diff --git a/mac/.config/LunarVim/utils/installer/install.ps1 b/mac/.config/LunarVim/utils/installer/install.ps1 new file mode 100644 index 0000000..5aef434 --- /dev/null +++ b/mac/.config/LunarVim/utils/installer/install.ps1 @@ -0,0 +1,305 @@ +#Requires -Version 7.1 +$ErrorActionPreference = "Stop" # exit when command fails +if ($PSVersionTable.PSVersion -lt 7.1) { + Write-Error "Powershell version needs to be greater than 7.1!" +} + +# set script variables +$LV_BRANCH = $LV_BRANCH ?? "master" +$LV_REMOTE = $LV_REMOTE ?? "lunarvim/lunarvim.git" +$INSTALL_PREFIX = $INSTALL_PREFIX ?? "$HOME\.local" + +$env:XDG_DATA_HOME = $env:XDG_DATA_HOME ?? $env:APPDATA +$env:XDG_CONFIG_HOME = $env:XDG_CONFIG_HOME ?? $env:LOCALAPPDATA +$env:XDG_CACHE_HOME = $env:XDG_CACHE_HOME ?? $env:TEMP + +$env:LUNARVIM_RUNTIME_DIR = $env:LUNARVIM_RUNTIME_DIR ?? "$env:XDG_DATA_HOME\lunarvim" +$env:LUNARVIM_CONFIG_DIR = $env:LUNARVIM_CONFIG_DIR ?? "$env:XDG_CONFIG_HOME\lvim" +$env:LUNARVIM_CACHE_DIR = $env:LUNARVIM_CACHE_DIR ?? "$env:XDG_CACHE_HOME\lvim" +$env:LUNARVIM_BASE_DIR = $env:LUNARVIM_BASE_DIR ?? "$env:LUNARVIM_RUNTIME_DIR\lvim" + +$__lvim_dirs = ( + $env:LUNARVIM_BASE_DIR, + $env:LUNARVIM_RUNTIME_DIR, + $env:LUNARVIM_CONFIG_DIR, + $env:LUNARVIM_CACHE_DIR +) + +function __add_separator($div_width) { + "-" * $div_width + Write-Output "" +} + +function msg($text){ + Write-Output $text + __add_separator "80" +} + +function main($cliargs) { + + print_logo + + 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 + } + uninstall_lvim + } + if ($cliargs.Contains("--local") -or $cliargs.Contains("--testing")) { + msg "Using local LunarVim installation" + local_install + exit + } + + msg "Checking dependencies.." + check_system_deps + + $answer = Read-Host "Would you like to check lunarvim's NodeJS dependencies? [y]es or [n]o (default: no) " + if ("$answer" -eq "y" -or "$answer" -eq "Y") { + install_nodejs_deps + } + + $answer = Read-Host "Would you like to check lunarvim's Python dependencies? [y]es or [n]o (default: no) " + if ("$answer" -eq "y" -or "$answer" -eq "Y") { + install_python_deps + } + + + if (Test-Path "$env:LUNARVIM_BASE_DIR\init.lua" ) { + msg "Updating LunarVim" + validate_lunarvim_files + } + else { + msg "Cloning Lunarvim" + clone_lvim + setup_lvim + } +} + +function print_missing_dep_msg($dep) { + Write-Output "[ERROR]: Unable to find dependency [$dep]" + Write-Output "Please install it first and re-run the installer." +} + +$winget_package_matrix=@{"git" = "Git.Git"; "nvim" = "Neovim.Neovim"; "make" = "GnuWin32.Make"; "node" = "OpenJS.NodeJS"; "pip" = "Python.Python.3.11"} +$winget_additional_arguments_matrix=@{"git" = "--source winget --interactive"; "nvim" = "--interactive"; "make" = "--interactive"; "node" = ""; "pip" = ""} + +$scoop_package_matrix=@{"git" = "git"; "nvim" = "neovim"; "make" = "make"; "node" = "nodejs"; "pip" = "python"} + +function install_system_package($dep) { + # Make installers sometimes have a problem when adding make to path + Write-Output "WARNING: Preparing 'make' installation. The make directory ('C:\Program Files (x86)\GnuWin32\bin') might not be added to the PATH by the installer, and you might have to manually to the PATH!" + if (Get-Command -Name "winget" -ErrorAction SilentlyContinue) { + Write-Output "Attempting to install dependency [$dep] with winget" + + $command="winget" + $command_arguments = "-e --id $($winget_package_matrix[$dep]) $($winget_additional_arguments_matrix[$dep])".Trim() -split ' ' + } + elseif (Get-Command -Name "scoop" -ErrorAction SilentlyContinue) { + Write-Output "Attempting to install dependency [$dep] with scoop" + # TODO: check if it's fine to not run it with --global + $command = "scoop" + $command_arguments = "$($scoop_package_matrix[$dep])".Trim() -split ' ' + } + else { + print_missing_dep_msg "$dep" + exit 1 + } + + try { + & $command install $command_arguments + # Refresh the path after installation + $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User") + } catch { + Write-Output "An error occurred: $_" + exit 1 + } +} + +function check_system_dep($dep) { + try { + Get-Command -Name $dep -ErrorAction Stop | Out-Null + } + catch { + install_system_package "$dep" + } +} + +function check_system_deps() { + check_system_dep "git" + check_system_dep "nvim" + check_system_dep "make" +} + +function install_nodejs_deps() { + $dep = "node" + try { + check_system_dep "$dep" + Invoke-Command -ScriptBlock { npm install --global neovim tree-sitter-cli } -ErrorAction Break + } + catch { + print_missing_dep_msg "$dep" + } +} + +function install_python_deps() { + $dep = "pip" + try { + check_system_dep "$dep" + Invoke-Command -ScriptBlock { python -m pip install --user pynvim } -ErrorAction Break + } + catch { + print_missing_dep_msg "$dep" + } +} + +function backup_old_config() { + $src = "$env:LUNARVIM_CONFIG_DIR" + if (Test-Path $src) { + New-Item "$src.old" -ItemType Directory -Force | Out-Null + Copy-Item -Force -Recurse "$src\*" "$src.old\." | Out-Null + } + msg "Backup operation complete" +} + + +function local_install() { + verify_lvim_dirs + $repoDir = git rev-parse --show-toplevel + $gitLocalCloneCmd = git clone --progress "$repoDir" "$env:LUNARVIM_BASE_DIR" + Invoke-Command -ErrorAction Stop -ScriptBlock { $gitLocalCloneCmd; setup_lvim } +} + +function clone_lvim() { + try { + $gitCloneCmd = git clone --progress --depth 1 --branch "$LV_BRANCH" ` + "https://github.com/$LV_REMOTE" ` + "$env:LUNARVIM_BASE_DIR" + Invoke-Command -ErrorAction Stop -ScriptBlock { $gitCloneCmd } + } + catch { + msg "Failed to clone repository. Installation failed." + exit 1 + } +} + +function setup_shim() { + if ((Test-Path "$INSTALL_PREFIX\bin") -eq $false) { + New-Item "$INSTALL_PREFIX\bin" -ItemType Directory | Out-Null + } + + Copy-Item -Force "$env:LUNARVIM_BASE_DIR\utils\bin\lvim.ps1" "$INSTALL_PREFIX\bin\lvim.ps1" +} + +function uninstall_lvim() { + foreach ($dir in $__lvim_dirs) { + if (Test-Path "$dir") { + Remove-Item -Force -Recurse "$dir" + } + } +} + +function verify_lvim_dirs() { + foreach ($dir in $__lvim_dirs) { + if ((Test-Path "$dir") -eq $false) { + New-Item "$dir" -ItemType Directory | Out-Null + } + } + backup_old_config +} + + +function setup_lvim() { + msg "Installing LunarVim shim" + setup_shim + + msg "Installing sample configuration" + + if (Test-Path "$env:LUNARVIM_CONFIG_DIR\config.lua") { + Move-Item "$env:LUNARVIM_CONFIG_DIR\config.lua" "$env:LUNARVIM_CONFIG_DIR\config.lua.old" + } + + New-Item -ItemType File -Path "$env:LUNARVIM_CONFIG_DIR\config.lua" | Out-Null + + $exampleConfig = "$env:LUNARVIM_BASE_DIR\utils\installer\config_win.example.lua" + Copy-Item -Force "$exampleConfig" "$env:LUNARVIM_CONFIG_DIR\config.lua" + + Write-Host "Make sure to run `:Lazy sync` at first launch" -ForegroundColor Green + + create_alias + + msg "Thank you for installing LunarVim!!" + + Write-Output "You can start it by running: $INSTALL_PREFIX\bin\lvim.ps1" + Write-Output "Do not forget to use a font with glyphs (icons) support [https://github.com/ryanoasis/nerd-fonts]" +} + + +function validate_lunarvim_files() { + Set-Alias lvim "$INSTALL_PREFIX\bin\lvim.ps1" + try { + $verify_version_cmd="if !empty(v:errmsg) | cquit | else | quit | endif" + Invoke-Command -ScriptBlock { lvim --headless -c 'LvimUpdate' -c "$verify_version_cmd" } -ErrorAction SilentlyContinue + } + catch { + Write-Output "Unable to guarantee data integrity while updating. Please run `:LvimUpdate` manually instead." + exit 1 + } + Write-Output "Your LunarVim installation is now up to date!" +} + +function create_alias { + try { + $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)" ) + } + catch { + msg "Non-interactive mode detected. Skipping alias creation" + return + } + + if ("$answer" -ne "y" -or "$answer" -ne "Y") { + return + } + + $lvim_bin="$INSTALL_PREFIX\bin\lvim.ps1" + $lvim_alias = Get-Alias lvim -ErrorAction SilentlyContinue + + if ($lvim_alias.Definition -eq $lvim_bin) { + Write-Output "Alias is already set and will not be reset." + return + } + + try { + Get-Content $PROFILE -ErrorAction Stop + } + catch { + New-Item -Path $PROFILE -ItemType "file" -Force + } + + Add-Content -Path $PROFILE -Value $("`r`nSet-Alias lvim '$lvim_bin'") + + Write-Host 'To use the new alias in this window reload your profile with: `. $PROFILE`' -ForegroundColor Green +} + +function print_logo(){ + Write-Output " + + 88\ 88\ + 88 | \__| + 88 |88\ 88\ 888888$\ 888888\ 888888\ 88\ 88\ 88\ 888888\8888\ + 88 |88 | 88 |88 __88\ \____88\ 88 __88\\88\ 88 |88 |88 _88 _88\ + 88 |88 | 88 |88 | 88 | 888888$ |88 | \__|\88\88 / 88 |88 / 88 / 88 | + 88 |88 | 88 |88 | 88 |88 __88 |88 | \88$ / 88 |88 | 88 | 88 | + 88 |\888888 |88 | 88 |\888888$ |88 | \$ / 88 |88 | 88 | 88 | + \__| \______/ \__| \__| \_______|\__| \_/ \__|\__| \__| \__| + + " +} + +main "$args" diff --git a/mac/.config/LunarVim/utils/installer/install.sh b/mac/.config/LunarVim/utils/installer/install.sh new file mode 100755 index 0000000..0fd09bc --- /dev/null +++ b/mac/.config/LunarVim/utils/installer/install.sh @@ -0,0 +1,461 @@ +#!/usr/bin/env bash +set -eo pipefail + +OS="$(uname -s)" + +#Set branch to master unless specified by the user +declare -x LV_BRANCH="${LV_BRANCH:-"master"}" +declare -xr LV_REMOTE="${LV_REMOTE:-lunarvim/lunarvim.git}" +declare -xr INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local"}" + +declare -xr XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}" +declare -xr XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}" +declare -xr XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}" + +declare -xr NVIM_APPNAME="${NVIM_APPNAME:-"lvim"}" + +declare -xr LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$XDG_DATA_HOME/lunarvim"}" +declare -xr LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/$NVIM_APPNAME"}" +declare -xr LUNARVIM_CACHE_DIR="${LUNARVIM_CACHE_DIR:-"$XDG_CACHE_HOME/$NVIM_APPNAME"}" +declare -xr LUNARVIM_BASE_DIR="${LUNARVIM_BASE_DIR:-"$LUNARVIM_RUNTIME_DIR/$NVIM_APPNAME"}" + +declare -xr LUNARVIM_LOG_LEVEL="${LUNARVIM_LOG_LEVEL:-warn}" + +declare BASEDIR +BASEDIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" +BASEDIR="$(dirname -- "$(dirname -- "$BASEDIR")")" +readonly BASEDIR + +declare ARGS_LOCAL=0 +declare ARGS_OVERWRITE=0 +declare ARGS_INSTALL_DEPENDENCIES=1 +declare INTERACTIVE_MODE=1 +declare ADDITIONAL_WARNINGS="" + +declare -a __lvim_dirs=( + "$LUNARVIM_RUNTIME_DIR" + "$LUNARVIM_CACHE_DIR" + "$LUNARVIM_BASE_DIR" +) + +declare -a __npm_deps=( + "neovim" +) +# treesitter installed with brew causes conflicts #3738 +if ! command -v tree-sitter &>/dev/null; then + __npm_deps+=("tree-sitter-cli") +fi + +declare -a __rust_deps=( + "fd::fd-find" + "rg::ripgrep" +) + +function usage() { + echo "Usage: install.sh [<options>]" + echo "" + echo "Options:" + echo " -h, --help Print this help message" + echo " -l, --local Install local copy of LunarVim" + echo " -y, --yes Disable confirmation prompts (answer yes to all questions)" + echo " --overwrite Overwrite previous LunarVim configuration (a backup is always performed first)" + echo " --[no-]install-dependencies Whether to automatically install external dependencies (will prompt by default)" +} + +function parse_arguments() { + while [ "$#" -gt 0 ]; do + case "$1" in + -l | --local) + ARGS_LOCAL=1 + ;; + --overwrite) + ARGS_OVERWRITE=1 + ;; + -y | --yes) + INTERACTIVE_MODE=0 + ;; + --install-dependencies) + ARGS_INSTALL_DEPENDENCIES=1 + ;; + --no-install-dependencies) + ARGS_INSTALL_DEPENDENCIES=0 + ;; + -h | --help) + usage + exit 0 + ;; + esac + shift + done +} + +function msg() { + local text="$1" + local div_width="80" + printf "%${div_width}s\n" ' ' | tr ' ' - + printf "%s\n" "$text" +} + +function confirm() { + local question="$1" + while true; do + msg "$question" + read -p "[y]es or [n]o (default: no) : " -r answer + case "$answer" in + y | Y | yes | YES | Yes) + return 0 + ;; + n | N | no | NO | No | *[[:blank:]]* | "") + return 1 + ;; + *) + msg "Please answer [y]es or [n]o." + ;; + esac + done +} + +function stringify_array() { + echo -n "${@}" | sed 's/ /, /' +} + +function main() { + parse_arguments "$@" + + print_logo + + msg "Detecting platform for managing any additional neovim dependencies" + detect_platform + + check_system_deps + + if [ "$ARGS_INSTALL_DEPENDENCIES" -eq 1 ]; then + if [ "$INTERACTIVE_MODE" -eq 1 ]; then + if confirm "Would you like to install LunarVim's NodeJS/BunJS dependencies: $(stringify_array "${__npm_deps[@]}")?"; then + install_nodejs_deps + fi + if confirm "Would you like to install LunarVim's Rust dependencies: $(stringify_array "${__rust_deps[@]}")?"; then + install_rust_deps + fi + else + install_nodejs_deps + install_rust_deps + fi + fi + + remove_old_cache_files + + verify_lvim_dirs + + if [ "$ARGS_LOCAL" -eq 1 ]; then + link_local_lvim + else + clone_lvim + fi + + setup_lvim + + msg "$ADDITIONAL_WARNINGS" + msg "Thank you for installing LunarVim!!" + echo "You can start it by running: $INSTALL_PREFIX/bin/$NVIM_APPNAME" + echo "Do not forget to use a font with glyphs (icons) support [https://github.com/ryanoasis/nerd-fonts]" +} + +function detect_platform() { + case "$OS" in + Linux) + if [ -f "/etc/arch-release" ] || [ -f "/etc/artix-release" ]; then + RECOMMEND_INSTALL="sudo pacman -S" + elif [ -f "/etc/fedora-release" ] || [ -f "/etc/redhat-release" ]; then + RECOMMEND_INSTALL="sudo dnf install -y" + elif [ -f "/etc/gentoo-release" ]; then + RECOMMEND_INSTALL="emerge -tv" + else # assume debian based + RECOMMEND_INSTALL="sudo apt install -y" + fi + ;; + FreeBSD) + RECOMMEND_INSTALL="sudo pkg install -y" + ;; + NetBSD) + RECOMMEND_INSTALL="sudo pkgin install" + ;; + OpenBSD) + RECOMMEND_INSTALL="doas pkg_add" + ;; + Darwin) + RECOMMEND_INSTALL="brew install" + ;; + *) + echo "OS $OS is not currently supported." + exit 1 + ;; + esac +} + +function print_missing_dep_msg() { + if [ "$#" -eq 1 ]; then + echo "[ERROR]: Unable to find dependency [$1]" + echo "Please install it first and re-run the installer. Try: $RECOMMEND_INSTALL $1" + else + local cmds + cmds=$(for i in "$@"; do echo "$RECOMMEND_INSTALL $i"; done) + printf "[ERROR]: Unable to find dependencies [%s]" "$@" + printf "Please install any one of the dependencies and re-run the installer. Try: \n%s\n" "$cmds" + fi +} + +function check_neovim_min_version() { + local verify_version_cmd='if !has("nvim-0.9") | 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.9 or higher" + exit 1 + fi +} + +function verify_core_plugins() { + msg "Verifying core plugins" + if ! bash "$LUNARVIM_BASE_DIR/utils/ci/verify_plugins.sh"; then + echo "[ERROR]: Unable to verify plugins, make sure to manually run ':Lazy sync' when starting lvim for the first time." + exit 1 + fi + echo "Verification complete!" +} + +function validate_install_prefix() { + local prefix="$1" + case $PATH in + *"$prefix/bin"*) + return + ;; + esac + local profile="$HOME/.profile" + test -z "$ZSH_VERSION" && profile="$HOME/.zshenv" + ADDITIONAL_WARNINGS="[WARN] the folder $prefix/bin is not on PATH, consider adding 'export PATH=$prefix/bin:\$PATH' to your $profile" + + # avoid problems when calling any verify_* function + export PATH="$prefix/bin:$PATH" +} + +function check_system_deps() { + + validate_install_prefix "$INSTALL_PREFIX" + + if ! command -v git &>/dev/null; then + print_missing_dep_msg "git" + exit 1 + fi + if ! command -v nvim &>/dev/null; then + print_missing_dep_msg "neovim" + exit 1 + fi + check_neovim_min_version +} + +function __install_nodejs_deps_pnpm() { + echo "Installing node modules with pnpm.." + pnpm install -g "${__npm_deps[@]}" + echo "All NodeJS dependencies are successfully installed" +} + +function __install_nodejs_deps_npm() { + echo "Installing node modules with npm.." + for dep in "${__npm_deps[@]}"; do + if ! npm ls -g "$dep" &>/dev/null; then + printf "installing %s .." "$dep" + npm install -g "$dep" + fi + done + + echo "All NodeJS dependencies are successfully installed" +} + +function __install_nodejs_deps_yarn() { + echo "Installing node modules with yarn.." + yarn global add "${__npm_deps[@]}" + echo "All NodeJS dependencies are successfully installed" +} + +function __install_nodejs_deps_bun() { + echo "Installing bun modules with bun..." + bun install -g "${__npm_deps[@]}" + echo "All BunJS dependencies are successfully installed" +} + +function __validate_node_installation() { + local pkg_manager="$1" + local manager_home + + if ! command -v "$pkg_manager" &>/dev/null; then + return 1 + fi + + if [ "$pkg_manager" == "npm" ]; then + manager_home="$(npm config get prefix 2>/dev/null)" + elif [ "$pkg_manager" == "bun" ]; then + manager_home="$BUN_INSTALL" + elif [ "$pkg_manager" == "pnpm" ]; then + manager_home="$(pnpm config get prefix 2>/dev/null)" + else + manager_home="$(yarn global bin 2>/dev/null)" + fi + + if [ ! -d "$manager_home" ] || [ ! -w "$manager_home" ]; then + return 1 + fi + + return 0 +} + +function install_nodejs_deps() { + local -a pkg_managers=("pnpm" "bun" "yarn" "npm") + for pkg_manager in "${pkg_managers[@]}"; do + if __validate_node_installation "$pkg_manager"; then + eval "__install_nodejs_deps_$pkg_manager" + return + fi + done + echo "[WARN]: skipping installing optional nodejs dependencies due to insufficient permissions." + echo "check how to solve it: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally" +} + +function __attempt_to_install_with_cargo() { + if command -v cargo &>/dev/null; then + echo "Installing missing Rust dependency with cargo" + cargo install "$1" + else + echo "[WARN]: Unable to find cargo. Make sure to install it to avoid any problems" + exit 1 + fi +} + +# we try to install the missing one with cargo even though it's unlikely to be found +function install_rust_deps() { + for dep in "${__rust_deps[@]}"; do + if ! command -v "${dep%%::*}" &>/dev/null; then + __attempt_to_install_with_cargo "${dep##*::}" + fi + done + echo "All Rust dependencies are successfully installed" +} + +function __backup_dir() { + local src="$1" + if [ ! -d "$src" ]; then + return + fi + mkdir -p "$src.old" + msg "Backing up old $src to $src.old" + if command -v rsync &>/dev/null; then + rsync --archive --quiet --backup --partial --copy-links --cvs-exclude "$src"/ "$src.old" + else + case "$OS" in + Darwin) + cp -R "$src/." "$src.old/." + ;; + *) + cp -r "$src/." "$src.old/." + ;; + esac + fi +} + +function verify_lvim_dirs() { + for dir in "${__lvim_dirs[@]}"; do + if [ -d "$dir" ]; then + if [ "$ARGS_OVERWRITE" -eq 0 ]; then + __backup_dir "$dir" + fi + rm -rf "$dir" + fi + mkdir -p "$dir" + done + mkdir -p "$LUNARVIM_CONFIG_DIR" +} + +function clone_lvim() { + msg "Cloning LunarVim configuration" + if ! git clone --progress --depth 1 --branch "$LV_BRANCH" \ + "https://github.com/${LV_REMOTE}" "$LUNARVIM_BASE_DIR"; then + echo "Failed to clone repository. Installation failed." + exit 1 + fi +} + +function link_local_lvim() { + echo "Linking local LunarVim repo" + + # Detect whether it's a symlink or a folder + if [ -d "$LUNARVIM_BASE_DIR" ]; then + msg "Moving old files to ${LUNARVIM_BASE_DIR}.old" + mv "$LUNARVIM_BASE_DIR" "${LUNARVIM_BASE_DIR}".old + fi + + echo " - $BASEDIR -> $LUNARVIM_BASE_DIR" + ln -s -f "$BASEDIR" "$LUNARVIM_BASE_DIR" +} + +function setup_shim() { + make -C "$LUNARVIM_BASE_DIR" install-bin +} + +function remove_old_cache_files() { + local lazy_cache="$LUNARVIM_CACHE_DIR/lazy/cache" + if [ -e "$lazy_cache" ]; then + msg "Removing old lazy cache file" + rm -f "$lazy_cache" + fi +} + +function setup_lvim() { + + msg "Installing LunarVim shim" + + setup_shim + + create_desktop_file + + [ ! -f "$LUNARVIM_CONFIG_DIR/config.lua" ] \ + && cp "$LUNARVIM_BASE_DIR/utils/installer/config.example.lua" "$LUNARVIM_CONFIG_DIR/config.lua" + + echo "Preparing Lazy setup" + + "$INSTALL_PREFIX/bin/$NVIM_APPNAME" --headless -c 'quitall' + + printf "\nLazy setup complete\n" + + verify_core_plugins +} + +function create_desktop_file() { + # TODO: Any other OSes that use desktop files? + ([ "$OS" != "Linux" ] || ! command -v xdg-desktop-menu &>/dev/null) && return + echo "Creating desktop file" + + for d in "$LUNARVIM_BASE_DIR"/utils/desktop/*/; do + size_folder=$(basename "$d") + mkdir -p "$XDG_DATA_HOME/icons/hicolor/$size_folder/apps/" + cp "$LUNARVIM_BASE_DIR/utils/desktop/$size_folder/lvim.svg" "$XDG_DATA_HOME/icons/hicolor/$size_folder/apps" + done + + xdg-desktop-menu install --novendor "$LUNARVIM_BASE_DIR/utils/desktop/lvim.desktop" || true +} + +function print_logo() { + cat <<'EOF' + + 88\ 88\ + 88 | \__| + 88 |88\ 88\ 888888$\ 888888\ 888888\ 88\ 88\ 88\ 888888\8888\ + 88 |88 | 88 |88 __88\ \____88\ 88 __88\\88\ 88 |88 |88 _88 _88\ + 88 |88 | 88 |88 | 88 | 888888$ |88 | \__|\88\88 / 88 |88 / 88 / 88 | + 88 |88 | 88 |88 | 88 |88 __88 |88 | \88$ / 88 |88 | 88 | 88 | + 88 |\888888 |88 | 88 |\888888$ |88 | \$ / 88 |88 | 88 | 88 | + \__| \______/ \__| \__| \_______|\__| \_/ \__|\__| \__| \__| + +EOF +} + +main "$@" diff --git a/mac/.config/LunarVim/utils/installer/install_bin.sh b/mac/.config/LunarVim/utils/installer/install_bin.sh new file mode 100755 index 0000000..a25ad37 --- /dev/null +++ b/mac/.config/LunarVim/utils/installer/install_bin.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -eo pipefail + +INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local"}" + +XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}" +XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}" +XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}" + +NVIM_APPNAME="${NVIM_APPNAME:-lvim}" + +LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$XDG_DATA_HOME/lunarvim"}" +LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/$NVIM_APPNAME"}" +LUNARVIM_CACHE_DIR="${LUNARVIM_CACHE_DIR:-"$XDG_CACHE_HOME/$NVIM_APPNAME"}" +LUNARVIM_BASE_DIR="${LUNARVIM_BASE_DIR:-"$LUNARVIM_RUNTIME_DIR/$NVIM_APPNAME"}" + +function setup_shim() { + local src="$LUNARVIM_BASE_DIR/utils/bin/lvim.template" + local dst="$INSTALL_PREFIX/bin/$NVIM_APPNAME" + + [ ! -d "$INSTALL_PREFIX/bin" ] && mkdir -p "$INSTALL_PREFIX/bin" + + # remove outdated installation so that `cp` doesn't complain + rm -f "$dst" + + cp "$src" "$dst" + + sed -e s"#NVIM_APPNAME_VAR#\"${NVIM_APPNAME}\"#"g \ + -e s"#RUNTIME_DIR_VAR#\"${LUNARVIM_RUNTIME_DIR}\"#"g \ + -e s"#CONFIG_DIR_VAR#\"${LUNARVIM_CONFIG_DIR}\"#"g \ + -e s"#CACHE_DIR_VAR#\"${LUNARVIM_CACHE_DIR}\"#"g \ + -e s"#BASE_DIR_VAR#\"${LUNARVIM_BASE_DIR}\"#"g "$src" \ + | tee "$dst" >/dev/null + + chmod u+x "$dst" +} + +setup_shim "$@" + +echo "You can start LunarVim by running: $INSTALL_PREFIX/bin/$NVIM_APPNAME" diff --git a/mac/.config/LunarVim/utils/installer/install_stylua.sh b/mac/.config/LunarVim/utils/installer/install_stylua.sh new file mode 100755 index 0000000..963416e --- /dev/null +++ b/mac/.config/LunarVim/utils/installer/install_stylua.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +set -eu pipefall + +declare -r INSTALL_DIR="$PWD/utils" +declare -r RELEASE="0.10.0" +declare -r OS="linux" +# declare -r OS="$(uname -s)" +declare -r FILENAME="stylua-$RELEASE-$OS" + +declare -a __deps=("curl" "unzip") + +function check_deps() { + for dep in "${__deps[@]}"; do + if ! command -v "$dep" >/dev/null; then + echo "Missing depdendecy!" + echo "The \"$dep\" command was not found!. Please install and try again." + fi + done +} + +function download_stylua() { + local DOWNLOAD_DIR + local URL="https://github.com/JohnnyMorganz/StyLua/releases/download/v$RELEASE/$FILENAME.zip" + + DOWNLOAD_DIR="$(mktemp -d)" + echo "Initiating download for Stylua v$RELEASE" + if ! curl --progress-bar --fail -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"; then + echo "Download failed. Check that the release/filename are correct." + exit 1 + fi + + echo "Installation in progress.." + unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR" + + if [ -f "$DOWNLOAD_DIR/stylua" ]; then + mv "$DOWNLOAD_DIR/stylua" "$INSTALL_DIR/stylua" + else + mv "$DOWNLOAD_DIR/$FILENAME/stylua" "$INSTALL_DIR/." + fi + + chmod u+x "$INSTALL_DIR/stylua" +} + +function verify_install() { + echo "Verifying installation.." + local DOWNLOADED_VER + DOWNLOADED_VER="$("$INSTALL_DIR/stylua" -V | awk '{ print $2 }')" + if [ "$DOWNLOADED_VER" != "$RELEASE" ]; then + echo "Mismatched version!" + echo "Expected: v$RELEASE but got v$DOWNLOADED_VER" + exit 1 + fi + echo "Verification complete!" +} + +function main() { + check_deps + download_stylua + verify_install +} + +main "$@" diff --git a/mac/.config/LunarVim/utils/installer/uninstall.ps1 b/mac/.config/LunarVim/utils/installer/uninstall.ps1 new file mode 100644 index 0000000..dcfeb26 --- /dev/null +++ b/mac/.config/LunarVim/utils/installer/uninstall.ps1 @@ -0,0 +1,63 @@ +#Requires -Version 7.1 +$ErrorActionPreference = "Stop" # exit when command fails + +# set script variables +$LV_BRANCH = $LV_BRANCH ?? "master" +$LV_REMOTE = $LV_REMOTE ?? "lunarvim/lunarvim.git" +$INSTALL_PREFIX = $INSTALL_PREFIX ?? "$HOME\.local" + +$env:XDG_DATA_HOME = $env:XDG_DATA_HOME ?? $env:APPDATA +$env:XDG_CONFIG_HOME = $env:XDG_CONFIG_HOME ?? $env:LOCALAPPDATA +$env:XDG_CACHE_HOME = $env:XDG_CACHE_HOME ?? $env:TEMP + +$env:LUNARVIM_RUNTIME_DIR = $env:LUNARVIM_RUNTIME_DIR ?? "$env:XDG_DATA_HOME\lunarvim" +$env:LUNARVIM_CONFIG_DIR = $env:LUNARVIM_CONFIG_DIR ?? "$env:XDG_CONFIG_HOME\lvim" +$env:LUNARVIM_CACHE_DIR = $env:LUNARVIM_CACHE_DIR ?? "$env:XDG_CACHE_HOME\lvim" +$env:LUNARVIM_BASE_DIR = $env:LUNARVIM_BASE_DIR ?? "$env:LUNARVIM_RUNTIME_DIR\lvim" + +$__lvim_dirs = ( + $env:LUNARVIM_BASE_DIR, + $env:LUNARVIM_RUNTIME_DIR, + $env:LUNARVIM_CONFIG_DIR, + $env:LUNARVIM_CACHE_DIR +) + +function main($cliargs) { + Write-Output "Removing LunarVim binary..." + remove_lvim_bin + Write-Output "Removing LunarVim directories..." + $force = $false + if ($cliargs.Contains("--remove-backups")) { + $force = $true + } + remove_lvim_dirs $force + Write-Output "Uninstalled LunarVim!" +} + +function remove_lvim_bin(){ + $lvim_bin="$INSTALL_PREFIX\bin\lvim" + if (Test-Path $lvim_bin) { + Remove-Item -Force $lvim_bin + } + if (Test-Path alias:lvim) { + Write-Warning "Please make sure to remove the 'lvim' alias from your `$PROFILE`: $PROFILE" + } +} + +function remove_lvim_dirs($force) { + foreach ($dir in $__lvim_dirs) { + if (Test-Path $dir) { + Remove-Item -Force -Recurse $dir + } + if ($force -eq $true) { + if (Test-Path "$dir.bak") { + Remove-Item -Force -Recurse "$dir.bak" + } + if (Test-Path "$dir.old") { + Remove-Item -Force -Recurse "$dir.old" + } + } + } +} + +main($args) diff --git a/mac/.config/LunarVim/utils/installer/uninstall.sh b/mac/.config/LunarVim/utils/installer/uninstall.sh new file mode 100755 index 0000000..9b26263 --- /dev/null +++ b/mac/.config/LunarVim/utils/installer/uninstall.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +set -eo pipefail + +ARGS_REMOVE_BACKUPS=0 +ARGS_REMOVE_CONFIG=0 + +declare -r XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}" +declare -r XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}" +declare -r XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}" + +declare -xr NVIM_APPNAME="${NVIM_APPNAME:-"lvim"}" + +declare -xr LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$XDG_DATA_HOME/lunarvim"}" +declare -xr LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/$NVIM_APPNAME"}" +declare -xr LUNARVIM_CACHE_DIR="${LUNARVIM_CACHE_DIR:-"$XDG_CACHE_HOME/$NVIM_APPNAME"}" +declare -xr LUNARVIM_BASE_DIR="${LUNARVIM_BASE_DIR:-"$LUNARVIM_RUNTIME_DIR/$NVIM_APPNAME"}" + +declare -a __lvim_dirs=( + "$LUNARVIM_RUNTIME_DIR" + "$LUNARVIM_CACHE_DIR" +) + +__lvim_config_dir="$LUNARVIM_CONFIG_DIR" + +function usage() { + echo "Usage: uninstall.sh [<options>]" + echo "" + echo "Options:" + echo " -h, --help Print this help message" + echo " --remove-config Remove user config files as well" + echo " --remove-backups Remove old backup folders as well" +} + +function parse_arguments() { + while [ "$#" -gt 0 ]; do + case "$1" in + --remove-backups) + ARGS_REMOVE_BACKUPS=1 + ;; + --remove-config) + ARGS_REMOVE_CONFIG=1 + ;; + -h | --help) + usage + exit 0 + ;; + esac + shift + done +} + +function remove_lvim_dirs() { + if [ "$ARGS_REMOVE_CONFIG" -eq 1 ]; then + __lvim_dirs+=("$__lvim_config_dir") + fi + for dir in "${__lvim_dirs[@]}"; do + rm -rf "$dir" + if [ "$ARGS_REMOVE_BACKUPS" -eq 1 ]; then + rm -rf "$dir.{bak,old}" + fi + done +} + +function remove_lvim_bin() { + lvim_bin="$(command -v "$NVIM_APPNAME" 2>/dev/null)" + rm -f "$lvim_bin" +} + +function remove_desktop_file() { + OS="$(uname -s)" + # TODO: Any other OSes that use desktop files? + ([ "$OS" != "Linux" ] || ! command -v xdg-desktop-menu &>/dev/null) && return + echo "Removing desktop file..." + + find "$XDG_DATA_HOME/icons/hicolor" -name "lvim.svg" -type f -delete + xdg-desktop-menu uninstall lvim.desktop +} + +function main() { + parse_arguments "$@" + echo "Removing LunarVim binary..." + remove_lvim_bin + echo "Removing LunarVim directories..." + remove_lvim_dirs + remove_desktop_file + echo "Uninstalled LunarVim!" +} + +main "$@" |
