Last active
May 6, 2026 12:01
-
-
Save bahamut45/728bc0e9108b126bc18cdf08876c0e13 to your computer and use it in GitHub Desktop.
Install Neovim with Powerline for all users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| set -o pipefail | |
| # -- Configuration ------------------------------------------------------------ | |
| readonly VIM_SYSTEM="/usr/share/nvim" | |
| readonly NVIM_PLUG_DIR="/usr/local/share/nvim/plugged" | |
| readonly NVIM_AUTOLOAD_DIR="$VIM_SYSTEM/site/autoload" | |
| readonly NVIM_CONFIG_FILE="$VIM_SYSTEM/sysinit.vim" | |
| readonly VIM_PLUG_URL="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" | |
| readonly DEPENDENCIES=(neovim curl) | |
| # -- Logging ------------------------------------------------------------------ | |
| log_info() { echo -e "\e[94m${1}\e[39m"; } | |
| log_success() { echo -e "\e[32m${1}\e[39m"; } | |
| log_warning() { echo -e "\e[33m${1}\e[39m"; } | |
| log_error() { echo -e "\e[31m${1}\e[39m" >&2; } | |
| # -- Dependency management ---------------------------------------------------- | |
| # Install a list of packages using the available system package manager | |
| install_packages() { | |
| local packages=("$@") | |
| if command -v apt-get &>/dev/null; then | |
| sudo apt-get install -y "${packages[@]}" | |
| elif command -v dnf &>/dev/null; then | |
| sudo dnf install -y "${packages[@]}" | |
| elif command -v pacman &>/dev/null; then | |
| sudo pacman -S --noconfirm "${packages[@]}" | |
| else | |
| log_error "Unsupported package manager. Please install manually: ${packages[*]}" | |
| exit 1 | |
| fi | |
| } | |
| # Check for missing dependencies and install them if needed | |
| check_dependencies() { | |
| log_info "Checking dependencies..." | |
| local missing=() | |
| for dep in "${DEPENDENCIES[@]}"; do | |
| if ! command -v "$dep" &>/dev/null; then | |
| missing+=("$dep") | |
| fi | |
| done | |
| if [ ${#missing[@]} -gt 0 ]; then | |
| log_warning "Installing missing dependencies: ${missing[*]}" | |
| install_packages "${missing[@]}" | |
| else | |
| log_success "All dependencies are satisfied." | |
| fi | |
| } | |
| # -- Setup -------------------------------------------------------------------- | |
| # Create required system directories | |
| create_directories() { | |
| log_info "Creating required directories..." | |
| sudo mkdir -p "$NVIM_PLUG_DIR" | |
| sudo mkdir -p "$NVIM_AUTOLOAD_DIR" | |
| } | |
| # Write the system-wide Neovim configuration file | |
| write_config() { | |
| log_info "Writing system-wide Neovim config to $NVIM_CONFIG_FILE..." | |
| sudo tee "$NVIM_CONFIG_FILE" > /dev/null << 'EOF' | |
| " Plug | |
| call plug#begin('/usr/local/share/nvim/plugged') | |
| Plug 'vim-airline/vim-airline' | |
| Plug 'rakr/vim-one' | |
| call plug#end() | |
| " airline | |
| let g:airline_powerline_fonts = 1 | |
| if (empty($TMUX)) | |
| if (has("nvim")) | |
| let $NVIM_TUI_ENABLE_TRUE_COLOR=1 | |
| endif | |
| if (has("termguicolors")) | |
| set termguicolors | |
| endif | |
| endif | |
| set background=dark | |
| if isdirectory('/usr/local/share/nvim/plugged/vim-one') | |
| colorscheme one | |
| endif | |
| " others | |
| set nu | |
| set tabstop=4 shiftwidth=4 expandtab | |
| EOF | |
| } | |
| # Download vim-plug into the system autoload directory | |
| install_vim_plug() { | |
| log_info "Downloading vim-plug to $NVIM_AUTOLOAD_DIR/plug.vim..." | |
| sudo curl -fLo "$NVIM_AUTOLOAD_DIR/plug.vim" "$VIM_PLUG_URL" | |
| } | |
| # Install plugins headlessly using the system config | |
| install_plugins() { | |
| log_info "Installing Neovim plugins..." | |
| nvim -u "$NVIM_CONFIG_FILE" --headless -c "PlugInstall --sync" -c "qa!" | |
| } | |
| # Set read permissions for all users on plugin and autoload directories | |
| set_permissions() { | |
| log_info "Setting read permissions..." | |
| sudo chmod -R a+rX "$NVIM_PLUG_DIR" | |
| sudo chmod -R a+rX "$NVIM_AUTOLOAD_DIR" | |
| } | |
| # -- Main --------------------------------------------------------------------- | |
| main() { | |
| echo "### INSTALL NEOVIM SYSTEM-WIDE CONFIG ###" | |
| check_dependencies | |
| create_directories | |
| write_config | |
| install_vim_plug | |
| install_plugins | |
| set_permissions | |
| log_success "Done! Config is now active for all users via $NVIM_CONFIG_FILE" | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment