case "$(basename "$(readlink -f /proc/$$/exe)")" in zsh) thisfile="$(readlink -f "${(%):-%N}")";; bash) thisfile="$(readlink -f "${BASH_SOURCE[0]}")";; *) thisfile="$(find /proc/$$/fd/ -print0 | xargs -0 -n1 -r readlink -f | grep aliases | head -n1)";; esac # Global aliases for ZSH if alias -g 2>/dev/null; then alias -g ...=../.. alias -g ....=../../.. alias -g .....=../../../.. alias -g ......=../../../../.. alias -g NO="1> /dev/null" alias -g NE="2> /dev/null" alias -g NUL="&> /dev/null" alias -g BG="&;disown" fi # File default aliases if alias -s 2>/dev/null; then alias -s pdf="open" alias -s jar="java -jar" alias -s git="git clone --recursive" fi alias l=ll alias ls='ls --color=auto' alias ll='ls -lFh --group-directories-first' alias la='ls -lAFh --group-directories-first' alias lt='ls -lFh --sort=time' alias lat='ls -lAFh --sort=time' alias lsz='ls -lAFh --sort=size' alias al=la # No, I don't need the Mono Assembly Linker alias md='mkdir -p' alias rd='rmdir -p' alias -- -='cd -' cdt() { cd "$(mktemp -d -t "${1:-tmp}.XXXXXXXX")"; } alias svi=sudoedit alias svim=sudoedit # This will enable us to use aliases in sudo. # (If alias finishes with a space or tab, the shell will check if the next command is also aliased.) # Source: https://github.com/mayah/home/blob/master/.zsh/zshrc.d/alias.zsh alias sudo='sudo ' alias open=xdg-open # Command rewrites alias rm='rm -iv' alias mv='mv -i' alias cp='cp -ir' alias scp='scp -r' alias dd='dd status=progress' alias wget='wget --hsts-file=$XDG_DATA_HOME/wget/hsts-file' alias vi=vim alias grip='grip --user=frebib --pass=$GRIP_API_KEY' alias acme.sh='$XDG_CONFIG_HOME/acme.sh/acme.sh --home $XDG_CONFIG_HOME/acme.sh --config-home $XDG_CONFIG_HOME/acme.sh --log $XDG_CONFIG_HOME/acme.sh/acme.sh.log' alias acmesh='$XDG_CONFIG_HOME/acme.sh/acme.sh --home $XDG_CONFIG_HOME/acme.sh --config-home $XDG_CONFIG_HOME/acme.sh --log $XDG_CONFIG_HOME/acme.sh/acme.sh.log' alias alpine-sdk="docker run -ti --rm \ -e USER \ -e UID=\"\$(id -u)\" \ -e PWD \ -e HOME \ -w \$PWD \ -v \$PWD:\$PWD \ -v ~/.abuild:\$HOME/.abuild \ -v ~/.abuild/distfiles:/var/cache/distfiles \ frebib/alpine-sdk:edge" alias abuild='alpine-sdk abuild' alias abuild-sign='alpine-sdk abuild-sign' alias apk='alpine-sdk apk' alias hddtemps='find /sys/block/ -name sd\* | sed "s|sys/block|dev|g" | sudo xargs hddtemp | sort -t: -k3' alias stripansi='sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g"' alias calc="noglob bc -l <<<" # noglob allows * without quoting exists pacman && \ alias pacman='pacman --color=always' exists yay && \ alias p='yay' exists tree && \ alias tree='tree --dirsfirst -C -F' exists make && \ alias make="make -j$(nproc)" exists gopass && \ alias pass='gopass' echo | busybox grep --color '' >/dev/null 2>&1 && \ alias grep='grep --color' vim --version 2>/dev/null | command grep -q +clientserver && \ alias vim="vim --servername vim -p" # Function aliases env() { command env "$@" | stripansi | sort; } mcd(){ mkdir -p -- "$@" && cd -- "$@"; } randstr() { tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$1" | head -n 1; } # System aliases alias sc="systemctl" alias ssc="sudo systemctl" alias scu="systemctl --user" alias j=journalctl alias ps='ps aux' alias catn='tail -n +1 --' alias kl='killall -s 9' alias chx='chmod +x' # Git Aliases alias git='TZ=UTC git' alias g=git alias ginit='git init' alias gignore='$EDITOR .gitignore' alias gitc='$EDITOR $XDG_CONFIG_HOME/git/config' alias ggignore='$EDITOR $XDG_CONFIG_HOME/git/gitignore' alias gcl="git clone --recursive" alias gco="git checkout" alias gcom="git checkout \"\$(git defbranch)\"" alias ga="git add" alias gap="git add -p" alias gau="git add -u" alias gaN="git add -N" alias gaa="ga -A" alias grm="git rm" alias gmv="git mv" alias gc="git commit -s" alias gcm="git commit -s -em" alias gca="git commit -s --amend --date=\"\$(date -R)\"" alias gcn="git commit -s --no-edit" alias gcan="gca -s --no-edit" alias gcam="gca -s -m" alias gst="git status" alias grl="git reflog" alias gm="git merge" alias gma="git merge --abort" alias grb="git rebase" alias grbi="grb -i" alias grba="grb --abort" alias grbc="grb --continue" alias grbsk="grb --skip" alias grbsh="grb --show-current" alias grbom="git rebase \"origin/\$(git defbranch)\"" gfrb() { remote="${1%%/*}"; git fetch "$remote" && git rebase "$@"; } gfrbi() { remote="${1%%/*}"; git fetch "$remote" && git rebase -i "$@"; } alias gam="git am" alias gama="git am --abort" alias gamc="git am --continue" alias gamsk="git am --skip" alias gcp="git cherry-pick" alias gcpa="git cherry-pick --abort" alias gcpc="git cherry-pick --continue" alias gcpsk="git cherry-pick --skip" alias grv="git revert" alias grva="git revert --abort" alias grvc="git revert --continue" alias grvsk="git revert --skip" alias gf="git fetch" alias gp="git push" alias gpf="gp --force" alias gpsu="git push --set-upstream" alias gpoH="git push origin HEAD" alias gpsuom="git push --set-upstream origin \"\$(git defbranch)\"" alias gpall="git remote | xargs -L1 git push" alias gl="git pull --rebase" alias glp="gl && gp" alias gd="git diff --patch-with-stat" alias gdni="gd --no-index" alias gds="gd --staged" alias gsh="git show --format=fuller --patch-with-stat" alias glg="git log --color --format=fuller --stat --no-merges --graph" alias glgp="git log --color --format=fuller --patch-with-stat --no-merges --graph" alias glog="git log --color --oneline --decorate --graph" alias grst="git reset" alias gundo="git reset --keep @~1" alias gclean="git clean" alias gclm="git cleanmerged" alias gbr="git branch" alias gbrl="git for-each-ref --sort=committerdate refs/heads/ --format=\"%(refname:short)\" | fzf -x --ansi --multi --preview-window=right:70% --preview=\"git log --format=fuller --stat --color=always {} | head -n\$((\$(tput lines)*10))\"" alias gtg="git tag" alias gbl="git blame" alias gr="git remote" alias gra="gr add" alias grr="gr rm" alias grao="gra origin" alias grro="grr origin" alias gsta='git stash' alias gstd='gsta drop' alias gstl='gsta list --stat --color' alias gstp='gsta pop' alias gstv="gsta show -p stash@{0}" # Docker aliases alias d=docker alias dps="docker ps --format='table {{.ID}}\t{{.Image}}\t{{.Label \"org.label-schema.version\"}}\t{{.Networks}}\t{{.RunningFor}}\t{{.Status}}\t{{.Names}}' | sed '1s/version/VERSION/'" alias dpsa="docker ps -a --format='table {{.ID}}\t{{.Image}}\t{{.Label \"org.label-schema.version\"}}\t{{.Networks}}\t{{.RunningFor}}\t{{.Status}}\t{{.Names}}' | sed '1s/version/VERSION/'" alias dnets="docker network ls -q | xargs docker inspect | jq '.[] | select(.Name != \"host\" and .Name != \"none\") | [.] | map(.Name + \"\t\" + (.IPAM.Config | map(.Subnet) | join(\"\t\")))[]' -r | sort -V -k2,3 | column -t" daddrs() { docker inspect "${1:-bridge}" | jq '.[0].Containers | map(.Name + "\t" + .IPv4Address + "\t" + .IPv6Address)[]' -r | sort -V -k2,3 | column -t; } alias din='docker inspect' alias drm='docker rm' alias drmi='docker rmi' alias dim='docker images' alias dbl='docker build --pull' alias dbl.='docker build --pull .' alias drun='docker run -ti' alias dkl='docker kill' alias drmf='docker rm -f' alias dst='docker stop' alias drst='docker restart' alias dnet='docker network' alias dvol='docker volume' alias dc='docker compose' alias dlg='docker logs --tail=1000 -f' alias dalpine='docker run -ti --rm spritsail/alpine /bin/sh' alias drm-stopped='docker container prune' alias drmi-untag='docker image prune' alias dprune='docker system prune -f' dsh() { do_dsh 2 exec "$@"; return $?; } _dsh() { __docker_complete_running_containers "$@"; } drsh() { do_dsh 4 run --rm --entrypoint= "$@"; return $?; } _drsh() { __docker_container_subcommand "$@"; } do_dsh() { local minargs=$1 shift if [ $# -lt "$minargs" ]; then # shellcheck disable=SC2154 echo "Usage: ${funcstack[2]} [user@]container [program [args]]" >&2 return 64 fi local dowhat="$1" local docker_args=("$dowhat" -ti) shift while [ "${1:0:1}" = '-' ]; do if [ "${1:0:2}" != '--' ]; then docker_args+=("$1") shift fi docker_args+=("$1") shift done local user user="$(echo "$1" | cut -d@ -f1 -s)" declare -a prog prog=("${@:2:$#}") if [ -z "$user" ]; then host="$1" else host="$(cut -d@ -f2 -s <<< "$1")" docker_args+=("--user=$user") fi if [ "$dowhat" = exec ] && [ -z "$(docker ps -q -f name="$host" <&-)" ]; then echo "No such container $host" >&2 return 5 fi if [ "$dowhat" = run ]; then docker image pull "$host" fi if [ ${#prog[@]} = 0 ]; then shell_args=("$dowhat") if [ "$dowhat" = 'run' ]; then shell_args+=(--rm --entrypoint=) fi for shell in bash sh; do shell_path="$(set -o pipefail; docker "${shell_args[@]}" "$host" which "$shell" <&- | sed 's|[\r\n]||g')" retval=$? if [ $retval -eq 0 ]; then prog=("$shell_path") break elif [ $retval -ge 125 ]; then return fi done if [ ${#prog[@]} = 0 ]; then echo "Warning: No shell found in path.. trying /bin/sh" >&2 prog=(/bin/sh) fi fi docker "${docker_args[@]}" "$host" "${prog[@]}" } alias dm='docker-machine' dmc() { eval "$(docker-machine env "$1")"; } # ZFS aliases alias zfs='sudo zfs' alias zpool='sudo zpool' alias zp=zpool zl() { (set -o pipefail; command zfs list "$@" | grep -Ev 'docker/[0-9a-f]{64}' | column -t -R 2,3,4); return $?; } _zl() { _zfs "list $*"; } # General Aliases alias ssha="eval \"\$(ssh-agent)\"; ssh-add" # shellcheck disable=SC2139 alias aliases="\$EDITOR $thisfile ; exec zsh" alias vimrc="\$EDITOR \$VIMRC" alias zshrc="\$EDITOR \${ZDOTDIR:-\$HOME}/.zshrc ; exec zsh" alias gitrc="\$EDITOR \$XDG_CONFIG_HOME/git/config" alias xinitrc="\$EDITOR \$XDG_CONFIG_HOME/X11/xinitrc" alias xresources="\$EDITOR \$XDG_CONFIG_HOME/X11/xresources ; xrdb merge \$XDG_CONFIG_HOME/X11/xresources" alias sshc="\$EDITOR ~/.ssh/config" alias dotfiles="cd \$XDG_CONFIG_HOME" alias i3c="\$EDITOR \$XDG_CONFIG_HOME/i3/config; systemctl --user reload i3" alias polybarc="\$EDITOR \$XDG_CONFIG_HOME/polybar/config.ini; systemctl --user reload polybar@i3bar" alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'" # Networking aliases alias ipa="ip a" alias addrs="ip a | grep inet | grep -ve fe80 -e '127\\.0\\.0\\.1/8' -e '::1/128' | sort -n | sed 's/^\\s*//'" # alertmanager alias alert='amtool alert' alias silence='amtool silence' alias expire='amtool silence expire' unsilence() { { for inst in "$@"; do amtool silence query instance=$inst | grep -Po '^([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})' | tee /dev/stderr | xargs -r amtool silence expire & done; wait; } | cat } # vim: ft=sh