wip
This commit is contained in:
parent
030acc85bf
commit
f45bc46aa8
2 changed files with 505 additions and 546 deletions
903
.bash_aliases
903
.bash_aliases
File diff suppressed because it is too large
Load diff
148
.bashrc
148
.bashrc
|
@ -2,6 +2,10 @@
|
|||
|
||||
blesh=true
|
||||
|
||||
# tmux autosession function
|
||||
# used in .bash_aliases
|
||||
autosession=true
|
||||
|
||||
# ─< Helper functions >─────────────────────────────────────────────────────────────────
|
||||
# ───────────────────────────────────< Message storage >─────────────────────────────────
|
||||
declare -A _MESSAGES
|
||||
|
@ -21,26 +25,26 @@ NC='\033[0m' # No Color
|
|||
BOLD='\033[1m'
|
||||
|
||||
# Functions to store messages
|
||||
echo_error() {
|
||||
echo-error() {
|
||||
_MESSAGES[error]+="${RED}❌ $@${NC}\n"
|
||||
}
|
||||
|
||||
echo_missing() {
|
||||
echo-missing() {
|
||||
_MESSAGES[missing]+="${YELLOW} $@${NC}\n"
|
||||
}
|
||||
|
||||
echo_warning() {
|
||||
echo-warning() {
|
||||
_MESSAGES[warn]+="${YELLOW}⚠️ $@${NC}\n"
|
||||
}
|
||||
|
||||
echo_info() {
|
||||
echo-info() {
|
||||
_MESSAGES[info]+="${CYAN}ℹ️ $@${NC}\n"
|
||||
}
|
||||
|
||||
if $blesh; then
|
||||
if [ ! -e /usr/share/blesh/ble.sh ] && [ ! -e "$HOME/.local/share/blesh/ble.sh" ]; then
|
||||
blesh=false
|
||||
echo_missing blesh
|
||||
echo-missing blesh
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -82,34 +86,41 @@ silentexec() {
|
|||
}
|
||||
|
||||
# ─< Check if the given command exists silently >─────────────────────────────────────────
|
||||
command_exists() {
|
||||
command-exists() {
|
||||
command -v "$@" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# ─< Check if the user is root and set sudo variable if necessary >───────────────────────
|
||||
check_root() {
|
||||
setup-sudo() {
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
if command_exists sudo; then
|
||||
# echo_warning "User is not root. Using sudo for privileged operations."
|
||||
if command-exists sudo; then
|
||||
# echo-warning "User is not root. Using sudo for privileged operations."
|
||||
_sudo="sudo -E"
|
||||
else
|
||||
# echo_error "No sudo found and you're not root! Can't install packages."
|
||||
# echo-error "No sudo found and you're not root! Can't install packages."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo_info "Root access confirmed."
|
||||
echo-info "Root access confirmed."
|
||||
_sudo=""
|
||||
fi
|
||||
}
|
||||
|
||||
_source() {
|
||||
[[ -e "$1" ]] &&
|
||||
. "$1" &&
|
||||
echo "Sourced $1"
|
||||
}
|
||||
source-file() {
|
||||
local file
|
||||
|
||||
_sources() {
|
||||
_source "$HOME/.bash_aliases"
|
||||
if [ "$1" == "-q" ]; then
|
||||
shift
|
||||
file=$1
|
||||
[[ -e "$file" ]] &&
|
||||
source $file
|
||||
else
|
||||
file=$1
|
||||
|
||||
[[ -e "$file" ]] &&
|
||||
source $file &&
|
||||
echo "Sourced $file"
|
||||
fi
|
||||
}
|
||||
|
||||
setup-pkg() {
|
||||
|
@ -123,7 +134,7 @@ setup-pkg() {
|
|||
fi
|
||||
}
|
||||
|
||||
if command_exists nala; then
|
||||
if command-exists nala; then
|
||||
alias search="nala search"
|
||||
alias update="$_sudo nala update && $_sudo nala upgrade --full"
|
||||
alias remove="$_sudo nala purge"
|
||||
|
@ -136,20 +147,20 @@ setup-pkg() {
|
|||
;;
|
||||
pacman)
|
||||
install() {
|
||||
if command_exists paru; then
|
||||
if command-exists paru; then
|
||||
paru -S --no-confirm --color=always "$@"
|
||||
elif command_exists yay; then
|
||||
elif command-exists yay; then
|
||||
yay -S --no-confirm --color=always "$@"
|
||||
else
|
||||
$_sudo pacman -S --no-confirm --color=always "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
if command_exists paru; then
|
||||
if command-exists paru; then
|
||||
alias search="paru -Ss"
|
||||
alias update="paru -Syu"
|
||||
alias remove="paru -R"
|
||||
elif command_exists yay; then
|
||||
elif command-exists yay; then
|
||||
alias search="yay -Ss"
|
||||
alias update="yay -Syu"
|
||||
alias remove="yay -R"
|
||||
|
@ -194,7 +205,7 @@ setup-pkg() {
|
|||
)
|
||||
|
||||
for p in "${pkg[@]}"; do
|
||||
if command_exists $p; then
|
||||
if command-exists $p; then
|
||||
setup-pkg $p
|
||||
break
|
||||
fi
|
||||
|
@ -226,46 +237,59 @@ setup-keychain() {
|
|||
|
||||
_init() {
|
||||
# ─< fzf >────────────────────────────────────────────────────────────────────────────────
|
||||
if command_exists fzf; then
|
||||
if command-exists fzf; then
|
||||
eval "$(fzf --bash)"
|
||||
else
|
||||
echo_missing fzf
|
||||
echo-missing fzf
|
||||
fi
|
||||
|
||||
# ─< oh-my-posh initialization >────────────────────────────────────────────────────────────
|
||||
if command_exists oh-my-posh; then
|
||||
eval "$(oh-my-posh init bash --config "$HOME/.omp.toml")"
|
||||
if command-exists oh-my-posh; then
|
||||
local theme="$HOME/.omp.toml"
|
||||
eval "$(oh-my-posh init bash --config $theme)"
|
||||
# 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/
|
||||
if command-exists curl; then
|
||||
# curl -s https://ohmyposh.dev/install.sh | $_sudo bash -s -- -d /usr/bin/
|
||||
binDirs=(
|
||||
"$HOME/.local/bin"
|
||||
"/usr/local/bin"
|
||||
"/usr/bin"
|
||||
)
|
||||
|
||||
while ! command_exists oh-my-posh; do
|
||||
local break accum
|
||||
break=false
|
||||
accum=0
|
||||
while ! command-exists "oh-my-posh" && $break; do
|
||||
for binDir in "${binDirs[@]}"; do
|
||||
((accum++))
|
||||
if [ -d "$binDir" ]; then
|
||||
case "$binDir" in
|
||||
"$HOME/.local/bin")
|
||||
echo_info "Installing oh-my-posh into $binDir"
|
||||
echo-info "Installing oh-my-posh into $binDir"
|
||||
curl -s https://ohmyposh.dev/install.sh | bash -s -- -d "$binDir"
|
||||
;;
|
||||
*)
|
||||
echo_info "Installing oh-my-posh into $binDir"
|
||||
echo-info "Installing oh-my-posh into $binDir"
|
||||
curl -s https://ohmyposh.dev/install.sh | $_sudo bash -s -- -d "$binDir"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
if ((accum == 3)); then
|
||||
break=true
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
if $break; then
|
||||
echo "oh-my-posh failed to install!" && sleep 3
|
||||
echo-missing "oh-my-posh"
|
||||
fi
|
||||
}
|
||||
|
||||
_env() {
|
||||
setup-environment() {
|
||||
local essentials=(
|
||||
neovim
|
||||
git
|
||||
|
@ -282,30 +306,30 @@ _env() {
|
|||
for pkg in "${essentials[@]}"; do
|
||||
case $pkg in
|
||||
neovim)
|
||||
if ! command_exists nvim; then
|
||||
echo_missing "$pkg"
|
||||
if command_exists vim; then
|
||||
EDITOR=vim
|
||||
elif command_exists vi; then
|
||||
EDITOR=vi
|
||||
if ! command-exists nvim; then
|
||||
echo-missing "$pkg"
|
||||
if command-exists vim; then
|
||||
export EDITOR=vim
|
||||
elif command-exists vi; then
|
||||
export EDITOR=vi
|
||||
else
|
||||
echo_missing "vim & vi"
|
||||
echo-missing "vim & vi"
|
||||
fi
|
||||
else
|
||||
EDITOR=nvim
|
||||
export EDITOR=nvim
|
||||
fi
|
||||
|
||||
;;
|
||||
*)
|
||||
if ! command_exists $pkg; then
|
||||
echo_missing "$pkg"
|
||||
if ! command-exists "$pkg"; then
|
||||
echo-missing "$pkg"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
_color_prompt_() {
|
||||
setup-prompt() {
|
||||
# set a fancy prompt (non-color, unless we know we "want" color)
|
||||
case "$TERM" in
|
||||
xterm-color | *-256color) color_prompt=yes ;;
|
||||
|
@ -336,9 +360,9 @@ _color_prompt_() {
|
|||
fi
|
||||
}
|
||||
|
||||
_end() {
|
||||
show-end-screen() {
|
||||
# ─< fastfetch >────────────────────────────────────────────────────────────────────────────
|
||||
if command_exists fastfetch; then
|
||||
if command-exists fastfetch; then
|
||||
alias ff="fastfetch"
|
||||
alias clearff="command clear & fastfetch"
|
||||
alias clearf="command clear & fastfetch"
|
||||
|
@ -352,13 +376,13 @@ _end() {
|
|||
fastfetch
|
||||
fi
|
||||
|
||||
if command_exists cowsay; then
|
||||
if command-exists cowsay; then
|
||||
alias clear='clear && cowsay -f tux "$(uptime --pretty)"'
|
||||
cowsay -f tux "$(uptime --pretty)"
|
||||
fi
|
||||
|
||||
# ─< zoxide >─────────────────────────────────────────────────────────────────────────────
|
||||
if command_exists zoxide; then
|
||||
if command-exists zoxide; then
|
||||
eval "$(zoxide init bash)"
|
||||
fi
|
||||
|
||||
|
@ -370,22 +394,28 @@ main() {
|
|||
# _blesh
|
||||
_init
|
||||
|
||||
_color_prompt_
|
||||
_env
|
||||
check_root
|
||||
setup-prompt
|
||||
setup-environment
|
||||
setup-sudo
|
||||
setup-pkg
|
||||
_end
|
||||
show-end-screen
|
||||
|
||||
_source "$HOME/.bash_aliases"
|
||||
_source "$HOME/.bash/plugins/autopairs.sh"
|
||||
_source "$HOME/.fzf/shell/completion.bash"
|
||||
_source "$HOME/.fzf/shell/key-bindings.bash"
|
||||
ble-import "$HOME/.bash_aliases"
|
||||
ble-import "$HOME/.bash/plugins/autopairs.sh"
|
||||
# source-file -q "$HOME/.bash_aliases"
|
||||
# source-file -q "$HOME/.bash/plugins/autopairs.sh"
|
||||
|
||||
if command_exists keychain; then
|
||||
# fzf completions for bash
|
||||
if command-exists fzf; then
|
||||
source-file "$HOME/.fzf/shell/completion.bash"
|
||||
source-file "$HOME/.fzf/shell/key-bindings.bash"
|
||||
fi
|
||||
|
||||
if command-exists keychain; then
|
||||
eval "$(keychain --eval --noask --agents ssh ~/.ssh/{homelab-id_rsa,hetzner_id_rsa})"
|
||||
# setup-keychain
|
||||
else
|
||||
echo_missing "keychain"
|
||||
echo-missing "keychain"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue