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:
# ╭──────────╮
# │ defaults │
@ -50,7 +12,7 @@ alias ...="cd ../.."
# ─< colored ip >───────────────────────────────────────────────────────────────────
alias ip="ip --color=always"
if command_exists curl; then
if command-exists curl; then
# ─< linutil >────────────────────────────────────────────────────────────────────────────
alias linutil="curl -fsSL https://christitus.com/linux | sh"
alias "linutil-dev"="curl -fsSL https://christitus.com/linuxdev | sh"
@ -58,107 +20,68 @@ if command_exists curl; then
# ─< weather >──────────────────────────────────────────────────────────────────────────────
alias www="curl wttr.in/Ulm"
else
echo_missing "curl"
echo-missing "curl"
fi
# ─< check for rg >─────────────────────────────────────────────────────────────────────────
if command_exists rg; then
if command-exists rg; then
alias grep="rg --color=always"
alias hl="rg --passthrough"
else
echo_missing "ripgrep"
echo-missing "ripgrep"
alias grep="grep --color=always"
alias hl="grep --passthrough"
fi
hm() {
find -type f -name "${1}" | wc -l
}
if command_exists dog; then
if command-exists dog; then
alias dig="dog"
fi
# ─< define copy command >────────────────────────────────────────────────────────────────
if command_exists wl-copy; then
if command-exists wl-copy; then
copy() {
if cat "$1"; then
command cat "$1" | wl-copy
local file
file="$1"
if cat "$file"; then
command cat "$file" | wl-copy
else
"$1" | wl-copy
"$file" | wl-copy
fi
}
elif command_exists xclip; then
elif command-exists xclip; then
copy() {
if cat "$1"; then
command cat "$1" | wl-copy
local file
file="$1"
if cat "$file"; then
command cat "$file" | wl-copy
else
"$1" | xclip -selection clipboard
"$file" | xclip -selection clipboard
fi
}
else
echo_missing "wl-clipboard | xclip"
echo-missing "wl-clipboard | xclip"
fi
# ─< telnet (starwars) >────────────────────────────────────────────────────────────────────
if command_exists telnet; then
if command-exists telnet; then
alias starwars="telnet -a telehack.com"
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'
fi
# ─< rsync >────────────────────────────────────────────────────────────────────────────────
if command_exists rsync; then
if command-exists rsync; then
alias scp="rsync -avP"
alias cp="rsync -avP"
else
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"
echo-missing "rsync"
fi
# ─< cli explorer >───────────────────────────────────────────────────────────────────────
if command_exists yazi; then
echo_info "yazi is the explorer of choice"
if command-exists yazi; then
echo-info "yazi is the explorer of choice"
# ─< yazi move when exit >────────────────────────────────────────────────────────────────
function y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
@ -170,65 +93,81 @@ if command_exists yazi; then
}
alias lf="y || ya pack -i"
elif command_exists ranger; then
echo_info "ranger is the explorer of choice"
elif command-exists ranger; then
echo-info "ranger is the explorer of choice"
alias lf="ranger"
elif command_exists lf; then
echo_info "lf is the explorer of choice"
elif command-exists lf; then
echo-info "lf is the explorer of choice"
else
echo_missing "yazi"
echo-missing "yazi"
fi
# ─< colorized ls >─────────────────────────────────────────────────────────────────────────
if command_exists exa; then
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
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
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
echo_missing "exa | eza | lsd"
echo-missing "exa | eza | lsd"
alias ls="ls --color=always -lAph"
alias l="ls --color=always -lph -w1"
alias ll="ls --color=always -lph"
fi
# ─< t stands for trash(-cli) >───────────────────────────────────────────────────────────────
if command_exists trash; then
if command-exists trash; then
alias rm="trash $@"
alias t="trash"
elif command_exists trash-cli; then
elif command-exists trash-cli; then
alias rm="trash-cli $@"
alias t="trash-cli"
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
# ─< bat alias >────────────────────────────────────────────────────────────────────────────
if command_exists batcat; then
if command-exists batcat; then
alias cat="batcat --color=always -p --paging=never"
alias less="batcat --paging always --color=always"
# alias gd="batcat --diff"
elif command_exists bat; then
elif command-exists bat; then
alias cat="bat --color=always -p"
alias less="bat --paging always --color=always"
# alias gd="bat --diff"
else
echo_missing "bat"
echo-missing "bat"
fi
# ─< fastfetch >────────────────────────────────────────────────────────────────────────────
if command_exists fastfetch; then
if command-exists fastfetch; then
alias ff="fastfetch"
alias clearff="command clear & fastfetch"
alias clearf="command clear & fastfetch"
@ -239,14 +178,76 @@ if command_exists fastfetch; then
exec "$SHELL"
fi
else
echo_missing "fastfetch"
echo-missing "fastfetch"
fi
# INFO:
# ╭──────────────────╮
# │ containerization │
# ╰──────────────────╯
__podman__() {
# NOTE:
# ───────────────────────────────────< Helper functions >───────────────────────────────────
source-script() {
local url import
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 down="podman-compose down"
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 dl="podman-compose logs -f"
alias dc="podman-compose"
}
__docker__() {
;;
docker)
alias d="docker"
alias dr="docker run --rm -it"
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 --format 'table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'"
alias dc="docker compose"
alias dcs="docker compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'"
alias dlog="docker compose logs"
# Check for required dependencies
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
if ! command-exists gmd; then
alias gmd='bash -c "$(curl -sLo- https://raw.githubusercontent.com/ajayd-san/gomanagedocker/main/install.sh)" && "$SHELL"'
fi
# ─< install lazydocker >─────────────────────────────────────────────────────────────────
alias inst_lazydocker="curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash"
}
# INFO:
# ╭─────╮
# │ git │
# ╰─────╯
__git__() {
# ─< lazygit >────────────────────────────────────────────────────────────────────────────
if command_exists lazygit; then
alias lg="lazygit"
fi
;;
git)
# ───────────────────────────────────────< aliases >─────────────────────────────────────
alias g="git"
alias gs="git status -sb"
@ -353,41 +297,51 @@ __git__() {
# │ .. or like `git add "<file>"` │
# ╰──────────────────────────────────────╯
ga() {
if [ -n "$2" ]; then
git diff ${1:-.}
git add ${1:-.}
git commit -m "$2"
local file1 file2
file1=$1
file2=$2
if [ -n "$file2" ]; then
git diff ${file1:-.}
git add ${file1:-.}
git commit -m "$file2"
else
git diff ${1:-.}
git add ${1:-.}
git diff ${file1:-.}
git add ${file1:-.}
fi
}
# ──────────────────────────────────────< functions >────────────────────────────────────
# a neat way to clone github repos with a shotname like
# $> gcl pik4li/ReDeploy.git
gcl() {
if [ -z "$2" ]; then
git clone --depth=1 "https://github.com/$1"
local file1 file1
if [ -z "$file2" ]; then
git clone --depth=1 "https://github.com/$file1"
else
git clone --depth=1 "https://github.com/$1" "$2"
git clone --depth=1 "https://github.com/$file1" "$file2"
fi
}
# just a fast way to clone from my own instance with a shotname like
# $> gck dotfiles/bash
gck() {
if [ -z "$2" ]; then
git clone --recurse-submodules --depth=1 "https://git.k4li.de/$1"
local uri_path clone_path
repo_path=$1
clone_path=$2
if [ -z "$clone_path" ]; then
git clone --recurse-submodules --depth=1 "https://git.k4li.de/$repo_path"
else
git clone --recurse-submodules --depth=1 "https://git.k4li.de/$1" "$2"
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"
git clone --recurse-submodules --depth=1 "https://git.k4li.de/$repo_path" "$clone_path"
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() {
echo "${CYAN}Updating submodules recursively with -> ${YELLOW}${BOLD}git submodule update --init --recursive${NC}"
git submodule update --init --recursive &&
@ -437,7 +391,21 @@ __git__() {
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() {
local BOLD GREEN YELLOW NC
BOLD=$'\e[1m'
GREEN=$'\e[92m'
YELLOW=$'\e[93m'
NC=$'\e[0m'
# Fetch the latest changes from the remote
git fetch
@ -450,18 +418,6 @@ __git__() {
local commit_files=()
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
for f in "$@"; do
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}"
fi
}
[[ -f "$HOME/go/bin/lazygit" ]] &&
alias lazygit="$HOME/go/bin/lazygit" &&
alias lg="lazygit"
}
# ─< 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
;;
tmux)
if [[ $- == *i* ]]; then
if $autosession; then
tmux-autosession
fi
fi
# function to quickly go into an active session
ta() {
if tmux list-sessions >/dev/null 2>&1; then
echo "-- tmux session active! | Connecting to active session --"
@ -553,85 +492,61 @@ if command_exists tmux; then
tmux
fi
}
;;
neovim)
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
}
alias ts="tmux source $HOME/.tmux.conf"
else
echo_missing "tmux"
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
if [ -d "$HOME/.config/nvdev" ]; then
alias nvdev='NVIM_APPNAME="nvdev" command nvim'
alias neodev='NVIM_APPNAME="nvdev" neovide --fork'
fi
;;
esac
}
# ─< h stands for HUGO >──────────────────────────────────────────────────────────────────
if command_exists hugo; then
alias h='hugo'
alias hs='hugo server -D --noHTTPCache --disableFastRender' # --bind "$(get_ip)"'
fi
# fills in the $missing variable for the main config to get the missing cli
# tools directly inside the "dashboard"/loading page
missing() {
local e=(
bash
zsh
fzf
curl
git
docker
nvim
local essentials=() i
essentials=(
"bash"
"zsh"
"fzf"
"duf"
"curl"
"wget"
)
for i in "$e{[@]}"; do
if ! command_exists $i; then
echo_missing "$i"
for i in "${essentials[@]}"; do
if ! command-exists $i; then
echo-missing "$i"
fi
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() {
local quiet=false
local quiet ip server dig_out line ptr hostname time
quiet=false
if [[ "$1" == "-q" ]]; then
quiet=true
shift
fi
local ip="$1"
local server="$2"
local dig_out
ip="$1"
server="$2"
dig_out=$(command dig +noall +answer -x "$ip" ${server:+@$server} 2>/dev/null)
local line ptr hostname time
line=$(grep 'PTR' <<<"$dig_out")
ptr=$(awk '{print $4}' <<<"$line")
time=$(awk '{print $2}' <<<"$dig_out")
@ -648,26 +563,40 @@ resolve() {
"$ptr" "$ip" "$hostname" "$time"
else
# ❌ 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}"
fi
}
main() {
# ─< g stands for GIT >─────────────────────────────────────────────────────────────────────
if command_exists git; then
__git__
if command-exists git; then
setup-alias git
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
# ─< d stands for docker >──────────────────────────────────────────────────────────────────
if command_exists docker; then
__docker__
elif command_exists podman; then
__podman__
if command-exists docker; then
setup-alias docker
elif command-exists podman; then
setup-alias podman
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
}

148
.bashrc
View file

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