addet message arrays
This commit is contained in:
parent
09c56ee57f
commit
a170f8725f
1 changed files with 77 additions and 41 deletions
118
.bashrc
118
.bashrc
|
@ -1,8 +1,31 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# ─< Helper functions >─────────────────────────────────────────────────────────────────
|
# ─< Helper functions >─────────────────────────────────────────────────────────────────
|
||||||
function echo_error() { echo -e "\033[0;1;31m❌ ERROR:\033[0;31m\t${*}\033[0m"; }
|
declare -a echo_messages
|
||||||
function echo_binfo() { echo -e "\033[0;1;34m⚠️ WARNING:\033[0;34m\t${*}\033[0m"; }
|
|
||||||
function echo_info() { echo -e "\033[0;35mℹ️ INFO:${*}\033[0m"; }
|
function echo_error() {
|
||||||
|
local message="\033[0;1;31m❌ ERROR:\033[0;31m\t${*}\033[0m"
|
||||||
|
echo -e "$message"
|
||||||
|
echo_messages+=("$message")
|
||||||
|
}
|
||||||
|
|
||||||
|
function echo_warning() {
|
||||||
|
local message="\033[0;1;34m⚠️ WARNING:\033[0;34m\t${*}\033[0m"
|
||||||
|
echo -e "$message"
|
||||||
|
echo_messages+=("$message")
|
||||||
|
}
|
||||||
|
|
||||||
|
function echo_info() {
|
||||||
|
local message="\033[0;35mℹ️ INFO:${*}\033[0m"
|
||||||
|
echo -e "$message"
|
||||||
|
echo_messages+=("$message")
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to print all stored messages
|
||||||
|
function print_echo_messages() {
|
||||||
|
for msg in "${echo_messages[@]}"; do
|
||||||
|
echo -e "$msg"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# ─< check if command exists >────────────────────────────────────────────────────────────
|
# ─< check if command exists >────────────────────────────────────────────────────────────
|
||||||
command_exists() {
|
command_exists() {
|
||||||
|
@ -14,15 +37,23 @@ silentexec() {
|
||||||
"$@" >/dev/null 2>&1
|
"$@" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ─< 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() {
|
check_root() {
|
||||||
if [[ "${EUID}" -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."
|
||||||
_sudo="sudo"
|
_sudo="sudo"
|
||||||
else
|
else
|
||||||
_sudo=""
|
echo_error "No sudo found and you're not root! Can't install packages."
|
||||||
echo_info "-- sudo was not found on this system ! --"
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
echo_info "Root access confirmed."
|
||||||
_sudo=""
|
_sudo=""
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -134,15 +165,7 @@ _sensible.bash_() {
|
||||||
# export dropbox="$HOME/Dropbox"
|
# export dropbox="$HOME/Dropbox"
|
||||||
}
|
}
|
||||||
|
|
||||||
_defaults_() {
|
_init() {
|
||||||
# ─< set keybinding mode >────────────────────────────────────────────────────────────────
|
|
||||||
# set -o emacs
|
|
||||||
# set -o vim
|
|
||||||
|
|
||||||
# If set, the pattern "**" used in a pathname expansion context will
|
|
||||||
# match all files and zero or more directories and subdirectories.
|
|
||||||
#shopt -s globstar
|
|
||||||
|
|
||||||
# make less more friendly for non-text input files, see lesspipe(1)
|
# make less more friendly for non-text input files, see lesspipe(1)
|
||||||
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
||||||
|
|
||||||
|
@ -159,24 +182,42 @@ _defaults_() {
|
||||||
*) ;;
|
*) ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
|
# ─< ssh completions >────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
if [ -f "$HOME/.bash_aliases" ]; then
|
|
||||||
. "$HOME/.bash_aliases"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "$HOME/.bash/ssh" ]; then
|
if [ -f "$HOME/.bash/ssh" ]; then
|
||||||
. "$HOME/.bash/ssh"
|
. "$HOME/.bash/ssh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ─< zoxide >─────────────────────────────────────────────────────────────────────────────
|
||||||
if command_exists zoxide; then
|
if command_exists zoxide; then
|
||||||
eval "$(zoxide init bash)"
|
eval "$(zoxide init bash)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ─< fzf >────────────────────────────────────────────────────────────────────────────────
|
||||||
if command_exists fzf; then
|
if command_exists fzf; then
|
||||||
eval "$(fzf --bash)"
|
eval "$(fzf --bash)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ─< oh-my-posh initialization >────────────────────────────────────────────────────────────
|
||||||
|
if command_exists oh-my-posh; then
|
||||||
|
eval "$(oh-my-posh init bash --config '~/.bash/themes/zen.toml')"
|
||||||
|
else
|
||||||
|
if command_exists curl; then
|
||||||
|
curl -s https://ohmyposh.dev/install.sh | $_sudo bash -s -- -d /usr/bin/
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_alias() {
|
||||||
|
# ─< set keybinding mode >────────────────────────────────────────────────────────────────
|
||||||
|
# set -o emacs
|
||||||
|
# set -o vim
|
||||||
|
|
||||||
|
# If set, the pattern "**" used in a pathname expansion context will
|
||||||
|
# match all files and zero or more directories and subdirectories.
|
||||||
|
#shopt -s globstar
|
||||||
|
|
||||||
|
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
|
||||||
|
|
||||||
# ─< colored everything >───────────────────────────────────────────────────────────────────
|
# ─< colored everything >───────────────────────────────────────────────────────────────────
|
||||||
alias ip="ip --color=always"
|
alias ip="ip --color=always"
|
||||||
|
|
||||||
|
@ -201,15 +242,6 @@ _defaults_() {
|
||||||
alias starwars="telnet -a telehack.com"
|
alias starwars="telnet -a telehack.com"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ─< oh-my-posh initialization >────────────────────────────────────────────────────────────
|
|
||||||
if command_exists oh-my-posh; then
|
|
||||||
eval "$(oh-my-posh init bash --config '~/.bash/themes/zen.toml')"
|
|
||||||
else
|
|
||||||
if command_exists curl; then
|
|
||||||
curl -s https://ohmyposh.dev/install.sh | $_sudo bash -s -- -d /usr/bin/
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ─< neovim >─────────────────────────────────────────────────────────────────────────────
|
# ─< neovim >─────────────────────────────────────────────────────────────────────────────
|
||||||
if command_exists nvim; then
|
if command_exists nvim; then
|
||||||
alias cnvim="command nvim"
|
alias cnvim="command nvim"
|
||||||
|
@ -391,6 +423,15 @@ _blesh() {
|
||||||
# . "$HOME/.local/share/blesh/ble.sh" --attach=none
|
# . "$HOME/.local/share/blesh/ble.sh" --attach=none
|
||||||
. "$HOME/.local/share/blesh/ble.sh"
|
. "$HOME/.local/share/blesh/ble.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
_games() {
|
||||||
|
if command_exists curl; then
|
||||||
|
echo_info "Games available. Try 'alias | grep g'"
|
||||||
|
alias g2048='bash --norc -c "$(curl -sSL https://git.k4li.de/pika/scripts/raw/branch/main/bash/games/2048.sh)"'
|
||||||
|
alias gwordle='bash --norc -c "$(curl -sSL https://git.k4li.de/pika/scripts/raw/branch/main/bash/games/wordle.sh)"'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_color_prompt_() {
|
_color_prompt_() {
|
||||||
|
@ -424,14 +465,6 @@ _color_prompt_() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_games() {
|
|
||||||
if command_exists curl; then
|
|
||||||
echo_info "Games available. Try 'alias | grep g'"
|
|
||||||
alias g2048='bash --norc -c "$(curl -sSL https://git.k4li.de/pika/scripts/raw/branch/main/bash/games/2048.sh)"'
|
|
||||||
alias gwordle='bash --norc -c "$(curl -sSL https://git.k4li.de/pika/scripts/raw/branch/main/bash/games/wordle.sh)"'
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
_end() {
|
_end() {
|
||||||
# ─< fastfetch >────────────────────────────────────────────────────────────────────────────
|
# ─< fastfetch >────────────────────────────────────────────────────────────────────────────
|
||||||
if command_exists fastfetch; then
|
if command_exists fastfetch; then
|
||||||
|
@ -441,7 +474,7 @@ _end() {
|
||||||
if fastfetch --config os >/dev/null 2>&1; then
|
if fastfetch --config os >/dev/null 2>&1; then
|
||||||
alias f="fastfetch --config os"
|
alias f="fastfetch --config os"
|
||||||
else
|
else
|
||||||
git clone https://git.k4li.de/mirrors/fastfetch.git $HOME/.local/share/fastfetch >/dev/null 2>&1
|
git clone https://git.k4li.de/mirrors/fastfetch.git "$HOME/.local/share/fastfetch" >/dev/null 2>&1
|
||||||
exec $SHELL
|
exec $SHELL
|
||||||
fi
|
fi
|
||||||
command clear &
|
command clear &
|
||||||
|
@ -452,6 +485,8 @@ _end() {
|
||||||
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
|
||||||
|
|
||||||
|
print_echo_messages
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭────────╮
|
# ╭────────╮
|
||||||
|
@ -544,15 +579,16 @@ get_packager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
get_alias() {
|
get_alias() {
|
||||||
_defaults_
|
_init
|
||||||
_sensible.bash_
|
_sensible.bash_
|
||||||
_blesh
|
|
||||||
_color_prompt_
|
_color_prompt_
|
||||||
_coding_
|
_coding_
|
||||||
|
_alias
|
||||||
_games
|
_games
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
_blesh
|
||||||
check_root
|
check_root
|
||||||
get_packager
|
get_packager
|
||||||
get_alias
|
get_alias
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue