From e22d899ce184f9d4765d99d617ecbf641d040f55 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 16 Sep 2023 14:46:45 +0200 Subject: Fixed not showing what version when installing/updating --- neovim.sh | 114 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/neovim.sh b/neovim.sh index 4b67d48..ce448ea 100755 --- a/neovim.sh +++ b/neovim.sh @@ -2,7 +2,7 @@ # Created By: srdusr # Created On: Sat 12 Aug 2023 13:11:39 CAT -# Project: Install/update/downgrade/change version/uninstall Neovim script, primarily for Linux but may work in other platforms +# Project: Install/update/uninstall/change version Neovim script, primarily for Linux but may work in other platforms # Color definitions RED='\033[0;31m' @@ -66,7 +66,7 @@ nightly_version() { local url="https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage" install_neovim "$url" local version_output=$(nvim --version) - version_id="Nightly $(echo "$version_output" | grep -oP 'v\d+\.\d+\.\d+')" + version_id="Nightly $(echo "$version_output" | grep -oP 'NVIM \d+\.\d+')" } # Stable version @@ -74,8 +74,7 @@ stable_version() { local url="https://github.com/neovim/neovim/releases/download/stable/nvim.appimage" install_neovim "$url" local version_output=$(nvim --version) - version_id="Stable $(echo "$version_output" | grep -oP 'v\d+\.\d+\.\d+')" - + version_id="Stable $(echo "$version_output" | grep -oP 'NVIM \d+\.\d+')" } # Specific version @@ -90,7 +89,7 @@ specific_version() { local url="https://github.com/neovim/neovim/releases/download/$version/nvim.appimage" install_neovim "$url" local version_output=$(nvim --version) - version_id="Stable $(echo "$version_output" | grep -oP 'v\d+\.\d+\.\d+')" + version_id="Version $version $(echo "$version_output" | grep -oP 'NVIM \d+\.\d+')" } # Function to download a file using wget or curl @@ -128,16 +127,63 @@ version_exists() { fi } +# Update Neovim to the latest version (nightly/stable) +update_version() { + 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 " 3. Choose specific version by tag\n" + printf "Enter the number corresponding to your choice (1/2/3): " + read update_choice + + case $update_choice in + 1) + version="Nightly" + nightly_version + valid_choice=true + ;; + 2) + version="Stable" + stable_version + valid_choice=true + ;; + 3) + # Ask user for specific version + read -p "Enter the specific version (e.g., v0.1.0): " version + # Normalize version + if [[ $version != v* ]]; then + version="v$version" + fi + # Check if the specific version exists on GitHub releases + if version_exists "$version"; then + # Install specific version + specific_version "$version" # Pass the normalized version to the function + valid_choice=true + else + printf "${RED}The specified version $version does not exist.${NC}\n" + fi + ;; + + *) + handle_error "Invalid choice. Please enter a valid option (1, 2 or 3)." + ;; + esac + done + +} + # Install Neovim install_neovim() { local url="$1" - local install_type="$2" # Pass the install type as an argument local install_action="$3" if [ "$install_action" = "installed" ]; then - printf "Downloading and installing $install_type Neovim $version_id...\n" + printf "Downloading and installing Neovim $version...\n" else - printf "${GREEN}Updating $install_type Neovim to the latest version...${NC}\n" + printf "${GREEN}Updating Neovim to the latest version ($version)...${NC}\n" fi # Determine the platform-specific installation steps @@ -190,60 +236,12 @@ install_neovim() { ;; esac if [ "$install_action" = "installed" ]; then - printf "${GREEN}$install_type Neovim $version_id has been installed successfully!${NC}\n" + printf "${GREEN}Neovim $version has been installed successfully!${NC}\n" else - printf "${GREEN}$install_type Neovim has been updated successfully to $version_id!${NC}\n" + printf "${GREEN}Neovim has been updated successfully to $version!${NC}\n" fi } -# Update Neovim to the latest version (nightly/stable) -update_version() { - 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 " 3. Choose specific version by tag\n" - printf "Enter the number corresponding to your choice (1/2/3): " - read update_choice - - case $update_choice in - 1) - action="updated" - nightly_version - valid_choice=true - ;; - 2) - action="updated" - stable_version - valid_choice=true - ;; - 3) - # Ask user for specific version - read -p "Enter the specific version (e.g., v0.1.0): " version - # Normalize version - if [[ $version != v* ]]; then - version="v$version" - fi - # Check if the specific version exists on GitHub releases - if version_exists "$version"; then - # Install specific version - specific_version "$version" # Pass the normalized version to the function - valid_choice=true - else - printf "${RED}The specified version $version does not exist.${NC}\n" - fi - ;; - - *) - handle_error "Invalid choice. Please enter a valid option (1, 2 or 3)." - ;; - esac - done - -} - # Uninstall Neovim uninstall_neovim() { printf "${RED}Uninstalling Neovim...${NC}\n" -- cgit v1.2.3 From cb71b3bd2e3394ccecc2fb39965290ad9810ead3 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 16 Sep 2023 14:58:23 +0200 Subject: Ask user if they want to install neovim if not installed --- neovim.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/neovim.sh b/neovim.sh index ce448ea..5bfe5e7 100755 --- a/neovim.sh +++ b/neovim.sh @@ -311,11 +311,25 @@ check_dependencies # Check for privilege escalation tools check_privilege_tools -# Check if Neovim is already installed +# Check if Neovim is already installed and ask the user if want to install it if check_neovim_installed; then printf "${GREEN}Neovim is already installed!${NC}\n" else - choose_version + printf "${RED}Neovim is not installed.${NC}\n" + read -p "Install Neovim? (y/n): " install_choice + + case $install_choice in + [Yy] ) + choose_version + ;; + [Nn] ) + echo "Exiting..." + exit + ;; + * ) + handle_error "Invalid choice. Please enter 'y' for yes or 'n' for no." + ;; + esac fi # Function to check for updates and display breaking changes -- cgit v1.2.3 From 3a3a4506fac92ef24ea6a999ceb871299b4aa4dc Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 16 Sep 2023 15:27:01 +0200 Subject: Updating is more or less the same as installing --- neovim.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/neovim.sh b/neovim.sh index 5bfe5e7..a43c593 100755 --- a/neovim.sh +++ b/neovim.sh @@ -132,7 +132,7 @@ update_version() { valid_choice=false while [ "$valid_choice" = false ]; do # Determine which version to update to (nightly/stable) - printf "Select version to update to:\n" + printf "Select version to install/update to:\n" printf " 1. Nightly\n" printf " 2. Stable\n" printf " 3. Choose specific version by tag\n" @@ -319,16 +319,16 @@ else read -p "Install Neovim? (y/n): " install_choice case $install_choice in - [Yy] ) - choose_version - ;; - [Nn] ) - echo "Exiting..." - exit - ;; - * ) - handle_error "Invalid choice. Please enter 'y' for yes or 'n' for no." - ;; + [Yy]) + choose_version + ;; + [Nn]) + echo "Exiting..." + exit + ;; + *) + handle_error "Invalid choice. Please enter 'y' for yes or 'n' for no." + ;; esac fi @@ -376,7 +376,7 @@ display_breaking_changes() { # Main loop while [ "$SHOW_PROMPT" -gt 0 ]; do printf "Select an option:\n" - printf " 1. Update Neovim\n" + printf " 1. Install/update Neovim\n" printf " 2. Check for updates\n" printf " 3. Uninstall Neovim\n" printf " 4. Run Neovim\n" -- cgit v1.2.3 From ad9b040976772d4d9888a7c3f61b7989a0d63468 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 17 Sep 2023 19:33:44 +0200 Subject: Handle errors for when download is interrupted --- neovim.sh | 300 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 156 insertions(+), 144 deletions(-) diff --git a/neovim.sh b/neovim.sh index a43c593..3ced5dd 100755 --- a/neovim.sh +++ b/neovim.sh @@ -45,9 +45,9 @@ check_privilege_tools() { printf "\nAttempt to continue Installation (might fail without a privilege escalation tool)? [yes/no] " read continue_choice case $continue_choice in - [Yy] | [Yy][Ee][Ss]) ;; - [Nn] | [Nn][Oo]) exit ;; - *) handle_error "Invalid choice. Exiting..." && exit ;; + [Yy] | [Yy][Ee][Ss]) ;; + [Nn] | [Nn][Oo]) exit ;; + *) handle_error "Invalid choice. Exiting..." && exit ;; esac fi } @@ -98,9 +98,15 @@ download_file() { local output="$2" if [ "$DOWNLOAD_COMMAND" = "wget" ]; then - "$DOWNLOAD_COMMAND" -q --show-progress -O "$output" "$url" + if ! "$DOWNLOAD_COMMAND" -q --show-progress -O "$output" "$url"; then + handle_error "Download failed. Exiting..." + exit 1 + fi elif [ "$DOWNLOAD_COMMAND" = "curl" ]; then - "$DOWNLOAD_COMMAND" --progress-bar -# -o "$output" "$url" + if ! "$DOWNLOAD_COMMAND" --progress-bar -# -o "$output" "$url"; then + handle_error "Download failed. Exiting..." + exit 1 + fi else echo "Unsupported download command: $DOWNLOAD_COMMAND" exit 1 @@ -140,36 +146,36 @@ update_version() { read update_choice case $update_choice in - 1) - version="Nightly" - nightly_version - valid_choice=true - ;; - 2) - version="Stable" - stable_version - valid_choice=true - ;; - 3) - # Ask user for specific version - read -p "Enter the specific version (e.g., v0.1.0): " version - # Normalize version - if [[ $version != v* ]]; then - version="v$version" - fi - # Check if the specific version exists on GitHub releases - if version_exists "$version"; then - # Install specific version - specific_version "$version" # Pass the normalized version to the function + 1) + version="Nightly" + nightly_version valid_choice=true - else - printf "${RED}The specified version $version does not exist.${NC}\n" - fi - ;; - - *) - handle_error "Invalid choice. Please enter a valid option (1, 2 or 3)." - ;; + ;; + 2) + version="Stable" + stable_version + valid_choice=true + ;; + 3) + # Ask user for specific version + read -p "Enter the specific version (e.g., v0.1.0): " version + # Normalize version + if [[ $version != v* ]]; then + version="v$version" + fi + # Check if the specific version exists on GitHub releases + if version_exists "$version"; then + # Install specific version + specific_version "$version" # Pass the normalized version to the function + valid_choice=true + else + printf "${RED}The specified version $version does not exist.${NC}\n" + fi + ;; + + *) + handle_error "Invalid choice. Please enter a valid option (1, 2 or 3)." + ;; esac done @@ -188,57 +194,63 @@ install_neovim() { # 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" "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" + 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 + ;; + + MINGW*) + printf "Detected Windows.\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 - ;; - - 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 - ;; + 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 + ;; - *) - printf "Unsupported operating system.\n" - exit 1 - ;; + *) + printf "Unsupported operating system.\n" + exit 1 + ;; esac - if [ "$install_action" = "installed" ]; then - printf "${GREEN}Neovim $version has been installed successfully!${NC}\n" + # Check if the installation was successful + if [ $? -eq 0 ]; then + if [ "$install_action" = "installed" ]; then + printf "${GREEN}Neovim $version has been installed successfully!${NC}\n" + else + printf "${GREEN}Neovim has been updated successfully to $version!${NC}\n" + fi else - printf "${GREEN}Neovim has been updated successfully to $version!${NC}\n" + printf "${RED}Error: Neovim installation/update failed.${NC}\n" + exit 1 fi } @@ -248,32 +260,32 @@ uninstall_neovim() { # Detect the operating system to determine the appropriate uninstallation method case "$(uname -s)" in - Linux) - printf "Detected Linux OS.\n" - "$PRIVILEGE_TOOL" rm /usr/local/bin/nvim - "$PRIVILEGE_TOOL" rm /usr/bin/nvim - ;; - - Darwin) - printf "Detected macOS.\n" - "$PRIVILEGE_TOOL" rm /usr/local/bin/nvim - "$PRIVILEGE_TOOL" rm /usr/bin/nvim - ;; - - MINGW*) - printf "Detected Windows.\n" - if [ "$PRIVILEGE_TOOL" = "sudo" ]; then + Linux) + printf "Detected Linux OS.\n" "$PRIVILEGE_TOOL" rm /usr/local/bin/nvim "$PRIVILEGE_TOOL" rm /usr/bin/nvim - else - [ "$PRIVILEGE_TOOL" = "" ] - rm /usr/local/bin/nvim - rm /usr/bin/nvim - fi - ;; - *) - printf "Unsupported operating system.\n" - ;; + ;; + + Darwin) + printf "Detected macOS.\n" + "$PRIVILEGE_TOOL" rm /usr/local/bin/nvim + "$PRIVILEGE_TOOL" rm /usr/bin/nvim + ;; + + MINGW*) + printf "Detected Windows.\n" + if [ "$PRIVILEGE_TOOL" = "sudo" ]; then + "$PRIVILEGE_TOOL" rm /usr/local/bin/nvim + "$PRIVILEGE_TOOL" rm /usr/bin/nvim + else + [ "$PRIVILEGE_TOOL" = "" ] + rm /usr/local/bin/nvim + rm /usr/bin/nvim + fi + ;; + *) + printf "Unsupported operating system.\n" + ;; esac printf "${GREEN}Neovim has been uninstalled successfully!${NC}\n" @@ -286,16 +298,16 @@ check_neovim_running() { 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." - ;; + [Yy] | [Yy][Ee][Ss]) + pkill nvim # Forcefully terminate Neovim + ;; + [Nn] | [Nn][Oo]) + echo "Exiting..." + exit 1 + ;; + *) + handle_error "Invalid choice." + ;; esac fi } @@ -319,16 +331,16 @@ else read -p "Install Neovim? (y/n): " install_choice case $install_choice in - [Yy]) - choose_version - ;; - [Nn]) - echo "Exiting..." - exit - ;; - *) - handle_error "Invalid choice. Please enter 'y' for yes or 'n' for no." - ;; + [Yy]) + choose_version + ;; + [Nn]) + echo "Exiting..." + exit + ;; + *) + handle_error "Invalid choice. Please enter 'y' for yes or 'n' for no." + ;; esac fi @@ -384,24 +396,24 @@ while [ "$SHOW_PROMPT" -gt 0 ]; do read -p "Enter a number or press 'q' to quit: " choice case $choice in - 1) - update_version - ;; - 2) - check_version_updates - ;; - 3) - uninstall_neovim - ;; - 4) - nvim - ;; - 5 | [Qq]) - echo "Exiting..." - exit - ;; - *) - handle_error "Invalid choice. Please choose a valid option by entering the corresponding number or press 'q' to 'quit'." - ;; + 1) + update_version + ;; + 2) + check_version_updates + ;; + 3) + uninstall_neovim + ;; + 4) + nvim + ;; + 5 | [Qq]) + echo "Exiting..." + exit + ;; + *) + handle_error "Invalid choice. Please choose a valid option by entering the corresponding number or press 'q' to 'quit'." + ;; esac done -- cgit v1.2.3 From 7b8434f5b5572304c7991e6d8d35978dc23f4564 Mon Sep 17 00:00:00 2001 From: srdusr Date: Mon, 18 Sep 2023 22:20:54 +0200 Subject: Bspwm script to toggle window visibility --- bspwm-toggle-visibility.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 bspwm-toggle-visibility.sh diff --git a/bspwm-toggle-visibility.sh b/bspwm-toggle-visibility.sh new file mode 100755 index 0000000..45a4c53 --- /dev/null +++ b/bspwm-toggle-visibility.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Created By: srdusr +# Created On: Mon 18 Sep 2023 18:37:21 CAT +# Project: Bspwm script to toggle visibility of initial window and bring focus back to it + +# Get the ID of the currently focused desktop +current_desktop_id=$(bspc query -D -d focused --names) + +# Get the ID of the first hidden window in the current desktop +hidden_window_id=$(bspc query -N -d "$current_desktop_id" -n .hidden | head -n 1) + +# Check if there's a hidden window in the current desktop +if [[ -n "$hidden_window_id" ]]; then + # There's a hidden window, so unhide it + bspc node "$hidden_window_id" -g hidden=off + # Bring focus back to the previously hidden window + bspc node -f "$hidden_window_id" +else + # There's no hidden window in the current desktop, hide the first available window + first_window_id=$(bspc query -N -n focused.window) + bspc node "$first_window_id" -g hidden=on +fi -- cgit v1.2.3 From 62140bc00089af7599cc4b2129ab1d4bba4a7796 Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 17 Oct 2023 13:53:12 +0200 Subject: Fixed command not found (choose_version) to update_version --- neovim.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neovim.sh b/neovim.sh index 3ced5dd..e905add 100755 --- a/neovim.sh +++ b/neovim.sh @@ -332,7 +332,7 @@ else case $install_choice in [Yy]) - choose_version + update_version ;; [Nn]) echo "Exiting..." -- cgit v1.2.3