changed some things quite a bit

This commit is contained in:
pika 2025-05-22 10:23:33 +02:00
parent ae986bd4a5
commit 9c487ce6d2
8 changed files with 817 additions and 946 deletions

196
.bashrc
View file

@ -1,36 +1,62 @@
#!/bin/bash
#!/usr/bin/env bash
# ─< Helper functions >─────────────────────────────────────────────────────────────────
declare -a echo_messages
# ───────────────────────────────────< Message storage >─────────────────────────────────
declare -A _MESSAGES
_MESSAGES=(
[missing]=""
[error]=""
[warn]=""
[info]=""
)
function echo_error() {
local message="\033[0;1;31m❌ ERROR:\033[0;31m\t${*}\033[0m"
echo -e "$message"
echo_messages+=("$message")
# Define color variables
RED='\033[0;31m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
GREEN='\033[1;32m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Functions to store messages
echo_error() {
_MESSAGES[error]+="${RED}$@${NC}\n"
}
function echo_warning() {
local message="\033[0;1;33m⚠ WARNING:\033[0;33m\t${*}\033[0m"
echo -e "$message"
echo_messages+=("$message")
echo_missing() {
_MESSAGES[missing]+="${YELLOW} 󱥸 $@${NC}\n"
}
function echo_info() {
local message="\033[0;1;34m INFO:\033[0;34m\t${*}\033[0m"
echo -e "$message"
echo_messages+=("$message")
echo_warning() {
_MESSAGES[warn]+="${YELLOW}⚠️ $@${NC}\n"
}
function echo_plugin() {
local message="\033[0;1;35m🔥 Pluginmgmt:\033[0;35m\t${*} loaded\033[0m"
echo -e "$message"
echo_messages+=("$message")
echo_info() {
_MESSAGES[info]+="${CYAN} $@${NC}\n"
}
# Function to print all stored messages
function print_echo_messages() {
echo -e "\033[38;5;196mL\033[38;5;202mo\033[38;5;208mg\033[38;5;214m \033[38;5;220mo\033[38;5;226mu\033[38;5;118mt\033[38;5;46mp\033[38;5;48mu\033[38;5;51mt\033[38;5;45m:"
for msg in "${echo_messages[@]}"; do
echo -e "$msg"
# Display stored messages
error_log() {
[[ -z "${_MESSAGES[error]}${_MESSAGES[warn]}${_MESSAGES[info]}${_MESSAGES[missing]}" ]] && return 0
typeset -A headers colors
headers=(
missing "⚠️ MISSING ESSENTIALS ⚠️"
error "❌ Errors"
warn "⚠️ Warnings"
info " Info"
)
colors=(
missing "$YELLOW"
error "$RED"
warn "$YELLOW"
info "$CYAN"
)
for type in error warn info missing; do
[[ -n "${_MESSAGES[$type]}" ]] && {
printf "\n${BOLD}${colors[$type]}=== ${headers[$type]} ===${NC}\n"
printf "${_MESSAGES[$type]}"
}
done
}
@ -49,7 +75,7 @@ check_root() {
if [ "$(id -u)" -ne 0 ]; then
if command_exists sudo; then
echo_warning "User is not root. Using sudo for privileged operations."
_sudo="sudo"
_sudo="sudo -E"
else
echo_error "No sudo found and you're not root! Can't install packages."
return 1
@ -81,19 +107,17 @@ _sources() {
}
_init() {
# ─< zoxide >─────────────────────────────────────────────────────────────────────────────
if command_exists zoxide; then
eval "$(zoxide init bash)"
fi
# ─< fzf >────────────────────────────────────────────────────────────────────────────────
if command_exists fzf; then
eval "$(fzf --bash)"
else
echo_missing fzf
fi
# ─< oh-my-posh initialization >────────────────────────────────────────────────────────────
if command_exists oh-my-posh; then
eval "$(oh-my-posh init bash --config "$HOME/.bash/themes/zen.toml")"
eval "$(oh-my-posh init bash --config "$HOME/.omp.toml")"
# eval "$(curl -fsSL https://git.k4li.de/dotfiles/oh-my-posh/raw/branch/main/zen.toml)"
else
if command_exists curl; then
curl -s https://ohmyposh.dev/install.sh | $_sudo bash -s -- -d /usr/bin/
@ -124,45 +148,74 @@ _init() {
}
# ─< ble.sh -- https://github.com/akinomyoga/ble.sh >─────────────────────────────────────
d_blesh() {
for deeps in git make gawk; do
if ! command_exists $deeps; then
echo_error "$deeps was missing from the system, cannot setup shell properly! (blesh setup)"
exit 1
fi
done
}
# d_blesh() {
# for deeps in git make gawk; do
# if ! command_exists $deeps; then
# echo_error "$deeps was missing from the system, cannot setup shell properly! (blesh setup)"
# exit 1
# fi
# done
# }
i_blesh() {
local tmp_dir="$(mktemp -d)"
# i_blesh() {
# local tmp_dir="$(mktemp -d)"
#
# cd "$tmp_dir" || echo_error "$tmp_dir is not valid!"
# git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
# make -C ble.sh install PREFIX=~/.local
# . "$HOME/.local/share/blesh/ble.sh"
# # bash
# # cd "$HOME" || return 0
# }
cd "$tmp_dir" || echo_error "$tmp_dir is not valid!"
git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
make -C ble.sh install PREFIX=~/.local
. "$HOME/.local/share/blesh/ble.sh"
# bash
# cd "$HOME" || return 0
}
_blesh() {
if [ ! -f $HOME/.local/share/blesh/ble.sh ]; then
d_blesh # Dependency check for blesh
echo_info "Installing blesh.. Depending on your internet connection and the performance of the client, this could take a minute or two.."
i_blesh # installing blesh silently
else
# . "$HOME/.local/share/blesh/ble.sh" --attach=none
. "$HOME/.local/share/blesh/ble.sh"
fi
}
# _blesh() {
# if [ ! -f $HOME/.local/share/blesh/ble.sh ]; then
# d_blesh # Dependency check for blesh
# echo_info "Installing blesh.. Depending on your internet connection and the performance of the client, this could take a minute or two.."
# i_blesh # installing blesh silently
# else
# # . "$HOME/.local/share/blesh/ble.sh" --attach=none
# . "$HOME/.local/share/blesh/ble.sh"
# fi
# }
_env() {
if command_exists nvim; then
export EDITOR="$(which nvim)"
elif command_exists vim; then
export EDITOR="$(which vim)"
elif command_exists vi; then
export EDITOR="$(which vi)"
fi
local essentials=(
neovim
git
docker
zoxide
yazi
curl
tmux
)
for pkg in "${essentials[@]}"; do
case $pkg in
neovim)
if ! command_exists nvim; then
echo_missing "$pkg"
else
EDITOR=nvim
fi
if [[ -z $EDITOR ]]; then
if command_exists vim; then
EDITOR=vim
elif command_exists vi; then
EDITOR=vi
else
echo_missing "vim & vi"
fi
fi
;;
*)
if ! command_exists $pkg; then
echo_missing "$pkg"
fi
;;
esac
done
}
_color_prompt_() {
@ -217,15 +270,22 @@ _end() {
cowsay -f tux "$(uptime --pretty)"
fi
print_echo_messages
# ─< zoxide >─────────────────────────────────────────────────────────────────────────────
if command_exists zoxide; then
eval "$(zoxide init bash)"
fi
error_log
}
main() {
_env
_sources
# _sources
# _blesh
_init
[[ -e "$HOME/.bash_aliases" ]] &&
. "$HOME/.bash_aliases"
_color_prompt_
_env
check_root
_end
}