#!/usr/bin/env bash # ─< Check if the given command exists silently >───────────────────────────────────────── command-exists() { command -v "$@" >/dev/null 2>&1 } source-script() { local url="$1" local import="$(mktemp)" # ─< if $1 is a local file, source this one instead >───────────────────────────────────── if [ -f "$url" ]; then source "$url" sleep 0.1 return 0 else # ─< if $1 is a url, grab it and source it, also deletes afterwards >───────────────────── 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" echo "${BLUE}Sourcing external script:${NC} $url" sleep 0.1 rm -f "$import" fi } check-powerstation() { local hn="$(hostname)" write-config() { _conf() { cat <"$HOME/.monitors.conf" } if [ "$hn" == 'cl-powerstation' ]; then if [ -e "$HOME/.monitors.conf" ]; then if ! grep -qi '3440x1440@165' <<<"$(cat $HOME/.monitors.conf)"; then write-config fi else write-config fi else return 69 fi } get-dependencies() { depends=( stow git bash curl unzip entr ) check-and-install ${depends[@]} } askThings() { if [ ! -d ./dotfiles/.config/tmux/ ] && [ ! -d ./dotfiles/.config/zellij/ ]; then choose plexer "Choose a multiplexer" tmux zellij none >"$HOME/.monitors.conf" else echo "monitor = preferred,, 0x0, 1" >>"$HOME/.monitors.conf" fi fi else return 69 fi } pkg_optional() { _ops=( "cowsay" "cmatrix" "trash-cli" "duf" ) for pkg in "${_opts[@]}"; do spin "Installing $pkg" if ! command-exists $pkg; then run pkg-install $pkg && check "$pkg installed" || throw "Error installing $pkg" fi done } dots=() homedots=() get-stow-folders() { # find foldernames for all used and cloned configs if [ -d "./dotfiles" ]; then for i in "./dotfiles/.config/"*; do echo "DOTS: ${i#./dotfiles/.config/}" dots+=("${i#./dotfiles/.config/}") done fi # find .files for ./zsh/ and ./bash/ folders for d in zsh bash; do for i in "./$d/".*; do echo "HOMEDOTS: ${i#./$d/}" homedots+=("${i#./$d/}") done done } # move the .files and .config/folders to the $bak dir, as stow would try to # migrate these, which will cause problems! move-and-prestow() { local home_conf bak target moved=() dirs=() shopt -s nullglob home_conf=$HOME/.config bak=$HOME/.bak dirs=( "$bak" "$HOME/.config" "$HOME/.local/share/icons" ) # create $bak dir if not present for d in "${dirs[@]}"; do if [ ! -d "$d" ]; then silent mkdir -p $bak fi done # move .config/folders to the $bak dir for i in "${dots[@]}"; do target=${home_conf}/$i if [ -d "$target" ]; then mv -f "$target" "$bak" && moved+=("$target") fi done # move $HOME/.files to the $bak dir for i in "${homedots[@]}"; do target=$HOME/$i if [[ -d "$target" || -e "$target" ]]; then mv -f "$target" "$bak" && moved+=("$target") fi done # printing the operations/debug echo "Moved ${#moved[@]} targets:" # printing exactly what files/folders were moved for m in "${moved[@]}"; do echo "${m} -> $bak" done } __stow__() { local err out spin grey bold "Linking dotfiles.." if run --err err stow --verbose --target="$HOME" --defer=.gitmodules --restow */; then upclear check "Linked dotfiles!" else upclear throw bold red "Could not use stow to link dofiles.." pen bold yellow "OUT: ${out:-}" echo-error "${err:-}" fi } c_fonts() { local err out local dirFonts="$HOME/.local/share/fonts/" local fontsRepo="https://git.k4li.de/pika/fonts.git" if [[ ! -d "$dirFonts" ]]; then if confirm "Seems like you may miss some fonts.. Do you want to clone them now into $(pen blue bold $dirFonts)" ──────────────────────────────────────────────────────────────────────── local dirs=() dirs=( "$HOME/.config" "$HOME/.local/share/icons" "$HOME/.bak" ) for d in "${dirs[@]}"; do if [[ ! -d "$d" ]]; then pen grey "mkdir $d" silentexec mkdir "$d" fi done c_fonts c_wallpapers } setup-env() { 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 fi } main() { __validate__ __dep__ make-dirs get-stow-folders move-and-prestow __stow__ sleep 2 if $__optional__; then pkg_optional fi __monitors__ && pen blue bold "found resolution ${res}" } if setup-env; then main fi