#!/bin/sh # Aliases used in all kinds of shells 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' 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 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