# ─< Helper functions >───────────────────────────────────────────────────────────────── # 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 # Message storage typeset -A _MESSAGES _MESSAGES=( [error]="" [warn]="" [info]="" ) # Logging functions with emojis echo_error() { local msg="${RED}❌ $1${NC}\n" printf "$msg" >&2 _MESSAGES[error]+="$msg" } echo_warning() { local msg="${YELLOW}⚠️ $1${NC}\n" printf "$msg" _MESSAGES[warn]+="$msg" } echo_info() { local msg="${CYAN}ℹ️ $1${NC}\n" printf "$msg" _MESSAGES[info]+="$msg" } # Display stored messages error_log() { [[ -z "${_MESSAGES[error]}${_MESSAGES[warn]}${_MESSAGES[info]}" ]] && return 0 typeset -A headers colors headers=( error "❌ Errors" warn "⚠️ Warnings" info "ℹ️ Info" ) colors=( error "$RED" warn "$YELLOW" info "$CYAN" ) for type in error warn info; do [[ -n "${_MESSAGES[$type]}" ]] && { printf "\n${BOLD}${colors[$type]}=== ${headers[$type]} ===${NC}\n" printf "${_MESSAGES[$type]}" } done } # ─< 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}" -ne 0 ]]; then if command_exists sudo; then echo_info "User <$(whoami)> 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." fi else echo_info "Root access confirmed." _sudo="" fi } _init() { if command_exists oh-my-posh; then # eval "$(oh-my-posh init zsh --config 'https://git.k4li.de/dotfiles/oh-my-posh/raw/branch/main/amro.toml')" # eval "$(oh-my-posh init zsh --config '~/.zsh/themes/sim-web.toml')" eval "$(oh-my-posh init zsh --config '~/.zsh/themes/amro.toml')" # eval "$(oh-my-posh init zsh --config '~/.zsh/themes/atomicBit.toml')" else curl -s https://ohmyposh.dev/install.sh | $_sudo bash --norc -s -- -d /usr/bin/ fi # ─< init fzf for zsh >─────────────────────────────────────────────────────────────────── if command_exists fzf; then source <(fzf --zsh) fi if command_exists zoxide; then eval "$(zoxide init zsh)" eval "$(zoxide init zsh --cmd cd)" fi } _sources() { local sourceDir="$HOME/.zsh" local sourceOptions=( "aliases" "defaults" "plugins" "installs" ) for _s in "${sourceOptions[@]}"; do local _source_="${sourceDir}/.${_s}.zsh" if [ -e "$_source_" ]; then . $_source_ fi local _source_"" done } _environment() { if command_exists nvim; then export EDITOR="$(which nvim)" fi # ─< paths >────────────────────────────────────────────────────────────────────────────── if [ -d "$HOME/.local/bin" ]; then export PATH="$HOME/.local/bin:$PATH" if [ -e "$HOME/.local/bin/lazydocker" ]; then alias ld="$HOME/.local/bin/lazydocker" fi fi [ -d "$HOME/go/bin" ] && export PATH="$HOME/go/bin:$PATH" [ -d "$HOME/.cargo/bin" ] && export PATH="$HOME/.cargo/bin:$PATH" [ -e "$HOME/.cargo/env" ] && . "$HOME/.cargo/env" # bun completions [ -s "$HOME/.bun/_bun" ] && . "$HOME/.bun/_bun" [ -s "$HOME/.bun/_bun" ] && export BUN_INSTALL="$HOME/.bun" && export PATH="$BUN_INSTALL/bin:$PATH" [ -d "$HOME/.zsh/plugins/fzf-zsh-plugin/bin" ] && export PATH="$HOME/.zsh/plugins/fzf-zsh-plugin/bin:$PATH" } _end() { if command_exists fastfetch; then clear && fastfetch fi if command_exists cowsay; then alias clear='clear && cowsay -f tux "$(uptime --pretty)"' cowsay -f tux "$(uptime --pretty)" fi error_log } main() { _environment _init _sources _end } if check_root; then main fi