From 284f3513916f7392e86e8e8704ff104bcd7f93fa Mon Sep 17 00:00:00 2001 From: Dalosuuu Date: Fri, 4 Apr 2025 04:12:26 -0400 Subject: [PATCH 1/2] feat: Improve dependency management with user prompt for installation - Added functionality to detect missing dependencies and list them all at once. - Prompted the user to confirm installation of all missing dependencies in a single step. - Enhanced the function to handle installation based on the Linux distribution. - Ensured the script exits gracefully if the user declines to install dependencies. - Improved user experience by reducing repetitive prompts for each missing dependency. --- layout_manager.sh | 83 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/layout_manager.sh b/layout_manager.sh index a67111a..1f97498 100755 --- a/layout_manager.sh +++ b/layout_manager.sh @@ -14,36 +14,65 @@ # #{ CHECK DEPENDENCIES -VIM_BIN="$(whereis -b vim | awk '{print $2}')" -NVIM_BIN="$(whereis -b nvim | awk '{print $2}')" -JQ_BIN="$(whereis -b jq | awk '{print $2}')" -XDOTOOL_BIN="$(whereis -b xdotool | awk '{print $2}')" -XRANDR_BIN="$(whereis -b xrandr | awk '{print $2}')" -ROFI_BIN="$(whereis -b rofi | awk '{print $2}')" +# Detect Linux distribution +DISTRO=$(lsb_release -is 2>/dev/null || echo "Unkown") -if [ -z "$NVIM_BIN" ] && [ -z "$VIM_BIN" ]; then - echo missing vim or neovim, please install dependencies - exit 1 +# Function to install a package based on the detected DISTRO +install_package(){ + PACKAGE=$1 + case "$DISTRO" in + Ubuntu|Debian) + sudo apt update && sudo apt install -y "$PACKAGE" + ;; + Fedora) + sudo dnf install -y "$PACKAGE" + ;; + openSUSE|SUSE) + sudo zypper install -y "$PACKAGE" + ;; + Arch) + sudo pacman -Syu "$PACKAGE" --noconfirm + ;; + *) + echo "Unsupported distribution: $DISTRO" + exit 1 + ;; + esac +} + +# Check dependencies and collect missing ones +MISSING_DEPENDENCIES=() +check_dependency() { + BIN_PATH=$(whereis -b "$1" | awk '{print $2}') + if [ -z "$BIN_PATH" ]; then + MISSING_DEPENDENCIES+=("$2") + fi +} + +# List of dependencies and their package names +check_dependency "vim" "vim" +check_dependency "nvim" "neovim" +check_dependency "jq" "jq" +check_dependency "xdotool" "xdotool" +check_dependency "xrandr" "xrandr" +check_dependency "rofi" "rofi" + +# Ensure at least one editor is available +if [ -z "$(whereis -b vim | awk '{print $2}')" ] && [ -z "$(whereis -b nvim | awk '{print $2}')" ]; then + MISSING_DEPENDENCIES+=("vim") fi -if [ -z "$JQ_BIN" ]; then - echo missing jq, please install dependencies - exit 1 -fi - -if [ -z "$XDOTOOL_BIN" ]; then - echo missing xdotool, please install dependencies - exit 1 -fi - -if [ -z "$XRANDR_BIN" ]; then - echo missing xrandr, please install dependencies - exit 1 -fi - -if [ -z "$ROFI_BIN" ]; then - echo missing rofi, please install dependencies - exit 1 +# Prompt to install missing dependencies +if [ ${#MISSING_DEPENDENCIES[@]} -gt 0 ]; then + echo "The following dependencies are missing: ${MISSING_DEPENDENCIES[*]}" + read -p "Do you want to install them? [y/N]: " RESPONSE + if [[ "$RESPONSE" =~ ^[Yy]$ ]]; then + for PACKAGE in "${MISSING_DEPENDENCIES[@]}"; do + install_package "$PACKAGE" + done + else + echo "Skipping installation of dependencies. The script may not work as expected." +exit 1 fi # #} From 0021b159b2dec3f37a7542fca8448f302b482ea3 Mon Sep 17 00:00:00 2001 From: Dalosuuu Date: Fri, 4 Apr 2025 04:41:16 -0400 Subject: [PATCH 2/2] Fix --- layout_manager.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layout_manager.sh b/layout_manager.sh index 1f97498..6c90493 100755 --- a/layout_manager.sh +++ b/layout_manager.sh @@ -73,8 +73,8 @@ if [ ${#MISSING_DEPENDENCIES[@]} -gt 0 ]; then else echo "Skipping installation of dependencies. The script may not work as expected." exit 1 + fi fi - # #} if [ -z "$XDG_CONFIG_HOME" ]; then