diff options
Diffstat (limited to 'neovim.sh')
| -rwxr-xr-x | neovim.sh | 281 |
1 files changed, 176 insertions, 105 deletions
@@ -13,17 +13,14 @@ NC='\033[0m' # No Color handle_error() { local message="$1" printf "${RED}Error: $message${NC}\n" - exit 1 } # Check if necessary dependencies are installed check_dependencies() { - DOWNLOAD_COMMAND="" - if [ -x "$(command -v wget)" ]; then - DOWNLOAD_COMMAND="wget -q -O" + DOWNLOAD_COMMAND="wget" elif [ -x "$(command -v curl)" ]; then - DOWNLOAD_COMMAND="curl -sSL -o" + DOWNLOAD_COMMAND="curl" else printf "${RED}Error: Neither wget nor curl found. Please install one of them to continue!${NC}\n" exit 1 @@ -50,7 +47,7 @@ check_privilege_tools() { case $continue_choice in [Yy] | [Yy][Ee][Ss]) ;; [Nn] | [Nn][Oo]) exit ;; - *) echo "Invalid choice. Exiting..." && exit ;; + *) handle_error "Invalid choice. Exiting..." && exit ;; esac fi } @@ -64,16 +61,21 @@ check_neovim_installed() { fi } +version_id="" +action="" + # Nightly version nightly_version() { local url="https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage" install_neovim "$url" + version_id=$(echo "$url" | grep -oP 'v\d+\.\d+\.\d+') } # Stable version stable_version() { local url="https://github.com/neovim/neovim/releases/download/stable/nvim.appimage" install_neovim "$url" + version_id=$(echo "$url" | grep -oP 'v\d+\.\d+\.\d+') } # Specific version @@ -81,6 +83,7 @@ specific_version() { local version="$1" local url="https://github.com/neovim/neovim/releases/download/$version/nvim.appimage" install_neovim "$url" + version_id=$(echo "$url" | grep -oP 'v\d+\.\d+\.\d+') } # Function to download a file using wget or curl @@ -88,16 +91,26 @@ download_file() { local url="$1" local output="$2" - $DOWNLOAD_COMMAND "$output" "$url" + if [ "$DOWNLOAD_COMMAND" = "wget" ]; then + "$DOWNLOAD_COMMAND" -q --show-progress -O "$output" "$url" + elif [ "$DOWNLOAD_COMMAND" = "curl" ]; then + "$DOWNLOAD_COMMAND" --progress-bar -# -o "$output" "$url" + else + echo "Unsupported download command: $DOWNLOAD_COMMAND" + exit 1 + fi } # Check if a specific version of Neovim exists version_exists() { local version="$1" + if [[ $version != v* ]]; then + version="v$version" + fi local url="https://github.com/neovim/neovim/releases/tag/$version" # Send a HEAD request and check the response status using wget or curl - if $DOWNLOAD_COMMAND /dev/null "$url" 2>/dev/null; then + if "$DOWNLOAD_COMMAND" /dev/null "$url" 2>/dev/null; then return 0 # Version exists else return 1 # Version does not exist @@ -108,16 +121,25 @@ version_exists() { choose_version() { printf "${GREEN}Choose what version to install...${NC}\n" - # Ask user for version preference - read -p "Installation options: - 1. Nightly version (default) - 2. Stable version - 3. Specific version - Enter the number corresponding to your choice (1/2/3): " version_choice - - case $version_choice in - 1) nightly_version ;; - 2) stable_version ;; + valid_choice=false + while [ "$valid_choice" = false ]; do + # Ask user for version preference + printf "Installation options:\n" + printf " 1. Nightly version (default)\n" + printf " 2. Stable version\n" + printf " 3. Specific version\n" + printf "Enter the number corresponding to your choice (1/2/3): " + read -r version_choice + + case $version_choice in + 1) + nightly_version + valid_choice=true + ;; + 2) + stable_version + valid_choice=true + ;; 3) # Ask user for specific version read -p "Enter the specific version (e.g., v0.1.0): " specific_version @@ -125,98 +147,112 @@ choose_version() { if version_exists "$specific_version"; then # Install specific version specific_version "$specific_version" + valid_choice=true else - printf "${RED}The specified version $specific_version does not exist. Aborting...${NC}\n" - exit 1 + printf "${RED}The specified version $specific_version does not exist.${NC}\n" fi ;; *) - echo "Invalid choice. Exiting..." - exit 1 + handle_error "Invalid choice. Please enter a valid option (1, 2, or 3)." ;; - esac + esac + done } # Install Neovim install_neovim() { local url="$1" - printf "Downloading and installing Neovim $version_choice...\n" + local install_action="$2" + version_id="$3" + printf "Downloading and installing Neovim $version_id...\n" # Determine the platform-specific installation steps case "$(uname -s)" in - Linux) - printf "Detected Linux OS.\n" - if [ -x "$(command -v fusermount)" ]; then - printf "FUSE is available. Downloading and running the AppImage...\n" - download_file "$url" -q -O nvim.appimage - chmod u+x nvim.appimage - "$PRIVILEGE_TOOL" cp nvim.appimage /usr/local/bin/nvim - "$PRIVILEGE_TOOL" mv nvim.appimage /usr/bin/nvim - nvim - else - printf "FUSE is not available. Downloading and extracting the AppImage...\n" - download_file "$url" -q -O nvim.appimage - chmod u+x nvim.appimage - ./nvim.appimage --appimage-extract - "$PRIVILEGE_TOOL" cp squashfs-root/usr/bin/nvim /usr/local/bin - "$PRIVILEGE_TOOL" mv squashfs-root/usr/bin/nvim /usr/bin - nvim - fi + Linux) + printf "Detected Linux OS.\n" + if [ -x "$(command -v fusermount)" ]; then + printf "FUSE is available. Downloading and running the AppImage...\n" + download_file "$url" "nvim.appimage" + chmod u+x nvim.appimage + "$PRIVILEGE_TOOL" cp nvim.appimage /usr/local/bin/nvim + "$PRIVILEGE_TOOL" mv nvim.appimage /usr/bin/nvim + else + printf "FUSE is not available. Downloading and extracting the AppImage...\n" + download_file "$url" "nvim.appimage" + chmod u+x nvim.appimage + ./nvim.appimage --appimage-extract + "$PRIVILEGE_TOOL" cp squashfs-root/usr/bin/nvim /usr/local/bin + "$PRIVILEGE_TOOL" mv squashfs-root/usr/bin/nvim /usr/bin + fi + ;; - ;; + Darwin) + printf "Detected macOS.\n" + download_file "$url" "nvim-macos.tar.gz" + xattr -c ./nvim-macos.tar.gz + tar xzvf nvim-macos.tar.gz + "$PRIVILEGE_TOOL" cp nvim-macos/bin/nvim /usr/local/bin + "$PRIVILEGE_TOOL" mv nvim-macos/bin/nvim /usr/bin/nvim + ;; - Darwin) - printf "Detected macOS.\n" - download_file "$url" -q -O nvim-macos.tar.gz - xattr -c ./nvim-macos.tar.gz - tar xzvf nvim-macos.tar.gz - "$PRIVILEGE_TOOL" cp nvim-macos/bin/nvim /usr/local/bin - "$PRIVILEGE_TOOL" mv nvim-macos/bin/nvim /usr/bin/nvim - nvim - ;; + MINGW*) + printf "Detected Windows.\n" + download_file "$url" "nvim.appimage" + chmod +x nvim.appimage + if [ "$PRIVILEGE_TOOL" = "sudo" ]; then + "$PRIVILEGE_TOOL" cp nvim.appimage /usr/local/bin/nvim + "$PRIVILEGE_TOOL" mv /usr/local/bin/nvim /usr/bin + elif [ "$PRIVILEGE_TOOL" = "" ]; then + cp nvim.appimage /usr/local/bin/nvim + mv /usr/local/bin/nvim /usr/bin + else + printf "No privilege escalation tool found. Cannot install Neovim on Windows.\n" + fi + ;; - MINGW*) - printf "Detected Windows.\n" - download_file "$url" -q -O nvim.appimage - chmod +x nvim.appimage - if [ "$PRIVILEGE_TOOL" = "sudo" ]; then - "$PRIVILEGE_TOOL" cp nvim.appimage /usr/local/bin/nvim - "$PRIVILEGE_TOOL" mv /usr/local/bin/nvim /usr/bin - nvim - elif [ "$PRIVILEGE_TOOL" = "" ]; then - cp nvim.appimage /usr/local/bin/nvim - mv /usr/local/bin/nvim /usr/bin - nvim - else - printf "No privilege escalation tool found. Cannot install Neovim on Windows.\n" - fi - ;; - *) - printf "Unsupported operating system.\n" - exit 1 - ;; + *) + printf "Unsupported operating system.\n" + exit 1 + ;; esac - printf "${GREEN}Neovim $version_choice has been installed successfully!${NC}\n" + if [ "$install_action" = "installed" ]; then + printf "${GREEN}Neovim $version_id has been installed successfully!${NC}\n" + fi } # Update Neovim to the latest version (nightly/stable) update_version() { printf "${GREEN}Updating Neovim to the latest version...${NC}\n" - # Determine which version to update to (nightly/stable) - printf "Select version to update to: - 1. Nightly - 2. Stable - Enter the number corresponding to your choice (1/2): " - read update_choice - - case $update_choice in - 1) nightly_version ;; - 2) stable_version ;; - *) echo "Invalid choice. Exiting..." && exit 1 ;; - esac + valid_choice=false + while [ "$valid_choice" = false ]; do + # Determine which version to update to (nightly/stable) + printf "Select version to update to:\n" + printf " 1. Nightly\n" + printf " 2. Stable\n" + printf "Enter the number corresponding to your choice (1/2): " + read update_choice + + case $update_choice in + 1) + nightly_version + action="updated" + valid_choice=true + ;; + 2) + stable_version + action="updated" + valid_choice=true + ;; + *) + handle_error "Invalid choice. Please enter a valid option (1 or 2)." + ;; + esac + done - printf "${GREEN}Neovim has been updated successfully!${NC}\n" + if [ "$action" = "updated" ]; then + printf "${GREEN}Neovim has been updated successfully to $version_id!${NC}\n" + fi } # Uninstall Neovim @@ -256,6 +292,29 @@ uninstall_neovim() { printf "${GREEN}Neovim has been uninstalled successfully!${NC}\n" } +# Check if Neovim is running +check_neovim_running() { + if pgrep nvim >/dev/null; then + printf "${RED}Error: Neovim is currently running. Please close Neovim before proceeding.${NC}\n" + read -p "Do you want to forcefully terminate Neovim and continue? [yes/no] " terminate_choice + + case $terminate_choice in + [Yy] | [Yy][Ee][Ss]) + pkill nvim # Forcefully terminate Neovim + ;; + [Nn] | [Nn][Oo]) + echo "Exiting..." + exit 1 + ;; + *) + handle_error "Invalid choice." + ;; + esac + fi +} + +check_neovim_running + # Define the variable to control the prompt SHOW_PROMPT=1 @@ -315,25 +374,37 @@ display_breaking_changes() { # Main loop while [ "$SHOW_PROMPT" -gt 0 ]; do - read -p "Do you wish to update, check for updates, change to a specific version, uninstall Neovim, or do nothing? [update/check/specific/uninstall/no] " choice + printf "Select an action:\n" + printf " 1. Update Neovim\n" + printf " 2. Check for updates\n" + printf " 3. Change to a specific version\n" + printf " 4. Uninstall Neovim\n" + printf " 5. Run Neovim\n" + printf " 6. Exit\n" + read -p "Enter the number or 'q' to exit: " choice + case $choice in - [Uu]*) - update_version - break ;; - [Ss]*) - choose_version - break ;; - [Rr]*) - uninstall_neovim - break ;; - [Nn]*) - echo "Exiting..." - exit ;; - [Cc]*) - check_version_updates - break ;; - *) - handle_error "Invalid choice. Please choose update, check, specific, uninstall, or no." - ;; + 1) + update_version + ;; + 2) + check_version_updates + ;; + 3) + choose_version + ;; + 4) + uninstall_neovim + ;; + 5) + nvim + ;; + 6 | [Qq]) + echo "Exiting..." + exit + ;; + *) + handle_error "Invalid choice. Please choose a valid option by entering the corresponding number or 'q' to 'exit'." + ;; esac done |
