#!/usr/bin/env bash # ─< Check if the given command exists silently >───────────────────────────────────────── command-exists() { command -v "$@" >/dev/null 2>&1 } silent() { "$@" >/dev/null } source-script() { 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 "curl/wget is required, but missing.." exit 69 fi source "$import" sleep 0.2 rm "$import" } _found() { path=./dotfiles/.config find=("$@") for f in "${find[@]}"; do [[ -d "${path}/$f" ]] && return 0 done return 69 } askThings() { # local dots=./dotfiles/.config if ! _found yazi lf ranger; then # if [[ ! -d "${dots}/yazi" && ! -d "${dots}/lf" && ! -d "${dots}/ranger" ]]; then choose cli_file_manager "Choose a cli filemanager" yazi ranger lf none $bak" done } __validate__() { if askThings; then case "$askFilemgr" in [yY] | yazi) cloneDots "yazi" if ! command-exists yazi; then if command-exists curl; then curl -fsSL https://git.k4li.de/scripts/installs/raw/branch/main/yazi.sh | bash else pen bold yellow "curl was not found, could not install yazi!" fi fi cli_file_manager="yazi" ;; [rR] | ranger) cloneDots "ranger" cli_file_manager="ranger" ;; [lL] | lf) cloneDots "lf" cli_file_manager="lf" ;; esac case "$askMultiPlexer" in [tT] | tmux) cloneDots "tmux" multi_plexer="tmux" ;; [zZ] | zellij) cloneDots "zellij" if ! command-exists zellij; then if command-exists curl; then curl -fsSL https://git.k4li.de/scripts/installs/raw/branch/main/zellij.sh | bash else pen bold yellow "curl was not found, could not install zellij!" fi fi multi_plexer="zellij" ;; esac else echo-error "Something went terribly wrong" exit 1 fi } __stow__() { stow --verbose --target="$HOME" --defer=.gitmodules --restow */ } main() { # ask stuff and validate variables __validate__ if ! command-exists stow; then if confirm "We couldn't find $(pen bold yellow stow) on the system, install it now?"; then pkg-install stow fi else pen bold blue "stow was found, going on to prepare to stow your config" sleep 0.3 fi get-stow-folders move-and-prestow __stow__ } # WHY: # This import will give you the following variables: # _sudo="sudo -E" <- only if non root user # distro = # arch = bool # fedora = bool # opensuse = bool.... # You can then use it for, `if $arch; then` # Also this gives you the pkg-install command, which installs a package pased on the packagemanager/distro used. # CAUTION: # This only wokrs for generic package names, like neovim, or vim, or tmux etc.. # not every package packagemanager has the same packagenames for their packages.. setup-env() { # local beddu=https://git.k4li.de/scripts/beddu/raw/branch/main/dist/beddu.sh # local pika=https://git.k4li.de/scripts/imports/raw/branch/main/distros.sh local dream=https://git.k4li.de/scripts/imports/raw/branch/main/dream.sh if ! command-exists pkg-install && ! command-exists check-and-install && ! command-exists spin; then source-script $dream line fi } if setup-env; then main else echo "Fatal error!" fi