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