removed most unused stuff (bash will be the minimal config, zsh the extendet)

This commit is contained in:
pika 2025-01-05 20:04:44 +01:00
parent 33ba7df9ef
commit 38a0834f40
13 changed files with 192 additions and 1125 deletions

511
.bashrc
View file

@ -1,20 +1,14 @@
#!/bin/bash
# ─< Helper functions >─────────────────────────────────────────────────────────────────
function echo_error() { echo -e "\033[0;1;31merror:\033[0;31m\t${*}\033[0m"; }
function echo_binfo() { echo -e "\033[0;1;34mInfo:\033[0;34m\t${*}\033[0m"; }
function echo_info() { echo -e "\033[0;35m${*}\033[0m"; }
function echo_error() { echo -e "\033[0;1;31m❌ ERROR:\033[0;31m\t${*}\033[0m"; }
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"; }
# ─< check if command exists >────────────────────────────────────────────────────────────
command_exists() {
command -v "$1" >/dev/null 2>&1
}
if command_exists curl; then
alias install_pkg='bash --norc -c "$(curl -sSL https://git.k4li.de/pika/scripts/raw/branch/main/bash/snippets/install_pkg.sh)" -- '
else
echo_error "curl is not installed, universal install disabled!"
fi
# ─< Silent execution >─────────────────────────────────────────────────────────────────
silentexec() {
"$@" >/dev/null 2>&1
@ -33,15 +27,6 @@ check_root() {
fi
}
# ─< ble.sh -- https://github.com/akinomyoga/ble.sh >─────────────────────────────────────
p_blesh() {
if [[ ! -f $HOME/.local/share/blesh/ble.sh ]]; then
bash -norc -c "$(curl -sSL https://git.k4li.de/pika/scripts/raw/branch/main/bash/installs/install-blesh.sh)"
else
source "$HOME/.local/share/blesh/ble.sh" --attach=none
fi
}
_sensible.bash_() {
# Sensible Bash - An attempt at saner Bash defaults
# Maintainer: mrzool <http://mrzool.cc>
@ -151,7 +136,7 @@ _sensible.bash_() {
_defaults_() {
# ─< set keybinding mode >────────────────────────────────────────────────────────────────
set -o emacs
# set -o emacs
# set -o vim
# If set, the pattern "**" used in a pathname expansion context will
@ -165,6 +150,7 @@ _defaults_() {
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm* | rxvt*)
@ -175,141 +161,18 @@ _defaults_() {
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$//'\'')"'
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
if [ -f "$HOME/.bash_aliases" ]; then
. "$HOME/.bash_aliases"
fi
if [ -f ~/.completions/ssh ]; then
. ~/.completions/ssh
if [ -f "$HOME/.bash/ssh" ]; then
. "$HOME/.bash/ssh"
fi
}
p_basher() {
if [[ ! -d $HOME/.basher/ ]]; then
git clone --depth=1 https://github.com/basherpm/basher.git ~/.basher
else
export PATH="$HOME/.basher/bin:$PATH"
eval "$(basher init - bash)" && silentexec $(cd $HOME/.basher/ && git pull)
fi
}
p_has() {
if ! command_exists has; then
inst_has() {
git clone https://github.com/kdabir/has.git /tmp/has && cd /tmp/has && sudo make install
}
echo_info "Installing has"
silentexec inst_has
else
tools() {
local pkgs="bash zsh git curl make cmake gcc g++ rg docker composer node npm php jre python3 go cargo"
has $pkgs
}
fi
}
# plugins() {
# ─< qfc -- https://github.com/pindexis/qfc >─────────────────────────────────────────────
# [[ -s "$HOME/.qfc/bin/qfc.sh" ]] && source "$HOME/.qfc/bin/qfc.sh"
# p_basher
# p_has
# p_blesh
# }
_color_prompt_() {
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color | *-256color) color_prompt=yes ;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
# force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
fi
}
_zoxide_() {
if command_exists zoxide; then
eval "$(zoxide init bash)"
fi
}
_fancy_ls_() {
# ─< colorized ls >─────────────────────────────────────────────────────────────────────────
if command_exists exa; then
alias ls="exa --icons -l --git"
alias l="exa --long --no-filesize --no-permissions --no-time --git --colour-scale --icons"
alias ll="exa --all --long --no-filesize --no-permissions --no-time --git --colour-scale --icons"
alias tree="exa --icons -l --tree"
elif command_exists lsd; then
alias ls="lsd -l -1 -h1 --almost-all --git"
alias l="lsd -1"
alias ll="lsd -1 --almost-all"
alias clearl="command clear && l"
alias tree="lsd --tree"
elif command_exists eza; then
alias ls="eza --icons --long --git"
alias l="eza --icons -l"
alias ll="eza --icons -laa"
alias tree="eza --icons -l --tree"
else
alias ls="ls --color=always -lAph"
alias l="ls --color=always -lph -w1"
alias ll="ls --color=always -lph"
fi
}
_tmux_() {
# ─< t stands for tmux >────────────────────────────────────────────────────────────────────
if command_exists tmux; then
tmux_y="-- tmux-session active! | connecting to active session --"
tmux_n="-- no tmux-session found! | creating one --"
ta() {
command tmux list-sessions >/dev/null 2>&1
if [ $? -eq 0 ]; then
if command_exists notify-send; then
notify-send "$tmux_y"
sleep 0.5
tmux attach
else
echo_info "$tmux_y"
sleep 0.5
tmux attach
fi
else
if command_exists notify-send; then
notify-send "$tmux_n"
sleep 0.5
tmux
else
echo_info "$tmux_n"
sleep 0.5
tmux
fi
fi
}
alias ts="tmux source $HOME/.tmux.conf"
fi
}
_cli_qol_() {
# ─< colored everything >───────────────────────────────────────────────────────────────────
alias ip="ip --color=always"
@ -342,50 +205,13 @@ _cli_qol_() {
else
curl -s https://ohmyposh.dev/install.sh | sudo bash -s -- -d /usr/bin/
fi
}
_games() {
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)"'
}
# ─< t stands for trash(-cli) >───────────────────────────────────────────────────────────────
_trash() {
if command_exists trash; then
alias rm="trash"
alias t="trash"
elif command_exists trash-cli; then
alias rm="trash-cli"
alias t="trash-cli"
else
echo_error "-- You do not have trash or trash-cli installed! Your 'rm' will be permanent! --"
fi
}
# ─< rsync >────────────────────────────────────────────────────────────────────────────────
_rsync_() {
_rrsync() {
if command_exists find; then
numbers=0
for source in "${@:1:$#-1}"; do
numbers=$(($numbers + $(find "$source" -type f | wc -l)))
done
destination="${@: -1}"
rsync -avP --info=progress2 "${@:1:$#-1}" "$destination" | pv -lpes $numbers
else
echo_error "-- We could not find 'find'. Please install 'find' to enable the progress bar. (hit 'CTRL + C' to exit now) --"
sleep 5
rsync -avP --info=progress2 "$@"
fi
}
# ─< rsync >────────────────────────────────────────────────────────────────────────────────
if command_exists rsync; then
alias cp="_rrsync"
alias scp="rsync -avP"
alias cp="scp"
fi
}
_cat_() {
# ─< bat alias >────────────────────────────────────────────────────────────────────────────
if command_exists batcat; then
alias cat="batcat --color=always -p --paging=never"
@ -396,51 +222,17 @@ _cat_() {
alias less="bat --paging always --color=always"
alias gd="bat --diff"
fi
}
_fetches_() {
# ─< fastfetch >────────────────────────────────────────────────────────────────────────────
if command_exists fastfetch; then
alias ff="fastfetch"
alias clearff="command clear & fastfetch"
alias clearf="command clear & fastfetch"
if fastfetch --config os >/dev/null 2>&1; then
alias f="fastfetch --config os"
else
git clone https://git.k4li.de/mirrors/fastfetch.git $HOME/.local/share/fastfetch >/dev/null 2>&1
exec $SHELL
fi
command clear &
fastfetch
if command_exists trash; then
alias rm="trash"
alias t="trash"
elif command_exists trash-cli; then
alias rm="trash-cli"
alias t="trash-cli"
else
echo_error "-- You do not have trash or trash-cli installed! Your 'rm' will be permanent! --"
fi
}
_nmap_() {
# ─< set nmap-alias >───────────────────────────────────────────────────────────────────────
if command_exists nmap; then
alias scanvuln="sudo nmap --script vuln -vvv"
alias sv="scanvuln"
alias portscan="sudo nmap -sT"
alias ps="portscan"
fi
}
_docker_() {
# ─< d stands for docker >──────────────────────────────────────────────────────────────────
if command_exists docker; then
alias up="docker compose up"
alias down="docker compose down"
alias pull="docker compose pull"
alias d="docker"
alias dr="docker run --rm -it"
alias drs="docker compose down && docker compose up -d --remove-orphans --force-recreate"
alias ds="docker ps -a"
alias dc="docker compose"
alias appupdate="docker compose pull && docker compose up -d --force-recreate"
fi
}
_git_() {
# ─< g stands for GIT >─────────────────────────────────────────────────────────────────────
if command_exists git; then
alias g="git"
@ -460,6 +252,133 @@ _git_() {
alias lg="lazygit"
fi
fi
# ─< d stands for docker >──────────────────────────────────────────────────────────────────
if command_exists docker; then
alias up="docker compose up"
alias down="docker compose down"
alias pull="docker compose pull"
alias d="docker"
alias dr="docker run --rm -it"
alias drs="docker compose down && docker compose up -d --remove-orphans --force-recreate"
alias ds="docker ps -a"
alias dc="docker compose"
alias appupdate="docker compose pull && docker compose up -d --force-recreate"
fi
# ─< colorized ls >─────────────────────────────────────────────────────────────────────────
if command_exists exa; then
alias ls="exa --icons -l --git"
alias l="exa --long --no-filesize --no-permissions --no-time --git --colour-scale --icons"
alias ll="exa --all --long --no-filesize --no-permissions --no-time --git --colour-scale --icons"
alias tree="exa --icons -l --tree"
elif command_exists lsd; then
alias ls="lsd -l -1 -h1 --almost-all --git"
alias l="lsd -1"
alias ll="lsd -1 --almost-all"
alias clearl="command clear && l"
alias tree="lsd --tree"
elif command_exists eza; then
alias ls="eza --icons --long --git"
alias l="eza --icons -l"
alias ll="eza --icons -laa"
alias tree="eza --icons -l --tree"
else
alias ls="ls --color=always -lAph"
alias l="ls --color=always -lph -w1"
alias ll="ls --color=always -lph"
fi
# ─< t stands for tmux >────────────────────────────────────────────────────────────────────
if command_exists tmux; then
local tmux_y="$(echo '-- tmux-session active! | connecting to active session --')"
local tmux_n="$(echo '-- no tmux-session found! | creating one --')"
ta() {
# command tmux list-sessions >/dev/null 2>&1
if command tmux list-sessions >/dev/null 2>&1; then
if command_exists notify-send; then
notify-send "TMUX" "${tmux_y}"
sleep 0.5
tmux attach
else
echo_info "${tmux_y}"
sleep 0.5
tmux attach
fi
else
if command_exists notify-send; then
notify-send "TMUX" "${tmux_n}"
sleep 0.5
tmux
else
echo_info "$tmux_n"
sleep 0.5
tmux
fi
fi
}
alias ts="tmux source ~/.tmux.conf"
fi
}
_color_prompt_() {
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color | *-256color) color_prompt=yes ;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
# force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
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() {
# ─< fastfetch >────────────────────────────────────────────────────────────────────────────
if command_exists fastfetch; then
alias ff="fastfetch"
alias clearff="command clear & fastfetch"
alias clearf="command clear & fastfetch"
if fastfetch --config os >/dev/null 2>&1; then
alias f="fastfetch --config os"
else
git clone https://git.k4li.de/mirrors/fastfetch.git $HOME/.local/share/fastfetch >/dev/null 2>&1
exec $SHELL
fi
command clear &
fastfetch
fi
if command_exists cowsay; then
alias clear='clear && cowsay -f tux "$(uptime --pretty)"'
cowsay -f tux "$(uptime --pretty)"
fi
}
# ╭────────╮
@ -471,26 +390,6 @@ _coding_() {
alias h='hugo'
alias hs='hugo server -D --noHTTPCache --disableFastRender'
fi
# ─< c stands for bin/cake >──────────────────────────────────────────────────────────────
alias cake='bin/cake'
alias c='cake'
alias cs='c server -p 1313'
# ─< VSCodium >─────────────────────────────────────────────────────────────────────────────
if command_exists codium; then
alias code="codium"
export EDITOR="codium"
fi
# ─< neovide, the best frontend for any neovim-config >───────────────────────────────────
if [ -d "$HOME/.local/share/neovide/" ]; then
if command_exists neovide; then
alias nvim='neovide --fork'
else
neovide_path=$(find "$HOME/" -name "*neovide*.appimage" 2>/dev/null)
if [ -n "$neovide_path" ]; then
alias nvim="$neovide_path --fork"
fi
fi
fi
# Function to get the IP address
get_ip() {
ip a | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d/ -f1 | head -n 1
@ -508,79 +407,65 @@ _coding_() {
}
get_packager() {
PKG=""
install=""
update=""
refresh=""
remove=""
source /etc/os-release
. /etc/os-release
case "$ID" in
ubuntu | debian)
# Debian-based
ubuntu | debian | pop | kali | zorin | rhinoh)
if command_exists nala; then
PKG="nala"
install="nala install --assume-yes"
upgrade="nala upgrade"
refresh="nala update"
clean="nala autoremove --assume-yes"
remove="nala remove"
purge="nala purge"
search="nala search"
alias update="$_sudo $refresh && $_sudo $upgrade"
alias install="$_sudo $refresh && $_sudo $install"
alias remove="$_sudo $purge"
alias search="$search"
elif command_exists apt-get; then
PKG="apt-get"
install="apt-get install --yes"
upgrade="apt-get upgrade"
refresh="apt-get update"
clean="apt-get autoremove"
remove="apt-get remove"
purge="apt-get purge"
search="apt-cache search"
alias update="$_sudo $refresh && $_sudo $upgrade"
alias install="$_sudo $refresh && $_sudo $install"
alias remove="$_sudo $purge"
alias search="$search"
alias search="nala search"
alias install="$_sudo nala install --assume-yes"
alias update="$_sudo nala update && $_sudo nala upgrade --full"
alias remove="$_sudo nala purge"
else
alias search="apt-cache search"
alias install="$_sudo apt-get install --yes"
alias update="$_sudo apt-get update && $_sudo apt-get upgrade"
alias remove="$_sudo apt-get purge"
fi
alias unbreak="$_sudo dpkg --configure -a"
;;
arch | manjaro | endevouros)
if command_exists yay; then
PKG="yay"
alias install="yay -S --noconfirm"
alias update="yay -Syu"
alias remove="yay -R"
alias search="yay -Ss"
elif command_exists paru; then
PKG="paru"
# Arch-based
arch | manjaro | endevouros | garuda)
if command_exists paru; then
alias search="paru -Ss"
alias install="paru -S --noconfirm"
alias update="paru -Syu"
alias remove="paru -R"
alias search="paru -Ss"
elif command_exists pacman; then
PKG="pacman"
elif command_exists yay; then
alias search="yay -Ss"
alias install="yay -S --noconfirm"
alias update="yay -Syu"
alias remove="yay -R"
else
alias search="$_sudo pacman -Ss"
alias install="$_sudo pacman -S --noconfirm"
alias update="$_sudo pacman -Syu"
alias remove="$_sudo pacman -R"
alias search="$_sudo pacman -Ss"
fi
;;
# RHEL-based
fedora | centos)
PKG="dnf"
alias install="dnf install --yes"
alias update="dnf update"
alias remove="dnf remove"
alias search="dnf search"
alias install="$_sudo dnf install"
alias update="$_sudo dnf update"
alias remove="$_sudo dnf remove"
;;
# openSUSE
opensuse-*)
alias search="zypper search"
alias install="$_sudo zypper install --no-confirm"
alias update="$_sudo zypper update"
alias remove="$_sudo zypper remove"
;;
# Alpine
alpine)
PKG="apk"
install="apk add"
update="apk update"
upgrade="apk upgrade"
remove="apk del"
alias install="$_sudo $install"
alias update="$_sudo $update && $_sudo $upgrade"
alias remove="$_sudo $remove"
alias install="$_sudo apk add"
alias update="$_sudo apk update && $_sudo apk upgrade"
alias remove="$_sudo apk del"
;;
esac
}
@ -589,18 +474,7 @@ get_alias() {
_defaults_
_sensible.bash_
_color_prompt_
_cli_qol_
_cat_
_trash
_nmap_
_tmux_
_docker_
_git_
_rsync_
_zoxide_
_fancy_ls_
_coding_
_fetches_
_games
}
@ -608,8 +482,7 @@ main() {
check_root
get_packager
get_alias
# plugins
# tools
# [[ ${BLE_VERSION-} ]] && ble-attach
_end
}
main