dotfiles/.config/shell/aliases

155 lines
3.4 KiB
Text
Raw Permalink Normal View History

#!/bin/sh
# Aliases used in all kinds of shells
# Make non-interactive `bash` expand aliases as well (e.g., ":!cmd" in `vim`)
if [ -n "${BASH_VERSION:-}" ]; then
shopt -s expand_aliases
fi
forget() { # the current history and restore $HISTFILE from disk
if [ -n "$BASH_VERSION" ]; then
history -c
history -r
elif [ -n "$ZSH_VERSION" ]; then
_histsize=$HISTSIZE
HISTSIZE=0 # because shrinking the list to 0 discards all entries
HISTSIZE=$_histsize
unset _histsize
fc -R "$HISTFILE"
fi
}
if [ -n "$ZSH_VERSION" ]; then
alias forget=' forget' # Leading space => The invocation itself is forgotten because of `setopt HIST_IGNORE_SPACE`
fi
alias path='echo $PATH | tr ":" "\n"'
# Easier `cd` movements
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
# Use human-readable sizes
alias df='df --human-readable'
alias du='du --human-readable'
alias free='free --human'
# Make the terminal more colorful
alias diff='diff --color=auto'
alias grep='grep --color=auto --exclude-dir=.git'
alias ip='ip -color=auto'
if _command_exists dircolors; then
# Compute `$LS_COLORS` only once because this file is also sourced
# by every non-interactive `bash` via `$BASH_ENV` (e.g., ":!cmd" in `vi`)
if [ -z "${LS_COLORS:-}" ]; then
if [ -r "$XDG_CONFIG_HOME/dircolors" ]; then
eval "$(dircolors -b "$XDG_CONFIG_HOME/dircolors")"
else
eval "$(dircolors -b)"
fi
fi
alias ls='ls --color=auto'
fi
# Add common `ls` utilities
alias l='ls --classify --format=vertical'
alias la='ls --classify --format=vertical --almost-all'
alias lal='ls --classify --format=long --almost-all'
alias ll='ls --classify --format=long'
alias lla='lal'
2026-09-11 19:21:35 +02:00
if _command_exists age; then
alias aged='age -d -i ~/.config/age/identity.txt'
alias agee='age -r age1gzy6tj8y93ljuelcedrkcsv3p6gygk7ng3386u32av9a4ujh737qef8crp'
fi
2026-08-03 14:28:42 +02:00
if _command_exists xclip; then
alias clip='xclip -selection clipboard'
alias clip-out='xclip -selection clipboard -o'
alias c='clip'
fi
if _command_exists git; then
# Manage the bare `git` repository in ~/ holding the dotfiles
alias dotfiles='git --git-dir=$DOTFILES_DIR --work-tree=$HOME'
alias g='git'
# Create "g" prefixed aliases from the "real" aliases
# defined under "[alias]" in ~/.config/git/config,
# for example, `gap` for `git add --patch`
#
# Interactive shells only: This spawns a `git` process,
# which every non-interactive `bash` via `$BASH_ENV`
# (e.g., ":!cmd" in `vi`) would pay on each command
# => There, `g ap` works just as well as `gap`
case $- in
*i*)
for al in $(git aliases --real); do
eval "alias g$al='git $al'"
done
unset al
;;
esac
fi
2026-08-03 04:00:21 +02:00
alias py='python3'
ipy() {
if _command_exists ipython; then
ipython "$@"
elif _command_exists ipython3; then
ipython3 "$@"
else
echo "ipython is not installed" >&2
return 1
fi
}
_command_exists poetry && alias pr='poetry run'
if _command_exists pyenv; then
alias pyvenvs='pyenv virtualenvs --bare --skip-aliases'
alias pyver='pyenv version'
alias pyvers='pyenv versions --skip-aliases'
alias pywhich='pyenv which'
fi
if _command_exists vim; then
alias v='vim'
_command_exists sudoedit && alias sv='sudoedit'
fi