This commit is contained in:
pika 2025-07-07 21:42:25 +02:00
parent 030acc85bf
commit f45bc46aa8
2 changed files with 505 additions and 546 deletions

View file

@ -1,41 +1,3 @@
# Basic Colors
BLACK=$'\e[30m'
RED=$'\e[31m'
GREEN=$'\e[32m'
YELLOW=$'\e[33m'
BLUE=$'\e[34m'
MAGENTA=$'\e[35m'
CYAN=$'\e[36m'
WHITE=$'\e[37m'
# Styles
BOLD=$'\e[1m'
ITALIC=$'\e[3m'
UNDERLINE=$'\e[4m'
BLINK=$'\e[5m' # May not work in all terminals
INVERT=$'\e[7m' # Invert foreground/background
STRIKE=$'\e[9m' # Strikethrough
# Reset
NC=$'\e[0m' # Reset all styles/colors
# Functions to store messages
echo_error() {
_MESSAGES[error]+="${RED}$@${NC}\n"
}
echo_missing() {
_MESSAGES[missing]+="${YELLOW} 󱥸 $@${NC}\n"
}
echo_warning() {
_MESSAGES[warn]+="${YELLOW}⚠️ $@${NC}\n"
}
echo_info() {
_MESSAGES[info]+="${CYAN} $@${NC}\n"
}
# INFO: # INFO:
# ╭──────────╮ # ╭──────────╮
# │ defaults │ # │ defaults │
@ -50,7 +12,7 @@ alias ...="cd ../.."
# ─< colored ip >─────────────────────────────────────────────────────────────────── # ─< colored ip >───────────────────────────────────────────────────────────────────
alias ip="ip --color=always" alias ip="ip --color=always"
if command_exists curl; then if command-exists curl; then
# ─< linutil >──────────────────────────────────────────────────────────────────────────── # ─< linutil >────────────────────────────────────────────────────────────────────────────
alias linutil="curl -fsSL https://christitus.com/linux | sh" alias linutil="curl -fsSL https://christitus.com/linux | sh"
alias "linutil-dev"="curl -fsSL https://christitus.com/linuxdev | sh" alias "linutil-dev"="curl -fsSL https://christitus.com/linuxdev | sh"
@ -58,107 +20,68 @@ if command_exists curl; then
# ─< weather >────────────────────────────────────────────────────────────────────────────── # ─< weather >──────────────────────────────────────────────────────────────────────────────
alias www="curl wttr.in/Ulm" alias www="curl wttr.in/Ulm"
else else
echo_missing "curl" echo-missing "curl"
fi fi
# ─< check for rg >───────────────────────────────────────────────────────────────────────── # ─< check for rg >─────────────────────────────────────────────────────────────────────────
if command_exists rg; then if command-exists rg; then
alias grep="rg --color=always" alias grep="rg --color=always"
alias hl="rg --passthrough" alias hl="rg --passthrough"
else else
echo_missing "ripgrep" echo-missing "ripgrep"
alias grep="grep --color=always" alias grep="grep --color=always"
alias hl="grep --passthrough" alias hl="grep --passthrough"
fi fi
hm() { if command-exists dog; then
find -type f -name "${1}" | wc -l
}
if command_exists dog; then
alias dig="dog" alias dig="dog"
fi fi
# ─< define copy command >──────────────────────────────────────────────────────────────── # ─< define copy command >────────────────────────────────────────────────────────────────
if command_exists wl-copy; then if command-exists wl-copy; then
copy() { copy() {
if cat "$1"; then local file
command cat "$1" | wl-copy file="$1"
if cat "$file"; then
command cat "$file" | wl-copy
else else
"$1" | wl-copy "$file" | wl-copy
fi fi
} }
elif command_exists xclip; then elif command-exists xclip; then
copy() { copy() {
if cat "$1"; then local file
command cat "$1" | wl-copy file="$1"
if cat "$file"; then
command cat "$file" | wl-copy
else else
"$1" | xclip -selection clipboard "$file" | xclip -selection clipboard
fi fi
} }
else else
echo_missing "wl-clipboard | xclip" echo-missing "wl-clipboard | xclip"
fi fi
# ─< telnet (starwars) >──────────────────────────────────────────────────────────────────── # ─< telnet (starwars) >────────────────────────────────────────────────────────────────────
if command_exists telnet; then if command-exists telnet; then
alias starwars="telnet -a telehack.com" alias starwars="telnet -a telehack.com"
fi fi
if command_exists hyprpanel; then if command-exists hyprpanel; then
alias get_cpu='for i in /sys/class/hwmon/hwmon*/temp*_input; do echo "$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*})) $(readlink -f $i)"; done' alias get_cpu='for i in /sys/class/hwmon/hwmon*/temp*_input; do echo "$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*})) $(readlink -f $i)"; done'
fi fi
# ─< rsync >──────────────────────────────────────────────────────────────────────────────── # ─< rsync >────────────────────────────────────────────────────────────────────────────────
if command_exists rsync; then if command-exists rsync; then
alias scp="rsync -avP" alias scp="rsync -avP"
alias cp="rsync -avP" alias cp="rsync -avP"
else else
echo_missing "rsync" echo-missing "rsync"
fi
# ─< Function to determine which Neovim command to use >──────────────────────────────────
choose_nvim() {
if [ -n "$TMUX" ]; then
# If inside an active tmux session, use nvim
echo "command nvim"
return
elif [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]; then
# If in a graphical environment, use Neovide
if command_exists neovide; then
echo "neovide --fork"
return
fi
fi
# Default to nvim
echo "command nvim"
}
# Set up Neovim aliases based on environment
if command_exists nvim; then
alias cnvim="command nvim"
alias nvim="$(choose_nvim)"
nv() {
appname="$1"
shift
if [ "$#" -eq 0 ]; then
NVIM_APPNAME="$appname" command nvim
else
NVIM_APPNAME="$appname" command nvim "$@"
fi
}
if [ -d "$HOME/.config/nvdev" ]; then
alias nvdev='NVIM_APPNAME="nvdev" command nvim'
alias neodev='NVIM_APPNAME="nvdev" neovide --fork'
fi
else
echo_missing "neovim"
fi fi
# ─< cli explorer >─────────────────────────────────────────────────────────────────────── # ─< cli explorer >───────────────────────────────────────────────────────────────────────
if command_exists yazi; then if command-exists yazi; then
echo_info "yazi is the explorer of choice" echo-info "yazi is the explorer of choice"
# ─< yazi move when exit >──────────────────────────────────────────────────────────────── # ─< yazi move when exit >────────────────────────────────────────────────────────────────
function y() { function y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
@ -170,65 +93,81 @@ if command_exists yazi; then
} }
alias lf="y || ya pack -i" alias lf="y || ya pack -i"
elif command_exists ranger; then elif command-exists ranger; then
echo_info "ranger is the explorer of choice" echo-info "ranger is the explorer of choice"
alias lf="ranger" alias lf="ranger"
elif command_exists lf; then elif command-exists lf; then
echo_info "lf is the explorer of choice" echo-info "lf is the explorer of choice"
else else
echo_missing "yazi" echo-missing "yazi"
fi fi
# ─< colorized ls >───────────────────────────────────────────────────────────────────────── # ─< colorized ls >─────────────────────────────────────────────────────────────────────────
if command_exists exa; then if command-exists exa; then
alias ls="exa --icons -l --git" alias ls="exa --icons -l --git"
alias l="exa --long --no-filesize --no-permissions --no-time --git --colour-scale --icons" 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 ll="exa --all --long --no-filesize --no-permissions --no-time --git --colour-scale --icons"
alias tree="exa --icons -l --tree" alias tree="exa --icons -l --tree"
elif command_exists lsd; then elif command-exists lsd; then
alias ls="lsd -l -1 -h1 --almost-all --git" alias ls="lsd -l -1 -h1 --almost-all --git"
alias l="lsd -1" alias l="lsd -1"
alias ll="lsd -1 --almost-all" alias ll="lsd -1 --almost-all"
alias clearl="command clear && l" alias clearl="command clear && l"
alias tree="lsd --tree" alias tree="lsd --tree"
elif command_exists eza; then elif command-exists eza; then
alias ls="eza --icons --long --git" alias ls="eza --icons --long --git"
alias l="eza --icons -l" alias l="eza --icons -l"
alias ll="eza --icons -laa" alias ll="eza --icons -laa"
alias tree="eza --icons -l --tree" alias tree="eza --icons -l --tree"
else else
echo_missing "exa | eza | lsd" echo-missing "exa | eza | lsd"
alias ls="ls --color=always -lAph" alias ls="ls --color=always -lAph"
alias l="ls --color=always -lph -w1" alias l="ls --color=always -lph -w1"
alias ll="ls --color=always -lph" alias ll="ls --color=always -lph"
fi fi
# ─< t stands for trash(-cli) >─────────────────────────────────────────────────────────────── # ─< t stands for trash(-cli) >───────────────────────────────────────────────────────────────
if command_exists trash; then if command-exists trash; then
alias rm="trash $@" alias rm="trash $@"
alias t="trash" alias t="trash"
elif command_exists trash-cli; then elif command-exists trash-cli; then
alias rm="trash-cli $@" alias rm="trash-cli $@"
alias t="trash-cli" alias t="trash-cli"
else else
echo_missing "trash-cli" echo-missing "trash-cli"
fi
# ─< wireshark / termshark alias >────────────────────────────────────────────────────────
if command-exists termshark; then
alias ws="$_sudo termshark"
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
}
# ─< h stands for HUGO >──────────────────────────────────────────────────────────────────
if command-exists hugo; then
alias h='hugo'
alias hs='hugo server -D --noHTTPCache --disableFastRender' # --bind "$(get_ip)"'
fi fi
# ─< bat alias >──────────────────────────────────────────────────────────────────────────── # ─< bat alias >────────────────────────────────────────────────────────────────────────────
if command_exists batcat; then if command-exists batcat; then
alias cat="batcat --color=always -p --paging=never" alias cat="batcat --color=always -p --paging=never"
alias less="batcat --paging always --color=always" alias less="batcat --paging always --color=always"
# alias gd="batcat --diff" # alias gd="batcat --diff"
elif command_exists bat; then elif command-exists bat; then
alias cat="bat --color=always -p" alias cat="bat --color=always -p"
alias less="bat --paging always --color=always" alias less="bat --paging always --color=always"
# alias gd="bat --diff" # alias gd="bat --diff"
else else
echo_missing "bat" echo-missing "bat"
fi fi
# ─< 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"
@ -239,14 +178,76 @@ if command_exists fastfetch; then
exec "$SHELL" exec "$SHELL"
fi fi
else else
echo_missing "fastfetch" echo-missing "fastfetch"
fi fi
# INFO: # NOTE:
# ╭──────────────────╮ # ───────────────────────────────────< Helper functions >───────────────────────────────────
# │ containerization │ source-script() {
# ╰──────────────────╯ local url import
__podman__() { url="$1"
import="$(mktemp)"
# ─< if $1 is a local file, source this one instead >─────────────────────────────────────
if [ -f "$url" ]; then
source "$url"
sleep 0.1
return 0
else
echo-info "Sourcing external script:${NC} $url"
# ─< if $1 is a url, grab it and source it, also deletes afterwards >─────────────────────
if command-exists curl; then
curl -fsSL $url -o $import
elif command-exists wget; then
wget -o $import $url
else
echo "curl/wget is required, but missing.."
exit 69
fi
source "$import"
sleep 0.1
rm -f "$import"
fi
}
tmux-autosession() {
if [ -z "$TMUX" ]; then
sleep 0.01
# Attach to existing session if any, otherwise create one named 'main'
if tmux ls &>/dev/null; then
sleep 0.01
tmux attach-session
else
sleep 0.01
tmux new-session
fi
fi
}
# ─< Function to determine which Neovim command to use >──────────────────────────────────
choose_nvim() {
if [ -n "$TMUX" ]; then
# If inside an active tmux session, use nvim
echo "command nvim"
return
elif [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]; then
# If in a graphical environment, use Neovide
if command-exists neovide; then
echo "neovide --fork"
return
fi
fi
# Default to nvim
echo "command nvim"
}
setup-alias() {
local alias
alias="$1"
case "$alias" in
podman)
alias up="podman-compose up" alias up="podman-compose up"
alias down="podman-compose down" alias down="podman-compose down"
alias pull="podman-compose pull" alias pull="podman-compose pull"
@ -256,84 +257,27 @@ __podman__() {
alias dcs="podman-compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'" alias dcs="podman-compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'"
alias dl="podman-compose logs -f" alias dl="podman-compose logs -f"
alias dc="podman-compose" alias dc="podman-compose"
} ;;
__docker__() { docker)
alias d="docker"
alias dr="docker run --rm -it"
alias up="docker compose up" alias up="docker compose up"
alias down="docker compose down" alias down="docker compose down"
alias pull="docker compose pull" 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 drs="docker compose down && docker compose up -d --remove-orphans --force-recreate"
alias ds="docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'" alias ds="docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'"
alias dc="docker compose" alias dc="docker compose"
alias dcs="docker compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'" alias dcs="docker compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'"
alias dlog="docker compose logs" alias dlog="docker compose logs"
# Check for required dependencies if ! command-exists gmd; then
check_for_updates() {
local compose_cmd
# Determine available compose command
if command -v docker-compose &>/dev/null; then
compose_cmd="docker-compose"
elif docker compose version &>/dev/null; then
compose_cmd="docker compose"
else
echo "Error: docker-compose or docker compose not found."
return 1
fi
# Check for compose file
if [ ! -f docker-compose.yml ] && [ ! -f docker-compose.yaml ] && [ ! -f compose.yml ]; then
echo "Error: No docker-compose.yml/yaml found in current directory."
return 1
fi
# Pull images and capture output
local pull_output
if ! pull_output=$(LC_ALL=C $compose_cmd pull 2>&1); then
echo "Error pulling images:"
echo "$pull_output"
return 1
fi
# Check for updated images
local updated=0
if echo "$pull_output" | grep -q "Downloaded newer image"; then
updated=1
fi
# Update containers if needed
if [ $updated -eq 1 ]; then
echo "Updates found. Updating containers..."
$compose_cmd up -d
echo "Cleaning up old images..."
docker system prune -f
echo "Update completed."
else
echo "All containers are up to date. Current versions:"
$compose_cmd images | awk '{if(NR>1) print $2, $3, $4}'
fi
}
alias appupdate="check_for_updates"
if ! command_exists gmd; then
alias gmd='bash -c "$(curl -sLo- https://raw.githubusercontent.com/ajayd-san/gomanagedocker/main/install.sh)" && "$SHELL"' alias gmd='bash -c "$(curl -sLo- https://raw.githubusercontent.com/ajayd-san/gomanagedocker/main/install.sh)" && "$SHELL"'
fi fi
# ─< install lazydocker >───────────────────────────────────────────────────────────────── # ─< install lazydocker >─────────────────────────────────────────────────────────────────
alias inst_lazydocker="curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash" alias inst_lazydocker="curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash"
} ;;
git)
# INFO:
# ╭─────╮
# │ git │
# ╰─────╯
__git__() {
# ─< lazygit >────────────────────────────────────────────────────────────────────────────
if command_exists lazygit; then
alias lg="lazygit"
fi
# ───────────────────────────────────────< aliases >───────────────────────────────────── # ───────────────────────────────────────< aliases >─────────────────────────────────────
alias g="git" alias g="git"
alias gs="git status -sb" alias gs="git status -sb"
@ -353,41 +297,51 @@ __git__() {
# │ .. or like `git add "<file>"` │ # │ .. or like `git add "<file>"` │
# ╰──────────────────────────────────────╯ # ╰──────────────────────────────────────╯
ga() { ga() {
if [ -n "$2" ]; then local file1 file2
git diff ${1:-.} file1=$1
git add ${1:-.} file2=$2
git commit -m "$2"
if [ -n "$file2" ]; then
git diff ${file1:-.}
git add ${file1:-.}
git commit -m "$file2"
else else
git diff ${1:-.} git diff ${file1:-.}
git add ${1:-.} git add ${file1:-.}
fi fi
} }
# ──────────────────────────────────────< functions >──────────────────────────────────── # ──────────────────────────────────────< functions >────────────────────────────────────
# a neat way to clone github repos with a shotname like
# $> gcl pik4li/ReDeploy.git
gcl() { gcl() {
if [ -z "$2" ]; then local file1 file1
git clone --depth=1 "https://github.com/$1" if [ -z "$file2" ]; then
git clone --depth=1 "https://github.com/$file1"
else else
git clone --depth=1 "https://github.com/$1" "$2" git clone --depth=1 "https://github.com/$file1" "$file2"
fi fi
} }
# just a fast way to clone from my own instance with a shotname like
# $> gck dotfiles/bash
gck() { gck() {
if [ -z "$2" ]; then local uri_path clone_path
git clone --recurse-submodules --depth=1 "https://git.k4li.de/$1" repo_path=$1
clone_path=$2
if [ -z "$clone_path" ]; then
git clone --recurse-submodules --depth=1 "https://git.k4li.de/$repo_path"
else else
git clone --recurse-submodules --depth=1 "https://git.k4li.de/$1" "$2" git clone --recurse-submodules --depth=1 "https://git.k4li.de/$repo_path" "$clone_path"
fi
}
gcs() {
if [ -z "$2" ]; then
git clone --recurse-submodules --depth=1 "git@git.k4li.de:$1"
else
git clone --recurse-submodules --depth=1 "git@git.k4li.de:$1" "$2"
fi fi
} }
# Git Submodule Update - gsu
# updates submodules inside a mother repo to the latest main branch and
# commits the files directly. Perfect for dotfile repository management,
# where you JUST want to fetch all the latest changes from all submodules of
# one `big` repo
gsu() { gsu() {
echo "${CYAN}Updating submodules recursively with -> ${YELLOW}${BOLD}git submodule update --init --recursive${NC}" echo "${CYAN}Updating submodules recursively with -> ${YELLOW}${BOLD}git submodule update --init --recursive${NC}"
git submodule update --init --recursive && git submodule update --init --recursive &&
@ -437,7 +391,21 @@ __git__() {
fi fi
} }
# fast way to commit files and a message within one command, also pushes the
# latest files specifyed, with an optional commit message (defaults to 'wip')
# also checks before push, if remote changes exist, warns and does nothing if so
#
# takes in a space separated list of files, and an optional commit message. like:
# $> gwip file1 path/to/file2 dir1 ./path/to/dir2 "This would be so many commands without the `gwip` function!! <3"
#
# $> gwip 'files and folders' 'commit message'
gwip() { gwip() {
local BOLD GREEN YELLOW NC
BOLD=$'\e[1m'
GREEN=$'\e[92m'
YELLOW=$'\e[93m'
NC=$'\e[0m'
# Fetch the latest changes from the remote # Fetch the latest changes from the remote
git fetch git fetch
@ -450,18 +418,6 @@ __git__() {
local commit_files=() local commit_files=()
local commit_message local commit_message
# case "$1" in
# '.')
# commit_files=.
# commit_message="wip"
#
# echo "${CYAN}No changes on the remote branch. Adding changes and pushing with ${RED}${BOLD}'$commit_message'${NC}${CYAN} commit.${NC}"
#
# git add "$commit_files"
# git commit -m "$commit_message"
# git push
# ;;
# *)
if [[ -n "$1" ]]; then if [[ -n "$1" ]]; then
for f in "$@"; do for f in "$@"; do
if [ -f "./${f}" ] || [ -d "./${f}/" ]; then if [ -f "./${f}" ] || [ -d "./${f}/" ]; then
@ -516,32 +472,15 @@ __git__() {
echo "${RED}${BOLD}There are changes on the remote branch. Please pull the latest changes first.${NC}" echo "${RED}${BOLD}There are changes on the remote branch. Please pull the latest changes first.${NC}"
fi fi
} }
;;
[[ -f "$HOME/go/bin/lazygit" ]] && tmux)
alias lazygit="$HOME/go/bin/lazygit" && if [[ $- == *i* ]]; then
alias lg="lazygit" if $autosession; then
} tmux-autosession
# ─< wireshark / termshark alias >────────────────────────────────────────────────────────
if command_exists termshark; then
alias ws="$_sudo termshark"
fi
# Tmux session manager
if command_exists tmux; then
sleep 0.01
if [ -z "$TMUX" ]; then
sleep 0.01
# Attach to existing session if any, otherwise create one named 'main'
if tmux ls &>/dev/null; then
sleep 0.01
tmux attach-session
else
sleep 0.01
tmux new-session
fi fi
fi fi
# function to quickly go into an active session
ta() { ta() {
if tmux list-sessions >/dev/null 2>&1; then if tmux list-sessions >/dev/null 2>&1; then
echo "-- tmux session active! | Connecting to active session --" echo "-- tmux session active! | Connecting to active session --"
@ -553,85 +492,61 @@ if command_exists tmux; then
tmux tmux
fi fi
} }
;;
alias ts="tmux source $HOME/.tmux.conf" neovim)
alias cnvim="command nvim"
alias nvim="$(choose_nvim)"
nv() {
appname="$1"
shift
if [ "$#" -eq 0 ]; then
NVIM_APPNAME="$appname" command nvim
else else
echo_missing "tmux" NVIM_APPNAME="$appname" command nvim "$@"
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
} }
# ─< h stands for HUGO >────────────────────────────────────────────────────────────────── if [ -d "$HOME/.config/nvdev" ]; then
if command_exists hugo; then alias nvdev='NVIM_APPNAME="nvdev" command nvim'
alias h='hugo' alias neodev='NVIM_APPNAME="nvdev" neovide --fork'
alias hs='hugo server -D --noHTTPCache --disableFastRender' # --bind "$(get_ip)"'
fi fi
;;
esac
}
# fills in the $missing variable for the main config to get the missing cli
# tools directly inside the "dashboard"/loading page
missing() { missing() {
local e=( local essentials=() i
bash essentials=(
zsh "bash"
fzf "zsh"
curl "fzf"
git "duf"
docker "curl"
nvim "wget"
) )
for i in "$e{[@]}"; do for i in "${essentials[@]}"; do
if ! command_exists $i; then if ! command-exists $i; then
echo_missing "$i" echo-missing "$i"
fi fi
done done
} }
# INFO:
# ╭─────────────────╮
# │ other functions │
# ╰─────────────────╯
source-script() {
local url="$1"
local import="$(mktemp)"
# ─< if $1 is a local file, source this one instead >─────────────────────────────────────
if [ -f "$url" ]; then
source "$url"
sleep 0.1
return 0
else
echo_info "Sourcing external script:${NC} $url"
# ─< if $1 is a url, grab it and source it, also deletes afterwards >─────────────────────
if command_exists curl; then
curl -fsSL $url -o $import
elif command_exists wget; then
wget -o $import $url
else
echo "curl/wget is required, but missing.."
exit 69
fi
source "$import"
sleep 0.1
rm -f "$import"
fi
}
resolve() { resolve() {
local quiet=false local quiet ip server dig_out line ptr hostname time
quiet=false
if [[ "$1" == "-q" ]]; then if [[ "$1" == "-q" ]]; then
quiet=true quiet=true
shift shift
fi fi
local ip="$1" ip="$1"
local server="$2" server="$2"
local dig_out
dig_out=$(command dig +noall +answer -x "$ip" ${server:+@$server} 2>/dev/null) dig_out=$(command dig +noall +answer -x "$ip" ${server:+@$server} 2>/dev/null)
local line ptr hostname time
line=$(grep 'PTR' <<<"$dig_out") line=$(grep 'PTR' <<<"$dig_out")
ptr=$(awk '{print $4}' <<<"$line") ptr=$(awk '{print $4}' <<<"$line")
time=$(awk '{print $2}' <<<"$dig_out") time=$(awk '{print $2}' <<<"$dig_out")
@ -648,26 +563,40 @@ resolve() {
"$ptr" "$ip" "$hostname" "$time" "$ptr" "$ip" "$hostname" "$time"
else else
# ❌ not resolved # ❌ not resolved
printf "\033[1;31m%s${NC} \033[1;90m%s${NC} \033[1;31mNOT FOUND${NC} \033[2m%s ms\033[0m\n" \ printf "${RED}%s${NC} \033[1;90m%s${NC} \033[1;31mNOT FOUND${NC} \033[2m%s ms\033[0m\n" \
"PTR" "$ip" "${time:-0}" "PTR" "$ip" "${time:-0}"
fi fi
} }
main() { main() {
# ─< g stands for GIT >───────────────────────────────────────────────────────────────────── # ─< g stands for GIT >─────────────────────────────────────────────────────────────────────
if command_exists git; then if command-exists git; then
__git__ setup-alias git
else else
echo_missing "git" echo-missing "git"
fi
# Set up Neovim aliases based on environment
if command-exists nvim; then
setup-alias neovim
else
echo-missing "neovim"
fi fi
# ─< d stands for docker >────────────────────────────────────────────────────────────────── # ─< d stands for docker >──────────────────────────────────────────────────────────────────
if command_exists docker; then if command-exists docker; then
__docker__ setup-alias docker
elif command_exists podman; then elif command-exists podman; then
__podman__ setup-alias podman
else else
echo_missing "docker | podman" echo-missing "docker | podman"
fi
# Tmux session manager
if command-exists tmux; then
setup-alias tmux
else
echo-missing "tmux"
fi fi
} }

148
.bashrc
View file

@ -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
} }