diff --git a/bash b/bash new file mode 160000 index 0000000..74357e7 --- /dev/null +++ b/bash @@ -0,0 +1 @@ +Subproject commit 74357e75d7e2817a0544099fd6833069484c2fd9 diff --git a/install.sh b/install.sh index 387412c..f9e5f2e 100755 --- a/install.sh +++ b/install.sh @@ -1,106 +1,21 @@ #!/usr/bin/env bash - -# ANSI color codes -RED='\033[0;31m' -CYAN='\033[0;36m' -YELLOW='\033[0;33m' -LIGHT_GREEN='\033[0;92m' -BOLD='\033[1m' -NC='\033[0m' # No Color - -echo_error() { - printf "${BOLD}${RED}ERROR: ${NC}${RED}%s${NC}\n" "$1" >&2 -} - -echo_info() { - printf "${BOLD}${CYAN}INFO: ${NC}${CYAN}%s${NC}\n" "$1" -} - -echo_warning() { - printf "${BOLD}${YELLOW}WARNING: ${NC}${YELLOW}%s${NC}\n" "$1" -} - -echo_note() { - printf "${BOLD}${LIGHT_GREEN}NOTE: ${NC}${LIGHT_GREEN}%s${NC}\n" "$1" -} - -# ─< Check if the given command exists silently >───────────────────────────────────────── -command_exists() { - command -v "$@" >/dev/null 2>&1 -} - -# ─< Check if the user is root and set sudo variable if necessary >─────────────────────── -check_root() { - if ((EUID != 0)); then - if command_exists sudo; then - echo_info "User is not root. Using sudo for privileged operations." - _sudo="sudo" - else - echo_error "No sudo found and you're not root! Can't install packages." - return 1 - fi +getImports() { + local url="$1" + local import="$(mktemp)" + if command_exists curl; then + curl -fsSL $url -o $import + elif command_exists wget; then + wget -O $import $url else - echo_info "Root access confirmed." - _sudo="" + echo "curl/wget is required, but missing.." + exit 69 fi + + source "$import" + sleep 0.2 + rm "$import" + echo "imported $url" } - -# ─< Distribution detection and installation >──────────────────────────────────────── -get_packager() { - pkger=( - "apt" - "pacman" - "dnf" - "apk" - "zypper" - ) - - for pkger in "${pkger[@]}"; do - if command_exists "$pkger"; then - echo_info "Found package manager: $pkger" - case "$pkger" in - "apt") - $_sudo apt-get update - _install() { $_sudo apt-get install --assume-yes "$@"; } - arch="false" - ;; - "pacman") - $_sudo pacman -Syy - if command_exists paru; then - echo_info "Using paru as aur helper" - _install() { paru -S --noconfirm "$@"; } - elif command_exists yay; then - echo_info "Using yay as aur helper" - _install() { yay -S --noconfirm "$@"; } - else - echo_info "Using no aur helper!" - _install() { $_sudo pacman -S --noconfirm "$@"; } - fi - arch="true" - ;; - "dnf") - $_sudo dnf update - _install() { $_sudo dnf install -y "$@"; } - arch="false" - ;; - "apk") - _install() { $_sudo apk add "$@"; } - arch="false" - ;; - "zypper") - $_sudo zypper ref - _install() { $_sudo zypper in -y "$@"; } - arch="false" - ;; - esac - fi - done -} - -silentexec() { - "$@" >/dev/null 2>&1 -} - __pre_stow__() { echo_note "__pre_stow__" conf="$HOME/.config" @@ -121,16 +36,19 @@ __pre_stow__() { "zellij" ) + pen yellow "Trying to clean the environment.." + if [ ! -d "$bak_dir" ]; then - echo_info "backup dir created at $bak_dir" && + repen yellow "backup dir created at $bak_dir" && silentexec mkdir "$bak_dir" else - echo_info "Backup dir already present, clearing now" && + pen bold yellow "Backup dir already present, clearing now" && rm -rf "${bak_dir:?}/*" fi for _dirs in "${dirs[@]}"; do if [ -d "$conf/$_dirs" ]; then + repen moved $_dirs mv -f "$conf/$_dirs" "$bak_dir" fi done @@ -143,12 +61,14 @@ __pre_stow__() { for _f in "${h_files[@]}"; do if [ -f "$HOME/$_f" ]; then + repen moved $_f mv -f "$HOME/$_f" "$bak_dir" && echo_info "Moved $_f to $bak_dir" fi done for _d in ".zsh .tmux .fzf"; do if [ -d "$HOME/$_d" ]; then + repen moved $_d mv -f "$HOME/$_d" "$bak_dir" && echo_info "Moved $_d to $bak_dir" fi done @@ -156,42 +76,46 @@ __pre_stow__() { askThings() { if [ ! -d ./dotfiles/.config/tmux/ ] && [ ! -d ./dotfiles/.config/zellij/ ]; then - echo_info "Choose a menu - [t]mux || [z]ellij || [n]one" + choose askMultiPlexer "Choose a menu" tmux zellij none