From 944c46c53c9d35c6dfbf50e01672f97377d3f37a Mon Sep 17 00:00:00 2001 From: srdusr Date: Wed, 9 Aug 2023 23:55:19 +0200 Subject: Allowed kitty/alacritty to also work in wayland --- scratchpad | 86 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/scratchpad b/scratchpad index 1b3dfeb..5a9f3fb 100755 --- a/scratchpad +++ b/scratchpad @@ -4,50 +4,58 @@ # Created On: Tue 07 Mar 2023 15:06:47 PM CAT # Project: Agnostic scratchpad/dropdown terminal that works on most window managers +# Dependencies: wmctrl, xprop, xdo, xdotool +# NOTE: Ensure script is included in system's path and can therefore be invoked with the command 'scratchpad'. +# Furthermore make sure the terminal is using x11 as a backend in wayland to allow this to work. +# example: wezterm.lua: enable_wayland = false, +# kitty.conf: linux_display_server x11 + # Set the GDK_BACKEND and QT_QPA_PLATFORM environment variables to x11 to allow working in Wayland export GDK_BACKEND=x11 export QT_QPA_PLATFORM=xcb +export WAYLAND_DISPLAY="" +export WINIT_UNIX_BACKEND=x11 # List of supported terminals with dropdown class supported_terminals=( - "wezterm" - "kitty" - "alacritty" + "wezterm" + "kitty" + "alacritty" ) # Check if any of the supported terminals with scratchpad class are running for term in "${supported_terminals[@]}"; do - if pgrep -f "$term.*--class scratchpad" >/dev/null; then - my_term="$term" - break - fi + if pgrep -f "$term.*--class scratchpad" >/dev/null; then + my_term="$term" + break + fi done # If none of the supported terminals are running, start the first available one if [ "$my_term" = "" ]; then - for term in "${supported_terminals[@]}"; do - if command -v "$term" >/dev/null 2>&1; then - my_term="$term" - break - fi - done - if [ "$my_term" = "" ]; then - echo "No supported terminal found." - exit 1 - fi + for term in "${supported_terminals[@]}"; do + if command -v "$term" >/dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ "$my_term" = "" ]; then + echo "No supported terminal found." + exit 1 + fi - # Start the terminal with scratchpad class - case "$my_term" in - "wezterm") - wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & - ;; - "kitty") - kitty --class scratchpad tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & - ;; - "alacritty") - alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & - ;; - esac + # Start the terminal with scratchpad class + case "$my_term" in + "wezterm") + wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + "kitty") + kitty --class scratchpad tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + "alacritty") + alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & + ;; + esac fi # Get the window ID of the scratchpad terminal @@ -55,14 +63,14 @@ id="$(xdo id -N scratchpad)" # Toggle the visibility of the scratchpad terminal if [ "$id" != "" ]; then - if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then - # The scratchpad window is visible, so hide it - dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" - xdo hide "$id" 2>/dev/null - else - # The scratchpad window is hidden, so show it - xdo show "$id" - # Restore the dimensions of the window - xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null - fi + if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then + # The scratchpad window is visible, so hide it + dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" + xdo hide "$id" 2>/dev/null + else + # The scratchpad window is hidden, so show it + xdo show "$id" + # Restore the dimensions of the window + xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null + fi fi -- cgit v1.2.3 From 5259f1f402a7984b083be4df533af1ab5419106b Mon Sep 17 00:00:00 2001 From: srdusr Date: Thu, 10 Aug 2023 12:12:19 +0200 Subject: Autostart script for gnome settings --- autostart.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 autostart.sh diff --git a/autostart.sh b/autostart.sh new file mode 100644 index 0000000..fdacb86 --- /dev/null +++ b/autostart.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Load custom dconf settings +dconf load / <~/.config/dconf-custom/settings.dconf -- cgit v1.2.3 From dd73e8957717ac1d89925b4d237da4944e7d0334 Mon Sep 17 00:00:00 2001 From: srdusr Date: Thu, 10 Aug 2023 12:13:37 +0200 Subject: Fixed formatting and made script more concise (less overhead) --- scratchpad | 84 +++++++++++++++++++++++++++----------------------------------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/scratchpad b/scratchpad index 5a9f3fb..513a30c 100755 --- a/scratchpad +++ b/scratchpad @@ -7,70 +7,58 @@ # Dependencies: wmctrl, xprop, xdo, xdotool # NOTE: Ensure script is included in system's path and can therefore be invoked with the command 'scratchpad'. # Furthermore make sure the terminal is using x11 as a backend in wayland to allow this to work. -# example: wezterm.lua: enable_wayland = false, -# kitty.conf: linux_display_server x11 +# Example: wezterm.lua: enable_wayland = false, +# kitty.conf: linux_display_server x11 -# Set the GDK_BACKEND and QT_QPA_PLATFORM environment variables to x11 to allow working in Wayland +# Set the environment variables to x11 to allow working in Wayland export GDK_BACKEND=x11 export QT_QPA_PLATFORM=xcb export WAYLAND_DISPLAY="" export WINIT_UNIX_BACKEND=x11 -# List of supported terminals with dropdown class -supported_terminals=( - "wezterm" - "kitty" - "alacritty" -) +# Supported terminals and dropdown class +supported_terminals=("wezterm" "kitty" "alacritty") -# Check if any of the supported terminals with scratchpad class are running +# Check if any supported terminal with scratchpad class is running for term in "${supported_terminals[@]}"; do - if pgrep -f "$term.*--class scratchpad" >/dev/null; then - my_term="$term" - break - fi + if pgrep -f "$term.*--class scratchpad" >/dev/null; then + my_term="$term" + break + fi done -# If none of the supported terminals are running, start the first available one +# If no supported terminal is running, start the first available one if [ "$my_term" = "" ]; then - for term in "${supported_terminals[@]}"; do - if command -v "$term" >/dev/null 2>&1; then - my_term="$term" - break - fi - done - if [ "$my_term" = "" ]; then - echo "No supported terminal found." - exit 1 - fi + for term in "${supported_terminals[@]}"; do + if command -v "$term" >/dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ "$my_term" = "" ]; then + echo "No supported terminal found." && exit 1 + fi - # Start the terminal with scratchpad class - case "$my_term" in - "wezterm") - wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & - ;; - "kitty") - kitty --class scratchpad tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & - ;; - "alacritty") - alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash >/dev/null 2>&1 & - ;; - esac + # Start terminal with scratchpad class + case "$my_term" in + "wezterm") wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash & ;; + "kitty") kitty --class scratchpad tmux new-session -A -s tmux -e bash & ;; + "alacritty") alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash & ;; + esac fi # Get the window ID of the scratchpad terminal id="$(xdo id -N scratchpad)" -# Toggle the visibility of the scratchpad terminal +# Toggle scratchpad terminal visibility if [ "$id" != "" ]; then - if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then - # The scratchpad window is visible, so hide it - dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" - xdo hide "$id" 2>/dev/null - else - # The scratchpad window is hidden, so show it - xdo show "$id" - # Restore the dimensions of the window - xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null - fi + if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then + # Scratchpad is visible, hide it + dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" + xdo hide "$id" 2>/dev/null + else + # Scratchpad is hidden, show it and restore dimensions + xdo show "$id" + xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null + fi fi -- cgit v1.2.3 From c40157f414d5b8e97d8efa845a699da3b4f1d8b2 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 12 Aug 2023 19:46:11 +0200 Subject: Initial commit --- neovim.sh | 338 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 338 insertions(+) create mode 100644 neovim.sh diff --git a/neovim.sh b/neovim.sh new file mode 100644 index 0000000..827e3a0 --- /dev/null +++ b/neovim.sh @@ -0,0 +1,338 @@ +#!/bin/bash + +# 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 + +# Color definitions +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color +BOLD=$(tput bold) +NORMAL=$(tput sgr0) + +# Check if necessary applications are installed +check_dependencies() { + missing_dependencies=() + + for cmd in wget curl xmllint datediff; do + if ! [ -x "$(command -v "$cmd")" ]; then + missing_dependencies+=("$cmd") + fi + done + + if [ ${#missing_dependencies[@]} -gt 0 ]; then + printf "\n${RED}Missing dependencies: ${missing_dependencies[*]}. Please install them to continue!${NC}\n" + exit 1 + fi +} + +# Check for privilege escalation tools +check_privilege_tools() { + if [ -x "$(command -v sudo)" ]; then + PRIVILEGE_TOOL="sudo" + elif [ -x "$(command -v doas)" ]; then + PRIVILEGE_TOOL="doas" + elif [ -x "$(command -v pkexec)" ]; then + PRIVILEGE_TOOL="pkexec" + elif [ -x "$(command -v dzdo)" ]; then + PRIVILEGE_TOOL="dzdo" + elif [ "$(id -u)" -eq 0 ]; then + PRIVILEGE_TOOL="" # root + else + PRIVILEGE_TOOL="" # No privilege escalation mechanism found + printf "\n${RED}Error: No privilege escalation tool (sudo, doas, pkexec, dzdo, or root privileges) found. You may not have sufficient permissions to run this script.${NC}\n" + 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 ;; + *) echo "Invalid choice. Exiting..." && exit ;; + esac + fi +} + +check_privilege_tools + +# Install Neovim +install_neovim() { + printf "${GREEN}Installing Neovim...${NC}\n" + + # Detect the operating system to determine the appropriate installation method + case "$(uname -s)" in + Linux) + printf "Detected Linux OS.\n" + # Check if FUSE is available + if [ -x "$(command -v fusermount)" ]; then + printf "FUSE is available. Downloading and running the AppImage...\n" + wget https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -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" + wget https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -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 + ;; + + Darwin) + printf "Detected macOS.\n" + wget https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz -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 + ;; + + MINGW*) + printf "Detected Windows.\n" + if [ "$PRIVILEGE_TOOL" = "sudo" ]; then + curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage && chmod +x nvim.appimage + "$PRIVILEGE_TOOL" cp nvim.appimage /usr/local/bin/nvim + "$PRIVILEGE_TOOL" mv /usr/local/bin/nvim /usr/bin + nvim + elif [ "$PRIVILEGE_TOOL" = "" ]; then + curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage && chmod +x nvim.appimage + 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" + ;; + esac + + printf "${GREEN}Neovim has been installed successfully!${NC}\n" +} + +# Uninstall Neovim +uninstall_neovim() { + printf "${RED}Uninstalling Neovim...${NC}\n" + + # 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 + "$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" +} + +# Check if Neovim is already installed +check_neovim_installed() { + if [ -x "$(command -v nvim)" ]; then + return 0 # Neovim is installed + else + return 1 # Neovim is not installed + fi +} + +# Define the variable to control the prompt +SHOW_PROMPT=1 + +# Check if necessary dependencies are installed +check_dependencies + +# Check if Neovim is already installed +if check_neovim_installed; then + printf "${GREEN}Neovim is already installed!${NC}\n" +else + # Prompt user for initial installation + read -p "Neovim is not installed. Do you want to install it? [yes/no] " install_choice + case $install_choice in + [Yy]*) install_neovim ;; + [Nn]*) ;; + *) echo "Please answer yes or no." ;; + esac +fi + +# Fetch the latest Neovim Nightly release information from GitHub +wget https://github.com/neovim/neovim/releases/tag/nightly -q -O - >/tmp/nvim_release_info +RESPONSE=$(wget https://github.com/neovim/neovim/releases/tag/nightly --save-headers -O - 2>&1) + +# Check if the release exists +if [[ "$RESPONSE" =~ 404\ Not\ Found ]]; then + printf "${RED}Unable to fetch latest Neovim Nightly info. Exiting...${NC}\n" + exit +fi + +# Initialize variables +should_prompt=0 +current_version=$(nvim --version | head -n 1) +new_version=$(xmllint --html --xpath "//pre//code/node()" /tmp/nvim_release_info 2>/dev/null | grep NVIM) +current_datetime_iso=$(date --iso-8601=ns) +new_release_datetime_iso=$(xmllint --html --xpath "string(//relative-time/@datetime)" /tmp/nvim_release_info 2>/dev/null) +time_since_release=$(datediff "$new_release_datetime_iso" "$current_datetime_iso" -f "%H hours %M minutes ago") + +# Check if the new Neovim version is available +if [[ "$new_version" == "" ]]; then + printf "\n${RED}Failed to retrieve latest Neovim Nightly version from the repository. Aborting...${NC}\n" + exit +fi + +# Check if the current version is already the latest +if [[ "$current_version" == "$new_version" ]]; then + printf "\n${RED}No new ${BOLD}Neovim Nightly${NORMAL}${RED} version found!\n${NC}Last release: ${time_since_release}\nExiting...\n" + exit +fi + +# If a newer version is found, prompt the user +if [[ "$current_version" != "$new_version" ]]; then + printf "\n${GREEN}New ${BOLD}Neovim Nightly${NORMAL}${GREEN} version available!${NC}\n${current_version} -> ${BOLD}${new_version}${NORMAL}\nReleased: ${time_since_release}\n\n" + should_prompt=1 +fi + +# Function to update Neovim Nightly +update_neovim() { + printf "${RED}Updating Neovim Nightly...${NC}\n" + download_url="https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage" + curl_command="curl -L -w http_code=%{http_code}" + curl_output=$("$curl_command" "$download_url" -o /tmp/nvim) + http_code=$(echo "$curl_output" | sed -e 's/.*\http_code=//') + error_message=$(echo "$curl_output" | sed -e 's/http_code.*//') + + if [[ $http_code == 200 ]]; then + chmod +x /tmp/nvim + "$PRIVILEGE_TOOL" cp /tmp/nvim /usr/local/bin + "$PRIVILEGE_TOOL" mv /tmp/nvim /usr/bin + printf "${GREEN}Neovim Nightly updated successfully!${NC}\n" + else + printf "${RED}Failed to update Neovim Nightly! ERROR: ${error_message}${NC}\n" + fi +} + +rm /tmp/nvim_release_info + +downgrade_neovim() { + # Fetch all the release tags from GitHub + ALL_TAGS=$(curl -s "https://api.github.com/repos/neovim/neovim/tags" | grep '"name":' | cut -d '"' -f 4) + + # Filter out major version tags (assumes version tag format is "vx.y.z") + MAJOR_VERSIONS=$(echo "$ALL_TAGS" | grep -E "^v[0-9]+\.[0-9]+\.0$") + + # Show available major versions to the user + echo "Available major versions:" + echo "$MAJOR_VERSIONS" + + # Ask user to choose a version + read -p "Enter the major version to downgrade to (e.g., v0.1, v0.2, ...): " DESIRED_MAJOR_VERSION + + # Construct the desired version tag + DESIRED_VERSION=$(echo "$MAJOR_VERSIONS" | grep "$DESIRED_MAJOR_VERSION") + + if [ "$DESIRED_VERSION" = "" ]; then + echo "Invalid major version. Exiting..." + exit 1 + fi + + printf "${RED}Downgrading Neovim to version $DESIRED_VERSION...${NC}\n" + + # Construct the URL for the desired version's release page on GitHub + RELEASE_URL="https://github.com/neovim/neovim/releases/tag/$DESIRED_VERSION" + + # Download the release page HTML + wget "$RELEASE_URL" -q -O /tmp/neovim_release.html + + # Find the download URL for the desired version's binary + DOWNLOAD_URL=$(grep -o "https://github.com/neovim/neovim/releases/download/$DESIRED_VERSION/nvim.appimage" /tmp/neovim_release.html) + + # Download the desired version of Neovim + wget "$DOWNLOAD_URL" -q -O /tmp/nvim + + # Make the downloaded binary executable + chmod +x /tmp/nvim + + # Install the downloaded binary to appropriate locations + "$PRIVILEGE_TOOL" cp /tmp/nvim /usr/local/bin + "$PRIVILEGE_TOOL" mv /tmp/nvim /usr/bin + + # Clean up temporary files + rm /tmp/neovim_release.html + + printf "${GREEN}Neovim has been downgraded to version $DESIRED_VERSION successfully!${NC}\n" +} + +use_stable_neovim() { + # Fetch the latest stable version tag from GitHub releases + STABLE_NVIM_VERSION=$(curl -s "https://api.github.com/repos/neovim/neovim/releases/latest" | grep '"tag_name":' | cut -d '"' -f 4) + + printf "${RED}Using Latest Stable Neovim version $STABLE_NVIM_VERSION...${NC}\n" + + # Construct the URL for the latest stable version's release page on GitHub + RELEASE_URL="https://github.com/neovim/neovim/releases/tag/$STABLE_NVIM_VERSION" + + # Download the release page HTML + wget "$RELEASE_URL" -q -O /tmp/neovim_release.html + + # Find the download URL for the latest stable version's binary + DOWNLOAD_URL=$(grep -o "https://github.com/neovim/neovim/releases/download/$STABLE_NVIM_VERSION/nvim.appimage" /tmp/neovim_release.html) + + # Download the latest stable version of Neovim + wget "$DOWNLOAD_URL" -q -O /tmp/nvim + + # Make the downloaded binary executable + chmod +x /tmp/nvim + + # Install the downloaded binary to appropriate locations + "$PRIVILEGE_TOOL" cp /tmp/nvim /usr/local/bin + "$PRIVILEGE_TOOL" mv /tmp/nvim /usr/bin + + # Clean up temporary files + rm /tmp/neovim_release.html + + printf "${GREEN}Latest Stable Neovim version $STABLE_NVIM_VERSION has been set up successfully!${NC}\n" +} + +while [ "$SHOW_PROMPT" -gt 0 ]; do + read -p "Do you wish to update, downgrade, or use stable Neovim? [update/downgrade/stable/no] " choice + case $choice in + [Uu]*) + update_neovim + break + ;; + [Dd]*) + downgrade_neovim + break + ;; + [Ss]*) + use_stable_neovim + break + ;; + [Nn]*) exit ;; + *) echo "Please choose update, downgrade, stable, or no." ;; + esac +done -- cgit v1.2.3 From 00d73345744a368c083d35152bb15c05a90c3cf0 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 12 Aug 2023 23:31:54 +0200 Subject: Made executable --- neovim.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 neovim.sh diff --git a/neovim.sh b/neovim.sh old mode 100644 new mode 100755 -- cgit v1.2.3 From 88cc39a51731276d45d7a2fb79ec7956d753da35 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 12 Aug 2023 23:32:22 +0200 Subject: Made executable and get full path --- autostart.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) mode change 100644 => 100755 autostart.sh diff --git a/autostart.sh b/autostart.sh old mode 100644 new mode 100755 index fdacb86..f15deda --- a/autostart.sh +++ b/autostart.sh @@ -1,4 +1,7 @@ #!/bin/bash +# Set the environment variable +export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ | tr '\0' '\n' | cut -d= -f2-) + # Load custom dconf settings -dconf load / <~/.config/dconf-custom/settings.dconf +/usr/bin/dconf load / <$HOME/.config/dconf-custom/settings.dconf -- cgit v1.2.3 From cdb7ef208bc4ad590cbb9317ea472ccac8d7e3a0 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 12 Aug 2023 23:44:22 +0200 Subject: Use dbus-launch --- autostart.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/autostart.sh b/autostart.sh index f15deda..dee4dc8 100755 --- a/autostart.sh +++ b/autostart.sh @@ -1,7 +1,4 @@ #!/bin/bash -# Set the environment variable -export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ | tr '\0' '\n' | cut -d= -f2-) - -# Load custom dconf settings -/usr/bin/dconf load / <$HOME/.config/dconf-custom/settings.dconf +# Launch the dconf command with dbus-launch and load custom dconf settings +dbus-launch /usr/bin/dconf load / <"$HOME"/.config/dconf-custom/settings.dconf -- cgit v1.2.3 From fd04753c589e0f723cd8202273d9862e4ef527f1 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 13 Aug 2023 14:09:52 +0200 Subject: Initial commit --- gsettings.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 gsettings.sh diff --git a/gsettings.sh b/gsettings.sh new file mode 100644 index 0000000..120f837 --- /dev/null +++ b/gsettings.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Disable screen lock +gsettings set org.gnome.desktop.screensaver lock-enabled false + +# Mutter Overlay Key +gsettings set org.gnome.mutter overlay-key '' + +# Disable update notification +gsettings set org.gnome.software enable-receipts false + +# Custom Keybinding Names +gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybinding-names "['custom-keybinding']" + +# Custom Keybinding 0 +gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybindings:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom-keybinding/ name "scratchpad" +gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybindings:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom-keybinding/ command "scratchpad" +gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybindings:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom-keybinding/ binding "T" + -- cgit v1.2.3 From 45c2b35ce93bd7dc77352d29a9b42350a733fb85 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 13 Aug 2023 14:24:45 +0200 Subject: Made executable and fixed "disable updates" and "custom keybindings" --- gsettings.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) mode change 100644 => 100755 gsettings.sh diff --git a/gsettings.sh b/gsettings.sh old mode 100644 new mode 100755 index 120f837..dc27f33 --- a/gsettings.sh +++ b/gsettings.sh @@ -7,13 +7,12 @@ gsettings set org.gnome.desktop.screensaver lock-enabled false gsettings set org.gnome.mutter overlay-key '' # Disable update notification -gsettings set org.gnome.software enable-receipts false +gsettings set org.gnome.software download-updates false # Custom Keybinding Names -gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybinding-names "['custom-keybinding']" +gsettings set org.gnome.settings-daemon.plugins,media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']" # Custom Keybinding 0 -gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybindings:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom-keybinding/ name "scratchpad" -gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybindings:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom-keybinding/ command "scratchpad" -gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybindings:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom-keybinding/ binding "T" - +gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding "T" +gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command "scratchpad" +gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name "scratchpad" -- cgit v1.2.3 From 95b358e32809d7fa60fb6a253bf9f08d5f53776c Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 13 Aug 2023 14:26:45 +0200 Subject: Also disable idle delay --- gsettings.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gsettings.sh b/gsettings.sh index dc27f33..5c4753b 100755 --- a/gsettings.sh +++ b/gsettings.sh @@ -2,6 +2,7 @@ # Disable screen lock gsettings set org.gnome.desktop.screensaver lock-enabled false +gsettings set org.gnome.desktop.session idle-delay 0 # Mutter Overlay Key gsettings set org.gnome.mutter overlay-key '' -- cgit v1.2.3 From 9fbe2a95bec9c848282689b7a339da8f0deaaff8 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 13 Aug 2023 14:41:49 +0200 Subject: Fixed automatic updates notifications to false --- gsettings.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gsettings.sh b/gsettings.sh index 5c4753b..6e77aa6 100755 --- a/gsettings.sh +++ b/gsettings.sh @@ -8,12 +8,13 @@ gsettings set org.gnome.desktop.session idle-delay 0 gsettings set org.gnome.mutter overlay-key '' # Disable update notification -gsettings set org.gnome.software download-updates false +#gsettings set org.gnome.software download-updates false +gsettings set com.ubuntu.update-notifier no-show-notifications true # Custom Keybinding Names -gsettings set org.gnome.settings-daemon.plugins,media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']" +gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']" # Custom Keybinding 0 -gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding "T" +gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding "T" gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command "scratchpad" gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name "scratchpad" -- cgit v1.2.3 From 263433f4181e3d137afccbeb486fc2e27debf824 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 13 Aug 2023 15:05:30 +0200 Subject: If datediff is unavailable then first check for dateutils.ddiff and use an alias if true --- neovim.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/neovim.sh b/neovim.sh index 827e3a0..8c39d71 100755 --- a/neovim.sh +++ b/neovim.sh @@ -21,6 +21,10 @@ check_dependencies() { fi done + if [ "${missing_dependencies[*]}" = "datediff" ] && [ -x "$(command -v dateutils.ddiff)" ]; then + alias datediff='dateutils.ddiff' + fi + if [ ${#missing_dependencies[@]} -gt 0 ]; then printf "\n${RED}Missing dependencies: ${missing_dependencies[*]}. Please install them to continue!${NC}\n" exit 1 -- cgit v1.2.3 From 857a3431d4bf3a241215c4a5df3be388ea9d2691 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 13 Aug 2023 16:54:43 +0200 Subject: Fixed different executable names for datediff --- neovim.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/neovim.sh b/neovim.sh index 8c39d71..8591584 100755 --- a/neovim.sh +++ b/neovim.sh @@ -11,18 +11,25 @@ NC='\033[0m' # No Color BOLD=$(tput bold) NORMAL=$(tput sgr0) -# Check if necessary applications are installed +# Define the variable for the date difference command +DATEDIFF_COMMAND="datediff" + +# Check if necessary dependencies are installed check_dependencies() { missing_dependencies=() - for cmd in wget curl xmllint datediff; do + for cmd in wget curl xmllint; do if ! [ -x "$(command -v "$cmd")" ]; then missing_dependencies+=("$cmd") fi done - if [ "${missing_dependencies[*]}" = "datediff" ] && [ -x "$(command -v dateutils.ddiff)" ]; then - alias datediff='dateutils.ddiff' + if [ -x "$(command -v datediff)" ]; then + DATEDIFF_COMMAND="datediff" + elif [ -x "$(command -v dateutils.ddiff)" ]; then + DATEDIFF_COMMAND="dateutils.ddiff" + else + missing_dependencies+=("datediff") fi if [ ${#missing_dependencies[@]} -gt 0 ]; then @@ -200,7 +207,7 @@ current_version=$(nvim --version | head -n 1) new_version=$(xmllint --html --xpath "//pre//code/node()" /tmp/nvim_release_info 2>/dev/null | grep NVIM) current_datetime_iso=$(date --iso-8601=ns) new_release_datetime_iso=$(xmllint --html --xpath "string(//relative-time/@datetime)" /tmp/nvim_release_info 2>/dev/null) -time_since_release=$(datediff "$new_release_datetime_iso" "$current_datetime_iso" -f "%H hours %M minutes ago") +time_since_release=$("DATEDIFF_COMMAND" "$new_release_datetime_iso" "$current_datetime_iso" -f "%H hours %M minutes ago") # Check if the new Neovim version is available if [[ "$new_version" == "" ]]; then -- cgit v1.2.3 From 70170c5246bd50f466eefc4b3087372be20992ba Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 13 Aug 2023 16:55:47 +0200 Subject: Removed autostart.sh, unneeded --- autostart.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autostart.sh b/autostart.sh index dee4dc8..8d95402 100755 --- a/autostart.sh +++ b/autostart.sh @@ -2,3 +2,5 @@ # Launch the dconf command with dbus-launch and load custom dconf settings dbus-launch /usr/bin/dconf load / <"$HOME"/.config/dconf-custom/settings.dconf +#dconf load / < ~/.config/dconf/user.d/settings.conf + -- cgit v1.2.3 From 9aa23bca95515102c90dde5c66760a2be7d77956 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 13 Aug 2023 19:08:02 +0200 Subject: Rewrite entire script --- neovim.sh | 446 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 218 insertions(+), 228 deletions(-) diff --git a/neovim.sh b/neovim.sh index 8591584..5ed803d 100755 --- a/neovim.sh +++ b/neovim.sh @@ -8,32 +8,24 @@ RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color -BOLD=$(tput bold) -NORMAL=$(tput sgr0) -# Define the variable for the date difference command -DATEDIFF_COMMAND="datediff" +# Function to handle errors +handle_error() { + local message="$1" + printf "${RED}Error: $message${NC}\n" + exit 1 +} # Check if necessary dependencies are installed check_dependencies() { - missing_dependencies=() - - for cmd in wget curl xmllint; do - if ! [ -x "$(command -v "$cmd")" ]; then - missing_dependencies+=("$cmd") - fi - done + DOWNLOAD_COMMAND="" - if [ -x "$(command -v datediff)" ]; then - DATEDIFF_COMMAND="datediff" - elif [ -x "$(command -v dateutils.ddiff)" ]; then - DATEDIFF_COMMAND="dateutils.ddiff" + if [ -x "$(command -v wget)" ]; then + DOWNLOAD_COMMAND="wget -q -O" + elif [ -x "$(command -v curl)" ]; then + DOWNLOAD_COMMAND="curl -sSL -o" else - missing_dependencies+=("datediff") - fi - - if [ ${#missing_dependencies[@]} -gt 0 ]; then - printf "\n${RED}Missing dependencies: ${missing_dependencies[*]}. Please install them to continue!${NC}\n" + printf "${RED}Error: Neither wget nor curl found. Please install one of them to continue!${NC}\n" exit 1 fi } @@ -63,67 +55,168 @@ check_privilege_tools() { fi } -check_privilege_tools +# Check if Neovim is already installed +check_neovim_installed() { + if [ -x "$(command -v nvim)" ]; then + return 0 # Neovim is installed + else + return 1 # Neovim is not installed + fi +} + +# Nightly version +nightly_version() { + local url="https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage" + install_neovim "$url" +} + +# Stable version +stable_version() { + local url="https://github.com/neovim/neovim/releases/download/stable/nvim.appimage" + install_neovim "$url" +} + +# Specific version +specific_version() { + local version="$1" + local url="https://github.com/neovim/neovim/releases/download/$version/nvim.appimage" + install_neovim "$url" +} + +# Function to download a file using wget or curl +download_file() { + local url="$1" + local output="$2" + + $DOWNLOAD_COMMAND "$output" "$url" +} + +# Check if a specific version of Neovim exists +version_exists() { + local version="$1" + 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 + return 0 # Version exists + else + return 1 # Version does not exist + fi +} + +# Choose Version +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 ;; + 3) + # Ask user for specific version + read -p "Enter the specific version (e.g., v0.1.0): " specific_version + # Check if the specific version exists on GitHub releases + if version_exists "$specific_version"; then + # Install specific version + specific_version "$specific_version" + else + printf "${RED}The specified version $specific_version does not exist. Aborting...${NC}\n" + exit 1 + fi + ;; + *) + echo "Invalid choice. Exiting..." + exit 1 + ;; + esac +} # Install Neovim install_neovim() { - printf "${GREEN}Installing Neovim...${NC}\n" - - # Detect the operating system to determine the appropriate installation method + local url="$1" + printf "Downloading and installing Neovim $version_choice...\n" + # Determine the platform-specific installation steps case "$(uname -s)" in - Linux) - printf "Detected Linux OS.\n" - # Check if FUSE is available - if [ -x "$(command -v fusermount)" ]; then - printf "FUSE is available. Downloading and running the AppImage...\n" - wget https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -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 + 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 + + ;; + + 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 - else - printf "FUSE is not available. Downloading and extracting the AppImage...\n" - wget https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -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 - ;; + ;; + + 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 + ;; + esac - Darwin) - printf "Detected macOS.\n" - wget https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz -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 - ;; + printf "${GREEN}Neovim $version_choice has been installed successfully!${NC}\n" +} - MINGW*) - printf "Detected Windows.\n" - if [ "$PRIVILEGE_TOOL" = "sudo" ]; then - curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage && chmod +x nvim.appimage - "$PRIVILEGE_TOOL" cp nvim.appimage /usr/local/bin/nvim - "$PRIVILEGE_TOOL" mv /usr/local/bin/nvim /usr/bin - nvim - elif [ "$PRIVILEGE_TOOL" = "" ]; then - curl -LO https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage && chmod +x nvim.appimage - 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" - ;; +# 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 - printf "${GREEN}Neovim has been installed successfully!${NC}\n" + printf "${GREEN}Neovim has been updated successfully!${NC}\n" } # Uninstall Neovim @@ -163,187 +256,84 @@ uninstall_neovim() { printf "${GREEN}Neovim has been uninstalled successfully!${NC}\n" } -# Check if Neovim is already installed -check_neovim_installed() { - if [ -x "$(command -v nvim)" ]; then - return 0 # Neovim is installed - else - return 1 # Neovim is not installed - fi -} - # Define the variable to control the prompt SHOW_PROMPT=1 # Check if necessary dependencies are installed check_dependencies +# Check for privilege escalation tools +check_privilege_tools + # Check if Neovim is already installed if check_neovim_installed; then printf "${GREEN}Neovim is already installed!${NC}\n" else - # Prompt user for initial installation - read -p "Neovim is not installed. Do you want to install it? [yes/no] " install_choice - case $install_choice in - [Yy]*) install_neovim ;; - [Nn]*) ;; - *) echo "Please answer yes or no." ;; - esac -fi - -# Fetch the latest Neovim Nightly release information from GitHub -wget https://github.com/neovim/neovim/releases/tag/nightly -q -O - >/tmp/nvim_release_info -RESPONSE=$(wget https://github.com/neovim/neovim/releases/tag/nightly --save-headers -O - 2>&1) - -# Check if the release exists -if [[ "$RESPONSE" =~ 404\ Not\ Found ]]; then - printf "${RED}Unable to fetch latest Neovim Nightly info. Exiting...${NC}\n" - exit + choose_version fi -# Initialize variables -should_prompt=0 -current_version=$(nvim --version | head -n 1) -new_version=$(xmllint --html --xpath "//pre//code/node()" /tmp/nvim_release_info 2>/dev/null | grep NVIM) -current_datetime_iso=$(date --iso-8601=ns) -new_release_datetime_iso=$(xmllint --html --xpath "string(//relative-time/@datetime)" /tmp/nvim_release_info 2>/dev/null) -time_since_release=$("DATEDIFF_COMMAND" "$new_release_datetime_iso" "$current_datetime_iso" -f "%H hours %M minutes ago") - -# Check if the new Neovim version is available -if [[ "$new_version" == "" ]]; then - printf "\n${RED}Failed to retrieve latest Neovim Nightly version from the repository. Aborting...${NC}\n" - exit -fi - -# Check if the current version is already the latest -if [[ "$current_version" == "$new_version" ]]; then - printf "\n${RED}No new ${BOLD}Neovim Nightly${NORMAL}${RED} version found!\n${NC}Last release: ${time_since_release}\nExiting...\n" - exit -fi +# Function to check for updates and display breaking changes +check_version_updates() { + local latest_version_url="https://api.github.com/repos/neovim/neovim/releases/latest" + local latest_version="" -# If a newer version is found, prompt the user -if [[ "$current_version" != "$new_version" ]]; then - printf "\n${GREEN}New ${BOLD}Neovim Nightly${NORMAL}${GREEN} version available!${NC}\n${current_version} -> ${BOLD}${new_version}${NORMAL}\nReleased: ${time_since_release}\n\n" - should_prompt=1 -fi + if [ -x "$(command -v curl)" ]; then + latest_version=$(curl -sSL "$latest_version_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + elif [ -x "$(command -v wget)" ]; then + latest_version=$(wget -qO - "$latest_version_url" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + else + printf "${RED}Error: Neither curl nor wget found. Please install one of them to continue!${NC}\n" + exit 1 + fi -# Function to update Neovim Nightly -update_neovim() { - printf "${RED}Updating Neovim Nightly...${NC}\n" - download_url="https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage" - curl_command="curl -L -w http_code=%{http_code}" - curl_output=$("$curl_command" "$download_url" -o /tmp/nvim) - http_code=$(echo "$curl_output" | sed -e 's/.*\http_code=//') - error_message=$(echo "$curl_output" | sed -e 's/http_code.*//') - - if [[ $http_code == 200 ]]; then - chmod +x /tmp/nvim - "$PRIVILEGE_TOOL" cp /tmp/nvim /usr/local/bin - "$PRIVILEGE_TOOL" mv /tmp/nvim /usr/bin - printf "${GREEN}Neovim Nightly updated successfully!${NC}\n" + if version_exists "$latest_version"; then + printf "${GREEN}An update is available!${NC}\n" + display_breaking_changes "$latest_version" else - printf "${RED}Failed to update Neovim Nightly! ERROR: ${error_message}${NC}\n" + printf "You have the latest version of Neovim.\n" fi } -rm /tmp/nvim_release_info - -downgrade_neovim() { - # Fetch all the release tags from GitHub - ALL_TAGS=$(curl -s "https://api.github.com/repos/neovim/neovim/tags" | grep '"name":' | cut -d '"' -f 4) - - # Filter out major version tags (assumes version tag format is "vx.y.z") - MAJOR_VERSIONS=$(echo "$ALL_TAGS" | grep -E "^v[0-9]+\.[0-9]+\.0$") +# Function to display breaking changes for a specific version +display_breaking_changes() { + local version="$1" + local changelog_url="https://github.com/neovim/neovim/releases/tag/$version" + local changelog="" - # Show available major versions to the user - echo "Available major versions:" - echo "$MAJOR_VERSIONS" - - # Ask user to choose a version - read -p "Enter the major version to downgrade to (e.g., v0.1, v0.2, ...): " DESIRED_MAJOR_VERSION - - # Construct the desired version tag - DESIRED_VERSION=$(echo "$MAJOR_VERSIONS" | grep "$DESIRED_MAJOR_VERSION") - - if [ "$DESIRED_VERSION" = "" ]; then - echo "Invalid major version. Exiting..." + if [ -x "$(command -v curl)" ]; then + changelog=$(curl -sSL "$changelog_url" | grep -oE '

Breaking Changes.*?' | sed 's/<[^>]*>//g') + elif [ -x "$(command -v wget)" ]; then + changelog=$(wget -qO - "$changelog_url" | grep -oE '

Breaking Changes.*?' | sed 's/<[^>]*>//g') + else + printf "${RED}Error: Neither curl nor wget found. Please install one of them to continue!${NC}\n" exit 1 fi - printf "${RED}Downgrading Neovim to version $DESIRED_VERSION...${NC}\n" - - # Construct the URL for the desired version's release page on GitHub - RELEASE_URL="https://github.com/neovim/neovim/releases/tag/$DESIRED_VERSION" - - # Download the release page HTML - wget "$RELEASE_URL" -q -O /tmp/neovim_release.html - - # Find the download URL for the desired version's binary - DOWNLOAD_URL=$(grep -o "https://github.com/neovim/neovim/releases/download/$DESIRED_VERSION/nvim.appimage" /tmp/neovim_release.html) - - # Download the desired version of Neovim - wget "$DOWNLOAD_URL" -q -O /tmp/nvim - - # Make the downloaded binary executable - chmod +x /tmp/nvim - - # Install the downloaded binary to appropriate locations - "$PRIVILEGE_TOOL" cp /tmp/nvim /usr/local/bin - "$PRIVILEGE_TOOL" mv /tmp/nvim /usr/bin - - # Clean up temporary files - rm /tmp/neovim_release.html - - printf "${GREEN}Neovim has been downgraded to version $DESIRED_VERSION successfully!${NC}\n" -} - -use_stable_neovim() { - # Fetch the latest stable version tag from GitHub releases - STABLE_NVIM_VERSION=$(curl -s "https://api.github.com/repos/neovim/neovim/releases/latest" | grep '"tag_name":' | cut -d '"' -f 4) - - printf "${RED}Using Latest Stable Neovim version $STABLE_NVIM_VERSION...${NC}\n" - - # Construct the URL for the latest stable version's release page on GitHub - RELEASE_URL="https://github.com/neovim/neovim/releases/tag/$STABLE_NVIM_VERSION" - - # Download the release page HTML - wget "$RELEASE_URL" -q -O /tmp/neovim_release.html - - # Find the download URL for the latest stable version's binary - DOWNLOAD_URL=$(grep -o "https://github.com/neovim/neovim/releases/download/$STABLE_NVIM_VERSION/nvim.appimage" /tmp/neovim_release.html) - - # Download the latest stable version of Neovim - wget "$DOWNLOAD_URL" -q -O /tmp/nvim - - # Make the downloaded binary executable - chmod +x /tmp/nvim - - # Install the downloaded binary to appropriate locations - "$PRIVILEGE_TOOL" cp /tmp/nvim /usr/local/bin - "$PRIVILEGE_TOOL" mv /tmp/nvim /usr/bin - - # Clean up temporary files - rm /tmp/neovim_release.html - - printf "${GREEN}Latest Stable Neovim version $STABLE_NVIM_VERSION has been set up successfully!${NC}\n" + printf "\nBreaking Changes in Neovim $version:\n" + printf "$changelog\n" } +# Main loop while [ "$SHOW_PROMPT" -gt 0 ]; do - read -p "Do you wish to update, downgrade, or use stable Neovim? [update/downgrade/stable/no] " choice + 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 case $choice in - [Uu]*) - update_neovim - break - ;; - [Dd]*) - downgrade_neovim - break - ;; - [Ss]*) - use_stable_neovim - break - ;; - [Nn]*) exit ;; - *) echo "Please choose update, downgrade, stable, or no." ;; + [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." + ;; esac done -- cgit v1.2.3 From 6fc42ad51136ec186a0786bd7f8f34ca2af29c64 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sun, 13 Aug 2023 19:28:41 +0200 Subject: Disable update-notifier --- gsettings.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gsettings.sh b/gsettings.sh index 6e77aa6..8391b75 100755 --- a/gsettings.sh +++ b/gsettings.sh @@ -8,8 +8,12 @@ gsettings set org.gnome.desktop.session idle-delay 0 gsettings set org.gnome.mutter overlay-key '' # Disable update notification -#gsettings set org.gnome.software download-updates false -gsettings set com.ubuntu.update-notifier no-show-notifications true +gsettings set org.gnome.software download-updates false +#gsettings set com.ubuntu.update-notifier no-show-notifications true +gconftool -s --type bool /apps/update-notifier/auto_launch false +#sudo rm /etc/xdg/autostart/upg-notifier-autostart.desktop +#sudo mv /etc/xdg/autostart/update-notifier.desktop /etc/xdg/autostart/update-notifier.desktop.old +#sudo mv /etc/xdg/autostart/gnome-software-service.desktop /etc/xdg/autostart/gnome-software-service.desktop.old # Custom Keybinding Names gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']" -- cgit v1.2.3 From 6109f733ebc72cc07e002e9297f516224685d338 Mon Sep 17 00:00:00 2001 From: srdusr Date: Mon, 14 Aug 2023 18:37:41 +0200 Subject: Trying to disable update-notifier --- gsettings.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gsettings.sh b/gsettings.sh index 8391b75..47f8e99 100755 --- a/gsettings.sh +++ b/gsettings.sh @@ -10,10 +10,9 @@ gsettings set org.gnome.mutter overlay-key '' # Disable update notification gsettings set org.gnome.software download-updates false #gsettings set com.ubuntu.update-notifier no-show-notifications true -gconftool -s --type bool /apps/update-notifier/auto_launch false #sudo rm /etc/xdg/autostart/upg-notifier-autostart.desktop -#sudo mv /etc/xdg/autostart/update-notifier.desktop /etc/xdg/autostart/update-notifier.desktop.old -#sudo mv /etc/xdg/autostart/gnome-software-service.desktop /etc/xdg/autostart/gnome-software-service.desktop.old +sudo mv /etc/xdg/autostart/update-notifier.desktop /etc/xdg/autostart/update-notifier.desktop.old +sudo mv /etc/xdg/autostart/gnome-software-service.desktop /etc/xdg/autostart/gnome-software-service.desktop.old # Custom Keybinding Names gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/']" -- cgit v1.2.3 From 20a8b52da8212b65d76885ddc2f5655a3789bc86 Mon Sep 17 00:00:00 2001 From: srdusr Date: Mon, 14 Aug 2023 18:38:42 +0200 Subject: Various changes and improvements (includes: progress bar, better user-input handling, etc...) --- neovim.sh | 281 +++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 176 insertions(+), 105 deletions(-) diff --git a/neovim.sh b/neovim.sh index 5ed803d..eab8521 100755 --- a/neovim.sh +++ b/neovim.sh @@ -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 -- cgit v1.2.3 From 428c120115a2faea9bbe118731406168eb66da97 Mon Sep 17 00:00:00 2001 From: srdusr Date: Sat, 19 Aug 2023 22:37:49 +0200 Subject: Combined "Change to specific version" and "Update neovim" into one "Update neovim" --- neovim.sh | 139 ++++++++++++++++++++++++++++---------------------------------- 1 file changed, 62 insertions(+), 77 deletions(-) diff --git a/neovim.sh b/neovim.sh index eab8521..4b67d48 100755 --- a/neovim.sh +++ b/neovim.sh @@ -61,29 +61,36 @@ 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+') + local version_output=$(nvim --version) + version_id="Nightly $(echo "$version_output" | 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+') + local version_output=$(nvim --version) + version_id="Stable $(echo "$version_output" | grep -oP 'v\d+\.\d+\.\d+')" + } # Specific version specific_version() { local version="$1" + + # Add 'v' prefix if not present + if [[ $version != v* ]]; then + version="v$version" + fi + 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+') + local version_output=$(nvim --version) + version_id="Stable $(echo "$version_output" | grep -oP 'v\d+\.\d+\.\d+')" } # Function to download a file using wget or curl @@ -104,67 +111,35 @@ download_file() { # Check if a specific version of Neovim exists version_exists() { local version="$1" + + # Add 'v' prefix if not present 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 + # Fetch all the release tags from GitHub + ALL_TAGS=$(curl -s "https://api.github.com/repos/neovim/neovim/tags" | grep '"name":' | cut -d '"' -f 4) + + # Check if the desired version is in the list of release tags + if echo "$ALL_TAGS" | grep -q "$version"; then return 0 # Version exists else return 1 # Version does not exist fi } -# Choose Version -choose_version() { - printf "${GREEN}Choose what version to install...${NC}\n" - - 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 - # Check if the specific version exists on GitHub releases - 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.${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_action="$2" - version_id="$3" - printf "Downloading and installing Neovim $version_id...\n" + 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" + else + printf "${GREEN}Updating $install_type Neovim to the latest version...${NC}\n" + fi + # Determine the platform-specific installation steps case "$(uname -s)" in Linux) @@ -214,45 +189,59 @@ install_neovim() { exit 1 ;; esac - if [ "$install_action" = "installed" ]; then - printf "${GREEN}Neovim $version_id has been installed successfully!${NC}\n" + printf "${GREEN}$install_type Neovim $version_id has been installed successfully!${NC}\n" + else + printf "${GREEN}$install_type Neovim has been updated successfully to $version_id!${NC}\n" fi } # Update Neovim to the latest version (nightly/stable) update_version() { - printf "${GREEN}Updating Neovim to the latest version...${NC}\n" - 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): " + 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) - nightly_version action="updated" + nightly_version valid_choice=true ;; 2) - stable_version 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 or 2)." + handle_error "Invalid choice. Please enter a valid option (1, 2 or 3)." ;; esac done - if [ "$action" = "updated" ]; then - printf "${GREEN}Neovim has been updated successfully to $version_id!${NC}\n" - fi } # Uninstall Neovim @@ -374,14 +363,13 @@ display_breaking_changes() { # Main loop while [ "$SHOW_PROMPT" -gt 0 ]; do - printf "Select an action:\n" + printf "Select an option:\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 + printf " 3. Uninstall Neovim\n" + printf " 4. Run Neovim\n" + printf " 5. Quit\n" + read -p "Enter a number or press 'q' to quit: " choice case $choice in 1) @@ -391,20 +379,17 @@ while [ "$SHOW_PROMPT" -gt 0 ]; do check_version_updates ;; 3) - choose_version - ;; - 4) uninstall_neovim ;; - 5) + 4) nvim ;; - 6 | [Qq]) + 5 | [Qq]) echo "Exiting..." exit ;; *) - handle_error "Invalid choice. Please choose a valid option by entering the corresponding number or 'q' to '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 23ff438313b905fd94e79da817b1b7082c80e149 Mon Sep 17 00:00:00 2001 From: srdusr Date: Mon, 21 Aug 2023 18:24:32 +0200 Subject: Python script to generate random data --- random_data.py | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100755 random_data.py diff --git a/random_data.py b/random_data.py new file mode 100755 index 0000000..071ab7c --- /dev/null +++ b/random_data.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 + +import os +import random +import string +import json +import datetime +import csv + + +def generate_random_string(length, charset=string.ascii_letters): + """Generate a random string of given length and character set.""" + return ''.join(random.choice(charset) for _ in range(length)) + + +def generate_random_number(min_value, max_value): + """Generate a random number within the specified range.""" + return random.randint(min_value, max_value) + + +def generate_random_date(start_date, end_date): + """Generate a random date within the specified range.""" + time_between_dates = end_date - start_date + days_between_dates = time_between_dates.days + random_number_of_days = random.randrange(days_between_dates) + random_date = start_date + datetime.timedelta(days=random_number_of_days) + return random_date.strftime("%Y-%m-%d") + + +def generate_sql_insert(table_name, columns, num_records): + """Generate SQL INSERT statements for populating a table.""" + sql_statements = [] + for _ in range(num_records): + values = [f"'{generate_random_string(int(input(f'Enter length for {column}: ')))}'" for column in columns] + sql = f"INSERT INTO {table_name} ({', '.join(columns)}) VALUES ({', '.join(values)});" + sql_statements.append(sql) + return sql_statements + + +def generate_placeholder_data(num_records, data_format): + """Generate placeholder data based on user-defined format.""" + placeholder_data = [] + for _ in range(num_records): + record = {} + for field, field_data in data_format.items(): + data_type = field_data['type'] + if data_type == 'string': + length = field_data['length'] + charset = field_data['charset'] + record[field] = generate_random_string(length, charset) + elif data_type == 'number': + min_value = field_data['min'] + max_value = field_data['max'] + record[field] = generate_random_number(min_value, max_value) + elif data_type == 'date': + start_date = datetime.datetime.strptime(field_data['start_date'], "%Y-%m-%d") + end_date = datetime.datetime.strptime(field_data['end_date'], "%Y-%m-%d") + record[field] = generate_random_date(start_date, end_date) + elif data_type == 'boolean': + record[field] = random.choice([True, False]) + placeholder_data.append(record) + return placeholder_data + + +def get_data_format_from_user(): + """Prompt the user for data format preferences.""" + data_format = {} + while True: + field = input("Enter field name (or 'done' to finish): ").strip() + if field.lower() == 'done': + break + + data_type = input(f"Enter data type for '{field}' (string/number/date/boolean): ").strip() + if data_type not in ['string', 'number', 'date', 'boolean']: + print("Invalid data type. Please enter 'string', 'number', 'date', or 'boolean'.") + continue + + if data_type == 'string': + length = int(input(f"Enter length for '{field}' (integer): ")) + charset = input(f"Enter character set for '{field}' (optional, press Enter for default): ").strip() + if not charset: + charset = string.ascii_letters + data_format[field] = {'type': 'string', 'length': length, 'charset': charset} + elif data_type == 'number': + min_value = int(input(f"Enter minimum value for '{field}' (integer): ")) + max_value = int(input(f"Enter maximum value for '{field}' (integer): ")) + data_format[field] = {'type': 'number', 'min': min_value, 'max': max_value} + elif data_type == 'date': + start_date = input(f"Enter start date for '{field}' (YYYY-MM-DD): ") + end_date = input(f"Enter end date for '{field}' (YYYY-MM-DD): ") + data_format[field] = {'type': 'date', 'start_date': start_date, 'end_date': end_date} + elif data_type == 'boolean': + data_format[field] = {'type': 'boolean'} + + return data_format + + +def get_file_type_from_user(): + """Prompt the user for the desired file type (e.g., JSON, CSV, SQL, TXT, MD, HTML).""" + while True: + file_type = input("Enter the desired file type for saving the data (json/csv/sql/txt/md/html): ").strip().lower() + if file_type in ['json', 'csv', 'sql', 'txt', 'md', 'html']: + return file_type + else: + print("Invalid file type. Please enter 'json', 'csv', 'sql', 'txt', 'md', or 'html'.") + + +def save_data_to_file(data, file_type): + """Save the generated data to a file of the specified type.""" + if file_type == 'json': + with open('placeholder_data.json', 'w') as json_file: + json.dump(data, json_file, indent=4) + elif file_type == 'csv': + with open('placeholder_data.csv', 'w', newline='') as csv_file: + fieldnames = data[0].keys() + writer = csv.DictWriter(csv_file, fieldnames=fieldnames) + writer.writeheader() + for record in data: + writer.writerow(record) + elif file_type == 'sql': + table_name = input("Enter the SQL table name: ") + columns = input("Enter column names separated by commas: ").split(',') + sql_statements = generate_sql_insert(table_name, columns, len(data)) + with open('generated_data.sql', 'w') as sql_file: + sql_file.write('\n'.join(sql_statements)) + elif file_type == 'txt': + with open('placeholder_data.txt', 'w') as txt_file: + for record in data: + txt_file.write(str(record) + '\n') + elif file_type == 'md': + with open('placeholder_data.md', 'w') as md_file: + for record in data: + md_file.write('- ' + ', '.join([f"{key}: {value}" for key, value in record.items()]) + '\n') + elif file_type == 'html': + with open('placeholder_data.html', 'w') as html_file: + html_file.write('\n\nPlaceholder Data\n\n\n') + for record in data: + html_file.write('
    \n') + for key, value in record.items(): + html_file.write(f'
  • {key}: {value}
  • \n') + html_file.write('
\n') + + +if __name__ == "__main__": + num_records = int(input("Enter the number of records to generate: ")) + data_format = get_data_format_from_user() + file_type = get_file_type_from_user() + + placeholder_data = generate_placeholder_data(num_records, data_format) + + save_data_to_file(placeholder_data, file_type) + + print(f"Data will be saved to: {os.path.abspath('generated_data.sql')}") -- cgit v1.2.3 From 486e9cb93a11060275903f32bc2822de44661458 Mon Sep 17 00:00:00 2001 From: srdusr Date: Mon, 21 Aug 2023 18:27:44 +0200 Subject: Updated install script, still-in-progress --- install.sh | 317 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 307 insertions(+), 10 deletions(-) mode change 100644 => 100755 install.sh diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index b811355..2f26daf --- a/install.sh +++ b/install.sh @@ -1,19 +1,316 @@ -#!/bin/bash +#!/usr/bin/env bash + +# Color definitions +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' # No Color + +# Function to handle errors +handle_error() { + local message="$1" + printf "${RED}Error: $message${NC}\n" +} if [[ $EUID -eq 0 ]]; then echo "This script must not be run as root" exit 1 fi -# Install system packages -packages=( - "ripgrep" - "xclip" - "ctags" -) +# Check if necessary dependencies are installed +check_download_dependencies() { + if [ -x "$(command -v wget)" ]; then + DOWNLOAD_COMMAND="wget" + elif [ -x "$(command -v curl)" ]; then + DOWNLOAD_COMMAND="curl" + else + printf "${RED}Error: Neither wget nor curl found. Please install one of them to continue!${NC}\n" + exit 1 + fi +} + +function get_or_update_dotfiles() { + if [ -d "$HOME/.cfg" ]; then + set MY_CWD = "$PWD" + cd "$HOME"/.cfg + git pull + cd "$(echo "$MY_CWD")" + else + git clone --bare https://github.com/srdusr/dotfiles.git "$HOME"/.cfg + fi +} + +function config() { + /usr/bin/git --git-dir="$HOME"/.cfg/ --work-tree="$HOME" "$@" +} + +function checkout_config() { + echo "Checking out config files..." + config checkout -for package in "${packages[@]}"; do - if ! pacman -Qi "$package" > /dev/null 2>&1; then - sudo pacman -S --noconfirm "$package" + if [ $? = 0 ]; then + echo "Checked out config." + else + echo "Backing up pre-existing dot files." + FILES=$(config checkout 2>&1 | egrep "\s+\." | awk {'print $1'}) + for file in "${FILES[@]}"; do + echo "Backing up $file" + mkdir -p .config-backup/"$(dirname "$file")" + mv "$file" .config-backup/"$file" + done + echo "Finished Backup" + fi + + echo "Verifying checkout..." + config checkout + config config status.showUntrackedFiles no +} + +# Check for privilege escalation tools +check_privilege_tools() { + if [ -x "$(command -v sudo)" ]; then + PRIVILEGE_TOOL="sudo" + elif [ -x "$(command -v doas)" ]; then + PRIVILEGE_TOOL="doas" + elif [ -x "$(command -v pkexec)" ]; then + PRIVILEGE_TOOL="pkexec" + elif [ -x "$(command -v dzdo)" ]; then + PRIVILEGE_TOOL="dzdo" + elif [ "$(id -u)" -eq 0 ]; then + PRIVILEGE_TOOL="" # root + else + PRIVILEGE_TOOL="" # No privilege escalation mechanism found + printf "\n${RED}Error: No privilege escalation tool (sudo, doas, pkexec, dzdo, or root privileges) found. You may not have sufficient permissions to run this script.${NC}\n" + 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 ;; + esac + fi +} + +# Create needed dirs and set proper permissions +for d in .cache .config .local; do + d="$HOME/$d" + if [ ! -d "$d" ]; then + mkdir -p "$d" + "$PRIVILEGE_TOOL" chown -R "$USER" "$d" + echo "Created $d" fi done + +# Function to change directory names from uppercase to lowercase +change_dir_names() { + local config_file="$HOME/.config/user-dirs.dirs" + + # Check if the system is not macOS + if [[ ! "$OSTYPE" == "darwin"* ]]; then + # Check if the config file exists + if [ -f "$config_file" ]; then + echo "Changing directory names from uppercase to lowercase..." + + # Read the lines from the config file and process them + while read -r line; do + # Extract variable name and path from each line + if [[ $line =~ ^[[:space:]]*([A-Z_]+)=\"(.+)\" ]]; then + var_name="${BASH_REMATCH[1]}" + var_path="${BASH_REMATCH[2]}" + + # Convert the variable name to lowercase + var_name_lowercase="$(echo "$var_name" | tr '[:upper:]' '[:lower:]')" + + # Check if the directory exists + if [ -d "$var_path" ]; then + # Rename the directory to lowercase + new_var_path="$HOME/${var_name_lowercase}" + mv "$var_path" "$new_var_path" + echo "Renamed $var_path to $new_var_path" + fi + fi + done <"$config_file" + + echo "Directory names changed successfully." + else + echo "The config file $config_file does not exist. Skipping directory name changes." + fi + else + echo "macOS detected. Skipping directory name changes." + fi +} + +# Check if a command is available +check_command() { + command -v "$1" >/dev/null 2>&1 +} + +# Check for required dependencies +check_dependencies() { + local dependencies=("git" "clang" "gcc" "make" "ninja" "cmake" "wmctrl" "xdo" "xdotool" "ripgrep" "fd" "tmux" "tree-sitter" "vim" "zsh") + local missing_dependencies=() + + for dep in "${dependencies[@]}"; do + if ! check_command "$dep"; then + missing_dependencies+=("$dep") + fi + done + + if [ ${#missing_dependencies[@]} -gt 0 ]; then + echo "Error: The following dependencies are missing: ${missing_dependencies[*]}" + exit 1 + fi +} + +# Install Fzf +install_fzf() { + if ! check_command "fzf"; then + echo "Installing Fzf..." + local INSTALL_CMD="git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install" + if [ "$PRIVILEGE_TOOL" != "" ]; then + "$PRIVILEGE_TOOL" bash -c "$INSTALL_CMD" + else + bash -c "$INSTALL_CMD" + fi + else + echo "Fzf is already installed." + fi +} + +# Install Zsh plugins +install_zsh_plugins() { + local zsh_plugins_dir="$HOME/.config/zsh/plugins" + + if [ ! -d "$zsh_plugins_dir/zsh-you-should-use" ]; then + echo "Installing zsh-you-should-use..." + git clone https://github.com/MichaelAquilina/zsh-you-should-use.git "$zsh_plugins_dir/zsh-you-should-use" + else + echo "zsh-you-should-use is already installed." + fi + + if [ ! -d "$zsh_plugins_dir/zsh-syntax-highlighting" ]; then + echo "Installing zsh-syntax-highlighting..." + git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$zsh_plugins_dir/zsh-syntax-highlighting" + else + echo "zsh-syntax-highlighting is already installed." + fi + + if [ ! -d "$zsh_plugins_dir/zsh-autosuggestions" ]; then + echo "Installing zsh-autosuggestions..." + git clone https://github.com/zsh-users/zsh-autosuggestions.git "$zsh_plugins_dir/zsh-autosuggestions" + else + echo "zsh-autosuggestions is already installed." + fi +} + +# Install Rust using rustup +install_rust() { + if ! check_command "rustup"; then + echo "Installing Rust using rustup..." + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + else + echo "Rust is already installed." + fi +} + +# Install Wezterm +install_wezterm() { + if ! check_command "wezterm"; then + echo "Installing Wezterm..." + git clone --depth=1 --branch=main --recursive https://github.com/wez/wezterm.git ~/wezterm + cd ~/wezterm || exit + git submodule update --init --recursive + ./get-deps + cargo build --release + cargo run --release --bin wezterm -- start + else + echo "Wezterm is already installed." + fi +} + +function install_font() { + FONT=$1 + ZIPFILE_NAME="${FONT}.zip" + DOWNLOAD_URL="https://github.com/ryanoasis/nerd-fonts/releases/download/v${NERDFONTS_LATEST_VERSION}/${ZIPFILE_NAME}" + echo "Downloading $DOWNLOAD_URL" + wget "$DOWNLOAD_URL" + unzip -u "$ZIPFILE_NAME" -d "$FONTS_DIR" -x "*.txt/*" -x "*.md/*" + rm "$ZIPFILE_NAME" +} + +function install_nerd_fonts() { + echo "Installing Nerd fonts" + + declare -a fonts=( + AnonymousPro + CascadiaCode + FiraCode + FiraMono + Hack + Iosevka + LiberationMono + Noto + Overpass + RobotoMono + Terminus + Ubuntu + UbuntuMono + ) + + if [[ "$OSTYPE" == "darwin"* ]]; then + brew tap homebrew/cask-fonts + for FONT in "${fonts[@]}"; do + brew install "font-$(sed --expression 's/\([A-Z]\)/-\L\1/g' --expression 's/^-//' <<<"$FONT")-nerd-font" + done + else + NERDFONTS_LATEST_VERSION="$(gh release list \ + --exclude-drafts \ + --exclude-pre-releases \ + --limit 1 \ + --repo ryanoasis/nerd-fonts | + grep Latest | + awk '{print substr($1, 2);}')" # take the first word of the line and remove the first char + + FONTS_DIR="${HOME}/.local/share/fonts" + + if [[ ! -d "$FONTS_DIR" ]]; then + mkdir -p "$FONTS_DIR" + fi + + for FONT in "${fonts[@]}"; do + confirm "Install $FONT?" && install_font "$FONT" + done + + find "$FONTS_DIR" -name '*Windows Compatible*' -delete + + fc-cache -fv + fi +} +# Main installation function +install() { + check_privilege_tool + + echo "This script will install and configure various tools and settings on your system." + read -p "Do you want to continue (y/n)? " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + + # Ask for privilege right away + "$PRIVILEGE_TOOL" echo -n + current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + + check_dependencies + change_dir_names + install_fzf + install_zsh_plugins + configure_zshrc + install_rust + install_wezterm + install_nerd_fonts + + echo "Installation completed." +} + +# Run the installation process +install -- cgit v1.2.3 From f074e608bfe1be13ad787c50feec6391737a4b9b Mon Sep 17 00:00:00 2001 From: srdusr Date: Tue, 22 Aug 2023 23:04:40 +0200 Subject: Move to home directory --- install.sh | 316 ------------------------------------------------------------- 1 file changed, 316 deletions(-) delete mode 100755 install.sh diff --git a/install.sh b/install.sh deleted file mode 100755 index 2f26daf..0000000 --- a/install.sh +++ /dev/null @@ -1,316 +0,0 @@ -#!/usr/bin/env bash - -# Color definitions -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' # No Color - -# Function to handle errors -handle_error() { - local message="$1" - printf "${RED}Error: $message${NC}\n" -} - -if [[ $EUID -eq 0 ]]; then - echo "This script must not be run as root" - exit 1 -fi - -# Check if necessary dependencies are installed -check_download_dependencies() { - if [ -x "$(command -v wget)" ]; then - DOWNLOAD_COMMAND="wget" - elif [ -x "$(command -v curl)" ]; then - DOWNLOAD_COMMAND="curl" - else - printf "${RED}Error: Neither wget nor curl found. Please install one of them to continue!${NC}\n" - exit 1 - fi -} - -function get_or_update_dotfiles() { - if [ -d "$HOME/.cfg" ]; then - set MY_CWD = "$PWD" - cd "$HOME"/.cfg - git pull - cd "$(echo "$MY_CWD")" - else - git clone --bare https://github.com/srdusr/dotfiles.git "$HOME"/.cfg - fi -} - -function config() { - /usr/bin/git --git-dir="$HOME"/.cfg/ --work-tree="$HOME" "$@" -} - -function checkout_config() { - echo "Checking out config files..." - config checkout - - if [ $? = 0 ]; then - echo "Checked out config." - else - echo "Backing up pre-existing dot files." - FILES=$(config checkout 2>&1 | egrep "\s+\." | awk {'print $1'}) - for file in "${FILES[@]}"; do - echo "Backing up $file" - mkdir -p .config-backup/"$(dirname "$file")" - mv "$file" .config-backup/"$file" - done - echo "Finished Backup" - fi - - echo "Verifying checkout..." - config checkout - config config status.showUntrackedFiles no -} - -# Check for privilege escalation tools -check_privilege_tools() { - if [ -x "$(command -v sudo)" ]; then - PRIVILEGE_TOOL="sudo" - elif [ -x "$(command -v doas)" ]; then - PRIVILEGE_TOOL="doas" - elif [ -x "$(command -v pkexec)" ]; then - PRIVILEGE_TOOL="pkexec" - elif [ -x "$(command -v dzdo)" ]; then - PRIVILEGE_TOOL="dzdo" - elif [ "$(id -u)" -eq 0 ]; then - PRIVILEGE_TOOL="" # root - else - PRIVILEGE_TOOL="" # No privilege escalation mechanism found - printf "\n${RED}Error: No privilege escalation tool (sudo, doas, pkexec, dzdo, or root privileges) found. You may not have sufficient permissions to run this script.${NC}\n" - 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 ;; - esac - fi -} - -# Create needed dirs and set proper permissions -for d in .cache .config .local; do - d="$HOME/$d" - if [ ! -d "$d" ]; then - mkdir -p "$d" - "$PRIVILEGE_TOOL" chown -R "$USER" "$d" - echo "Created $d" - fi -done - -# Function to change directory names from uppercase to lowercase -change_dir_names() { - local config_file="$HOME/.config/user-dirs.dirs" - - # Check if the system is not macOS - if [[ ! "$OSTYPE" == "darwin"* ]]; then - # Check if the config file exists - if [ -f "$config_file" ]; then - echo "Changing directory names from uppercase to lowercase..." - - # Read the lines from the config file and process them - while read -r line; do - # Extract variable name and path from each line - if [[ $line =~ ^[[:space:]]*([A-Z_]+)=\"(.+)\" ]]; then - var_name="${BASH_REMATCH[1]}" - var_path="${BASH_REMATCH[2]}" - - # Convert the variable name to lowercase - var_name_lowercase="$(echo "$var_name" | tr '[:upper:]' '[:lower:]')" - - # Check if the directory exists - if [ -d "$var_path" ]; then - # Rename the directory to lowercase - new_var_path="$HOME/${var_name_lowercase}" - mv "$var_path" "$new_var_path" - echo "Renamed $var_path to $new_var_path" - fi - fi - done <"$config_file" - - echo "Directory names changed successfully." - else - echo "The config file $config_file does not exist. Skipping directory name changes." - fi - else - echo "macOS detected. Skipping directory name changes." - fi -} - -# Check if a command is available -check_command() { - command -v "$1" >/dev/null 2>&1 -} - -# Check for required dependencies -check_dependencies() { - local dependencies=("git" "clang" "gcc" "make" "ninja" "cmake" "wmctrl" "xdo" "xdotool" "ripgrep" "fd" "tmux" "tree-sitter" "vim" "zsh") - local missing_dependencies=() - - for dep in "${dependencies[@]}"; do - if ! check_command "$dep"; then - missing_dependencies+=("$dep") - fi - done - - if [ ${#missing_dependencies[@]} -gt 0 ]; then - echo "Error: The following dependencies are missing: ${missing_dependencies[*]}" - exit 1 - fi -} - -# Install Fzf -install_fzf() { - if ! check_command "fzf"; then - echo "Installing Fzf..." - local INSTALL_CMD="git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install" - if [ "$PRIVILEGE_TOOL" != "" ]; then - "$PRIVILEGE_TOOL" bash -c "$INSTALL_CMD" - else - bash -c "$INSTALL_CMD" - fi - else - echo "Fzf is already installed." - fi -} - -# Install Zsh plugins -install_zsh_plugins() { - local zsh_plugins_dir="$HOME/.config/zsh/plugins" - - if [ ! -d "$zsh_plugins_dir/zsh-you-should-use" ]; then - echo "Installing zsh-you-should-use..." - git clone https://github.com/MichaelAquilina/zsh-you-should-use.git "$zsh_plugins_dir/zsh-you-should-use" - else - echo "zsh-you-should-use is already installed." - fi - - if [ ! -d "$zsh_plugins_dir/zsh-syntax-highlighting" ]; then - echo "Installing zsh-syntax-highlighting..." - git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$zsh_plugins_dir/zsh-syntax-highlighting" - else - echo "zsh-syntax-highlighting is already installed." - fi - - if [ ! -d "$zsh_plugins_dir/zsh-autosuggestions" ]; then - echo "Installing zsh-autosuggestions..." - git clone https://github.com/zsh-users/zsh-autosuggestions.git "$zsh_plugins_dir/zsh-autosuggestions" - else - echo "zsh-autosuggestions is already installed." - fi -} - -# Install Rust using rustup -install_rust() { - if ! check_command "rustup"; then - echo "Installing Rust using rustup..." - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - else - echo "Rust is already installed." - fi -} - -# Install Wezterm -install_wezterm() { - if ! check_command "wezterm"; then - echo "Installing Wezterm..." - git clone --depth=1 --branch=main --recursive https://github.com/wez/wezterm.git ~/wezterm - cd ~/wezterm || exit - git submodule update --init --recursive - ./get-deps - cargo build --release - cargo run --release --bin wezterm -- start - else - echo "Wezterm is already installed." - fi -} - -function install_font() { - FONT=$1 - ZIPFILE_NAME="${FONT}.zip" - DOWNLOAD_URL="https://github.com/ryanoasis/nerd-fonts/releases/download/v${NERDFONTS_LATEST_VERSION}/${ZIPFILE_NAME}" - echo "Downloading $DOWNLOAD_URL" - wget "$DOWNLOAD_URL" - unzip -u "$ZIPFILE_NAME" -d "$FONTS_DIR" -x "*.txt/*" -x "*.md/*" - rm "$ZIPFILE_NAME" -} - -function install_nerd_fonts() { - echo "Installing Nerd fonts" - - declare -a fonts=( - AnonymousPro - CascadiaCode - FiraCode - FiraMono - Hack - Iosevka - LiberationMono - Noto - Overpass - RobotoMono - Terminus - Ubuntu - UbuntuMono - ) - - if [[ "$OSTYPE" == "darwin"* ]]; then - brew tap homebrew/cask-fonts - for FONT in "${fonts[@]}"; do - brew install "font-$(sed --expression 's/\([A-Z]\)/-\L\1/g' --expression 's/^-//' <<<"$FONT")-nerd-font" - done - else - NERDFONTS_LATEST_VERSION="$(gh release list \ - --exclude-drafts \ - --exclude-pre-releases \ - --limit 1 \ - --repo ryanoasis/nerd-fonts | - grep Latest | - awk '{print substr($1, 2);}')" # take the first word of the line and remove the first char - - FONTS_DIR="${HOME}/.local/share/fonts" - - if [[ ! -d "$FONTS_DIR" ]]; then - mkdir -p "$FONTS_DIR" - fi - - for FONT in "${fonts[@]}"; do - confirm "Install $FONT?" && install_font "$FONT" - done - - find "$FONTS_DIR" -name '*Windows Compatible*' -delete - - fc-cache -fv - fi -} -# Main installation function -install() { - check_privilege_tool - - echo "This script will install and configure various tools and settings on your system." - read -p "Do you want to continue (y/n)? " -n 1 -r - echo - if [[ ! $REPLY =~ ^[Yy]$ ]]; then - exit 1 - fi - - # Ask for privilege right away - "$PRIVILEGE_TOOL" echo -n - current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - - check_dependencies - change_dir_names - install_fzf - install_zsh_plugins - configure_zshrc - install_rust - install_wezterm - install_nerd_fonts - - echo "Installation completed." -} - -# Run the installation process -install -- cgit v1.2.3 From ddf2e42ecf7445397f753170b13a475ac3a09aaa Mon Sep 17 00:00:00 2001 From: srdusr Date: Mon, 28 Aug 2023 21:06:43 +0200 Subject: Removed unneeded script --- autostart.sh | 6 ------ 1 file changed, 6 deletions(-) delete mode 100755 autostart.sh diff --git a/autostart.sh b/autostart.sh deleted file mode 100755 index 8d95402..0000000 --- a/autostart.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# Launch the dconf command with dbus-launch and load custom dconf settings -dbus-launch /usr/bin/dconf load / <"$HOME"/.config/dconf-custom/settings.dconf -#dconf load / < ~/.config/dconf/user.d/settings.conf - -- cgit v1.2.3 From e1bd334c2d06796efd7c079aa39c862b741c9b10 Mon Sep 17 00:00:00 2001 From: srdusr Date: Mon, 28 Aug 2023 21:06:58 +0200 Subject: Reformatted --- scratchpad | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/scratchpad b/scratchpad index 513a30c..8a1aea0 100755 --- a/scratchpad +++ b/scratchpad @@ -21,30 +21,30 @@ supported_terminals=("wezterm" "kitty" "alacritty") # Check if any supported terminal with scratchpad class is running for term in "${supported_terminals[@]}"; do - if pgrep -f "$term.*--class scratchpad" >/dev/null; then - my_term="$term" - break - fi + if pgrep -f "$term.*--class scratchpad" >/dev/null; then + my_term="$term" + break + fi done # If no supported terminal is running, start the first available one if [ "$my_term" = "" ]; then - for term in "${supported_terminals[@]}"; do - if command -v "$term" >/dev/null 2>&1; then - my_term="$term" - break - fi - done - if [ "$my_term" = "" ]; then - echo "No supported terminal found." && exit 1 - fi + for term in "${supported_terminals[@]}"; do + if command -v "$term" >/dev/null 2>&1; then + my_term="$term" + break + fi + done + if [ "$my_term" = "" ]; then + echo "No supported terminal found." && exit 1 + fi - # Start terminal with scratchpad class - case "$my_term" in - "wezterm") wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash & ;; - "kitty") kitty --class scratchpad tmux new-session -A -s tmux -e bash & ;; - "alacritty") alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash & ;; - esac + # Start terminal with scratchpad class + case "$my_term" in + "wezterm") wezterm start --class scratchpad -e tmux new-session -A -s tmux -e bash & ;; + "kitty") kitty --class scratchpad tmux new-session -A -s tmux -e bash & ;; + "alacritty") alacritty --class scratchpad -e tmux new-session -A -s tmux -e bash & ;; + esac fi # Get the window ID of the scratchpad terminal @@ -52,13 +52,13 @@ id="$(xdo id -N scratchpad)" # Toggle scratchpad terminal visibility if [ "$id" != "" ]; then - if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then - # Scratchpad is visible, hide it - dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" - xdo hide "$id" 2>/dev/null - else - # Scratchpad is hidden, show it and restore dimensions - xdo show "$id" - xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null - fi + if xwininfo -id "$id" | grep "Map State: IsViewable" >/dev/null; then + # Scratchpad is visible, hide it + dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')" + xdo hide "$id" 2>/dev/null + else + # Scratchpad is hidden, show it and restore dimensions + xdo show "$id" + xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null + fi fi -- cgit v1.2.3 From b9d5ce0f653d5dcdb939cc5cb3bb888f5abc13f9 Mon Sep 17 00:00:00 2001 From: srdusr Date: Mon, 11 Sep 2023 20:50:13 +0200 Subject: Disable keyboard plugin --- gsettings.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gsettings.sh b/gsettings.sh index 47f8e99..d4f6045 100755 --- a/gsettings.sh +++ b/gsettings.sh @@ -21,3 +21,6 @@ gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings "[ gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding "T" gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command "scratchpad" gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name "scratchpad" + +# Disable keyboard plugin +gsettings set org.gnome.settings-daemon.plugins.keyboard active false -- cgit v1.2.3