Files
dotfiles/dot_config/bash/dot_bash_aliases
2025-04-24 02:32:32 -03:00

177 lines
5.8 KiB
Plaintext

# shellcheck shell=bash
# shellcheck disable=SC1090,SC1091,SC2034
# Set aliases
hash ug 2>/dev/null && alias grep="ug"
hash bat 2>/dev/null && alias cat="bat -p"
hash zoxide 2>/dev/null && alias cd="z"
hash fd 2>/dev/null && alias find="fd"
hash numbat 2>/dev/null && alias bc="numbat"
# hash sd 2>/dev/null && alias sed="sd" # Disabled because some scripts use sed, and don't set the -i flag
hash dust 2>/dev/null && alias du="dust"
hash tealdeer 2>/dev/null && alias tldr="tealdeer"
hash hexyl 2>/dev/null && alias xxd="hexyl"
hash xdg-open 2>/dev/null && alias start="xdg-open"
hash micro 2>/dev/null && alias edit="micro" && alias nano="micro"
hash nvim 2>/dev/null && alias vim="nvim" && alias vi="nvim"
hash trash-put 2>/dev/null && alias rm="trash-put" && alias tp="trash-put"
hash gallery-dl 2>/dev/null && alias gallery-dl="gallery-dl --cookies-from-browser firefox"
if [[ -n $BASH_VERSION ]]; then
alias rc='source "$XDG_CONFIG_HOME"/bash/.bashrc'
elif [[ -n $ZSH_VERSION ]]; then
alias rc='source "$XDG_CONFIG_HOME"/zsh/.zshrc'
fi
if hash lsb_release 2>/dev/null; then
if [[ $(lsb_release -si) =~ "Arch" ]]; then
alias update-mirrors="rate-mirrors arch | sudo tee /etc/pacman.d/mirrorlist; rate-mirrors chaotic-aur | sudo tee /etc/pacman.d/chaotic-mirrorlist"
# System package managers
hash pacman 2>/dev/null && command="sudo pacman -Syu; sudo pacman -Sc;"
hash pamac 2>/dev/null && command="pamac update; pamac clean;"
hash yay 2>/dev/null && command="yay; yay -Sc;"
hash paru 2>/dev/null && command="paru; paru -c;"
# Non system packages
hash flatpak 2>/dev/null && command+="flatpak update; flatpak uninstall --unused;"
# We want this to be expanded to the command, as the command is not very helpful
# shellcheck disable=SC2139
alias update="$command"
elif [[ $(lsb_release -si) =~ "Debian" || $(lsb_release -si) =~ "Ubuntu" ]]; then
# Unset on Debian/Ubuntu
# alias update-mirrors=""
# System package managers
hash apt 2>/dev/null && command="sudo apt update && sudo apt upgrade && sudo apt autoremove;"
# Non system packages
hash flatpak 2>/dev/null && command+="flatpak update; flatpak uninstall --unused;"
# We want this to be expanded to the command, as the command is not very helpful
# shellcheck disable=SC2139
alias update="$command"
fi
# Non privaledged environemnt, have to use local package managers like eget, nix, etc
else
alias update-mirrors="echo 'No mirrors to update'"
alias update='eget -D; . "$HOME"/.config/eget/post_install.sh'
alias nix-shell-local="nix-user-chroot ~/.local/share/nix bash"
if [ -e ~/.nix-profile/etc/profile.d/nix.sh ]; then
. ~/.nix-profile/etc/profile.d/nix.sh
fi
fi
if hash eza 2>/dev/null; then
function ls {
if [[ "$*" =~ "-a" || "$*" =~ "-A" || "$*" =~ "--all" || "$*" =~ "--almost-all" ]]; then
eza --icons --long "$@"
else
eza --icons --long --ignore-glob "$([[ -f .hidden ]] && < .hidden tr '\n' '|')" "$@"
fi
}
fi
function clamav-exception-add {
if [[ -z $1 ]]; then
echo "Usage: clamav-exception-add <file>"
return 1
fi
if [[ ! -f $1 ]]; then
echo "File not found: $1"
return 1
fi
sudo bash -c "sigtool --sha256 $1 >> /var/lib/clamav/user-defined-exceptions.sfp"
}
# Dotfiles management
# TODO: Rewrite to use bash read instead of zsh read
if hash chezmoi 2>/dev/null; then
function .add {
if [[ -z $1 || -z $2 ]]; then
echo "Usage: .add <file> <message>"
return 1
fi
chezmoi add "$1"
chezmoi git add .
chezmoi git status
echo -n "Commit changes? [y/N] "
read -r answer
if [[ $answer =~ ^[Yy]$ ]]; then
chezmoi git -- commit -m "$2"
echo -n "Push changes? [y/N] "
read -r answer
if [[ $answer =~ ^[Yy]$ ]]; then
chezmoi git push
fi
fi
}
# TODO: Rewrite to use bash read instead of zsh read
function .re-add {
if [[ -z $1 ]]; then
echo "Usage: .re-add <message>"
return 1
fi
chezmoi re-add
chezmoi git status
chezmoi git diff
echo -n "Commit changes? [y/N] "
read -r answer
if [[ $answer =~ ^[Yy]$ ]]; then
chezmoi git -- commit -am "$1"
echo -n "Push changes? [y/N] "
read -r answer
if [[ $answer =~ ^[Yy]$ ]]; then
chezmoi git push
fi
fi
}
alias .push="chezmoi git push"
alias .pull="chezmoi git pull"
alias .status="chezmoi git status"
alias .diff="chezmoi git diff"
alias .update="chezmoi update"
fi
# XDG aliases
alias wget='wget --hsts-file="$XDG_DATA_HOME"/wget-hsts'
alias yarn='yarn --use-yarnrc "$XDG_CONFIG_HOME"/yarn/config'
alias units='units --history "$XDG_DATA_HOME"/units_history'
alias nvidia-settings='nvidia-settings --config="$XDG_CONFIG_HOME"/nvidia/settings'
alias adb='HOME="$XDG_DATA_HOME"/android adb'
# If we have local rust installed, set it up
if [[ -f $XDG_DATA_HOME/cargo/env ]]; then
. "$XDG_DATA_HOME/cargo/env"
fi
# Final shell specific init
if [[ -n $BASH_VERSION ]]; then
# https://github.com/pkasemir/find-the-command
[[ -f /usr/share/doc/find-the-command/ftc.bash ]] && source /usr/share/doc/find-the-command/ftc.bash noupdate quiet info
# https://wiki.archlinux.org/title/Pkgfile#Command_not_found
# [[ -f /usr/share/doc/pkgfile/command-not-found.bash ]] && source /usr/share/doc/pkgfile/command-not-found.bash
# Starship after defining custom prompt, easy to remove
eval "$(starship init bash)"
# Zoxide init has to be last
eval "$(zoxide init bash)"
elif [[ -n $ZSH_VERSION ]]; then
# https://github.com/pkasemir/find-the-command
[[ -f /usr/share/doc/find-the-command/ftc.zsh ]] && source /usr/share/doc/find-the-command/ftc.zsh noupdate quiet info
# https://wiki.archlinux.org/title/Pkgfile#Command_not_found
# [[ -f /usr/share/doc/pkgfile/command-not-found.zsh ]] && source /usr/share/doc/pkgfile/command-not-found.zsh
# Starship after defining custom prompt, easy to remove
hash starship 2>/dev/null && eval "$(starship init zsh)"
# Zoxide init has to be last
hash zoxide 2>/dev/null && eval "$(zoxide init zsh)"
fi