2020-08-11 14:59:45 +00:00
case "$(basename "$(readlink -f /proc/$$/exe)")" in
zsh) thisfile="$(readlink -f "${(%):-%N}")";;
bash) thisfile="$(readlink -f "${BASH_SOURCE[0]}")";;
2021-05-25 11:27:38 +00:00
*) thisfile="$(find /proc/$$/fd/ -print0 | xargs -0 -n1 -r readlink -f | grep aliases | head -n1)";;
2020-08-11 14:59:45 +00:00
esac
2018-11-20 15:35:05 +00:00
# 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
2016-03-31 02:03:55 +00:00
alias l=ll
2018-10-01 15:26:55 +00:00
alias ls='ls --color=auto'
2021-05-25 11:00:48 +00:00
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'
2018-03-14 02:09:24 +00:00
alias lsz='ls -lAFh --sort=size'
2016-04-01 12:55:26 +00:00
alias al=la # No, I don't need the Mono Assembly Linker
2016-03-31 02:03:55 +00:00
2021-05-25 11:00:48 +00:00
alias md='mkdir -p'
alias rd='rmdir -p'
2018-02-22 13:03:37 +00:00
alias -- -='cd -'
2021-05-25 11:01:14 +00:00
cdt() { cd "$(mktemp -d -t "${1:-tmp}.XXXXXXXX")"; }
2016-03-31 02:03:55 +00:00
alias svi=sudoedit
2018-07-30 08:30:03 +00:00
alias svim=sudoedit
2016-04-23 12:18:54 +00:00
# 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
2019-04-08 13:14:00 +00:00
alias sudo='sudo '
2016-04-30 13:18:38 +00:00
alias open=xdg-open
2016-03-31 02:03:55 +00:00
2016-04-30 13:18:38 +00:00
# Command rewrites
2022-03-21 21:35:00 +00:00
alias rm='rm -iv'
2016-03-31 18:21:23 +00:00
alias mv='mv -i'
2017-02-02 00:30:16 +00:00
alias cp='cp -ir'
2020-03-22 12:46:26 +00:00
alias scp='scp -r'
2016-07-27 08:36:47 +00:00
alias dd='dd status=progress'
2021-05-25 11:27:38 +00:00
alias wget='wget --hsts-file=$XDG_DATA_HOME/wget/hsts-file'
2018-03-31 20:55:23 +00:00
alias vi=vim
2022-10-23 23:17:44 +00:00
alias grip='grip --pass=$GRIP_API_KEY'
2018-03-29 10:36:43 +00:00
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'
2021-05-25 11:27:38 +00:00
alias alpine-sdk="docker run -ti --rm \
2017-11-10 12:42:23 +00:00
-e USER \
2021-05-25 11:27:38 +00:00
-e UID=\"\$(id -u)\" \
2017-11-10 12:42:23 +00:00
-e PWD \
2018-03-26 17:35:46 +00:00
-e HOME \
2021-05-25 11:27:38 +00:00
-w \$PWD \
-v \$PWD:\$PWD \
-v ~/.abuild:\$HOME/.abuild \
2018-07-30 08:31:18 +00:00
-v ~/.abuild/distfiles:/var/cache/distfiles \
2021-05-25 11:27:38 +00:00
frebib/alpine-sdk:edge"
2018-07-30 08:31:18 +00:00
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"'
2018-10-31 17:24:37 +00:00
alias calc="noglob bc -l <<<" # noglob allows * without quoting
2016-03-31 18:21:23 +00:00
2018-11-20 15:35:05 +00:00
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"
2018-10-31 17:26:36 +00:00
# Function aliases
2021-05-25 11:27:38 +00:00
env() { command env "$@" | stripansi | sort; }
mcd(){ mkdir -p -- "$@" && cd -- "$@"; }
randstr() { tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$1" | head -n 1; }
2018-10-31 17:26:36 +00:00
2016-04-01 12:37:15 +00:00
# System aliases
2020-03-21 21:27:43 +00:00
alias sc="systemctl"
alias ssc="sudo systemctl"
alias scu="systemctl --user"
2017-02-02 00:30:16 +00:00
alias j=journalctl
2016-04-01 12:37:15 +00:00
alias ps='ps aux'
2017-02-02 00:30:16 +00:00
alias catn='tail -n +1 --'
alias kl='killall -s 9'
2016-10-04 23:47:55 +00:00
alias chx='chmod +x'
2016-03-31 18:21:23 +00:00
2016-03-31 02:03:55 +00:00
# Git Aliases
2021-05-25 09:58:32 +00:00
alias git='TZ=UTC git'
2016-03-31 02:03:55 +00:00
alias g=git
2020-03-22 12:46:07 +00:00
alias ginit='git init'
2017-01-25 14:02:30 +00:00
alias gignore='$EDITOR .gitignore'
2018-04-11 16:42:42 +00:00
alias gitc='$EDITOR $XDG_CONFIG_HOME/git/config'
alias ggignore='$EDITOR $XDG_CONFIG_HOME/git/gitignore'
2016-03-31 02:03:55 +00:00
alias gcl="git clone --recursive"
alias gco="git checkout"
2022-05-18 10:46:05 +00:00
alias gcom="git checkout \"\$(git defbranch)\""
2016-03-31 02:03:55 +00:00
alias ga="git add"
2018-03-29 14:57:51 +00:00
alias gap="git add -p"
2018-11-20 15:07:07 +00:00
alias gau="git add -u"
alias gaN="git add -N"
2016-03-31 02:03:55 +00:00
alias gaa="ga -A"
2017-02-07 00:35:45 +00:00
alias grm="git rm"
2020-05-29 23:22:27 +00:00
alias gc="git commit -s"
2020-07-14 20:08:54 +00:00
alias gcm="git commit -s -em"
2021-05-25 11:27:38 +00:00
alias gca="git commit -s --amend --date=\"\$(date -R)\""
2020-05-29 23:22:27 +00:00
alias gcn="git commit -s --no-edit"
alias gcan="gca -s --no-edit"
alias gcam="gca -s -m"
2016-03-31 02:03:55 +00:00
alias gst="git status"
alias gm="git merge"
alias gma="git merge --abort"
2020-03-28 15:23:35 +00:00
2016-03-31 02:03:55 +00:00
alias grb="git rebase"
2021-04-29 10:30:35 +00:00
alias grbi="grb -i"
2016-03-31 02:03:55 +00:00
alias grba="grb --abort"
alias grbc="grb --continue"
2019-12-14 22:16:49 +00:00
alias grbsk="grb --skip"
alias grbsh="grb --show-current"
2022-05-18 10:46:05 +00:00
alias grbom="git rebase \"origin/\$(git defbranch)\""
2021-09-21 16:53:07 +00:00
gfrb() { remote="${1%/*}"; git fetch "$remote" && git rebase "$@"; }
gfrbi() { remote="${1%/*}"; git fetch "$remote" && git rebase -i "$@"; }
2016-03-31 02:03:55 +00:00
2021-01-24 11:30:19 +00:00
alias gam="git am"
alias gama="git am --abort"
alias gamc="git am --continue"
2022-03-04 11:32:27 +00:00
alias gamsk="git am --skip"
2021-01-24 11:30:19 +00:00
2020-03-28 15:23:35 +00:00
alias gcp="git cherry-pick"
2021-01-24 11:30:19 +00:00
alias gcpa="git cherry-pick --abort"
alias gcpc="git cherry-pick --continue"
2022-03-04 11:32:27 +00:00
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"
2020-03-28 15:23:35 +00:00
2016-03-31 02:03:55 +00:00
alias gf="git fetch"
alias gp="git push"
alias gpf="gp --force"
2017-03-21 05:13:29 +00:00
alias gpsu="git push --set-upstream"
2019-04-08 13:14:18 +00:00
alias gpoH="git push origin HEAD"
2022-05-18 10:46:05 +00:00
alias gpsuom="git push --set-upstream origin \"\$(git defbranch)\""
2017-11-15 23:21:27 +00:00
alias gpall="git remote | xargs -L1 git push"
2016-03-31 02:03:55 +00:00
alias gl="git pull --rebase"
2016-07-06 07:39:52 +00:00
alias glp="gl && gp"
2019-09-15 10:30:00 +00:00
alias gd="git diff --patch-with-stat"
2020-03-21 21:15:43 +00:00
alias gdni="gd --no-index"
2019-09-15 10:30:00 +00:00
alias gds="gd --staged"
2020-03-21 21:15:00 +00:00
alias gsh="git show --format=fuller --patch-with-stat"
2021-07-31 00:04:30 +00:00
alias glg="git log --color --format=fuller --stat --no-merges --graph"
alias glgp="git log --color --format=fuller --patch-with-stat --no-merges --graph"
2020-03-21 21:15:00 +00:00
alias glog="git log --color --oneline --decorate --graph"
2016-03-31 02:03:55 +00:00
2016-04-18 13:06:14 +00:00
alias grst="git reset"
2020-03-21 21:15:43 +00:00
alias gundo="git reset --keep @~1"
2016-03-31 02:03:55 +00:00
alias gclean="git clean"
alias gbr="git branch"
2021-07-31 00:06:05 +00:00
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))\""
2019-12-14 22:16:49 +00:00
alias gtg="git tag"
2020-03-21 21:15:43 +00:00
alias gbl="git blame"
2016-03-31 02:03:55 +00:00
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'
2018-02-22 13:03:37 +00:00
alias gstl='gsta list --stat --color'
2016-03-31 02:03:55 +00:00
alias gstp='gsta pop'
alias gstv="gsta show -p stash@{0}"
2016-06-21 23:23:19 +00:00
# Docker aliases
alias d=docker
2019-03-03 13:33:15 +00:00
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/'"
2019-09-10 09:19:18 +00:00
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"
2021-05-25 11:27:38 +00:00
daddrs() { docker inspect "${1:-bridge}" | jq '.[0].Containers | map(.Name + "\t" + .IPv4Address + "\t" + .IPv6Address)[]' -r | sort -V -k2,3 | column -t; }
2019-03-03 13:33:15 +00:00
alias din='docker inspect'
2016-06-21 23:23:19 +00:00
alias drm='docker rm'
alias drmi='docker rmi'
alias dim='docker images'
2017-05-14 21:25:18 +00:00
alias dbl='docker build --pull'
alias dbl.='docker build --pull .'
2016-06-21 23:23:19 +00:00
alias drun='docker run -ti'
2016-07-20 15:26:06 +00:00
alias dkl='docker kill'
2021-02-13 14:46:19 +00:00
alias drmf='docker rm -f'
2016-08-12 14:54:08 +00:00
alias dst='docker stop'
2017-01-18 17:04:20 +00:00
alias drst='docker restart'
alias dnet='docker network'
alias dvol='docker volume'
2021-10-10 09:25:50 +00:00
alias dc='docker compose'
2021-01-04 15:38:34 +00:00
alias dlg='docker logs --tail=1000 -f'
2018-05-29 00:22:23 +00:00
alias dalpine='docker run -ti --rm spritsail/alpine /bin/sh'
2017-05-22 17:20:46 +00:00
alias drm-stopped='docker container prune'
alias drmi-untag='docker image prune'
2017-08-27 15:36:11 +00:00
alias dprune='docker system prune -f'
2021-05-25 11:27:38 +00:00
dsh() { do_dsh 2 exec "$@"; return $?; }
_dsh() { __docker_complete_running_containers "$@"; }
drsh() { do_dsh 4 run --rm --entrypoint= "$@"; return $?; }
_drsh() { __docker_container_subcommand "$@"; }
2018-11-20 15:35:05 +00:00
do_dsh() {
local minargs=$1
2018-08-21 12:34:43 +00:00
shift
2021-05-25 11:27:38 +00:00
if [ $# -lt "$minargs" ]; then
# shellcheck disable=SC2154
2018-11-20 15:35:05 +00:00
echo "Usage: ${funcstack[2]} [user@]container [program [args]]" >&2
2017-07-15 12:32:22 +00:00
return 64
fi
2016-12-18 12:29:51 +00:00
local dowhat="$1"
2021-05-25 11:27:38 +00:00
local docker_args=("$dowhat" -ti)
2017-07-16 00:51:28 +00:00
shift
while [ "${1:0:1}" = '-' ]; do
2017-08-27 15:37:45 +00:00
if [ "${1:0:2}" != '--' ]; then
docker_args+=("$1")
shift
fi
2017-07-16 00:51:28 +00:00
docker_args+=("$1")
shift
done
2021-05-25 11:27:38 +00:00
local user
user="$(echo "$1" | cut -d@ -f1 -s)"
declare -a prog
prog=("${@:2:$#}")
2016-12-18 12:29:51 +00:00
if [ -z "$user" ]; then
2017-07-16 00:51:28 +00:00
host="$1"
2016-08-12 14:54:08 +00:00
else
2021-05-25 11:27:38 +00:00
host="$(cut -d@ -f2 -s <<< "$1")"
docker_args+=("--user=$user")
2016-08-12 14:54:08 +00:00
fi
2021-05-25 11:27:38 +00:00
if [ "$dowhat" = exec ] && [ -z "$(docker ps -q -f name="$host" <&-)" ]; then
2017-07-15 12:32:22 +00:00
echo "No such container $host" >&2
return 5
fi
2021-05-25 11:27:38 +00:00
if [ "$dowhat" = run ]; then
docker image pull "$host"
fi
2017-07-15 12:32:22 +00:00
2021-05-25 11:27:38 +00:00
if [ ${#prog[@]} = 0 ]; then
shell_args=("$dowhat")
2017-08-27 15:40:58 +00:00
if [ "$dowhat" = 'run' ]; then
2021-05-25 11:27:38 +00:00
shell_args+=(--rm --entrypoint=)
2017-08-27 15:40:58 +00:00
fi
2017-07-15 12:32:22 +00:00
for shell in bash sh; do
2021-05-25 11:27:38 +00:00
shell_path="$(set -o pipefail; docker "${shell_args[@]}" "$host" which "$shell" <&- | sed 's|[\r\n]||g')"
2018-08-21 12:34:43 +00:00
retval=$?
if [ $retval -eq 0 ]; then
2021-05-25 11:27:38 +00:00
prog=("$shell_path")
2017-07-15 12:32:22 +00:00
break
2018-08-21 12:34:43 +00:00
elif [ $retval -ge 125 ]; then
return
2017-07-15 12:32:22 +00:00
fi
done
2021-05-25 11:27:38 +00:00
if [ ${#prog[@]} = 0 ]; then
2017-07-15 12:32:22 +00:00
echo "Warning: No shell found in path.. trying /bin/sh" >&2
2021-05-25 11:27:38 +00:00
prog=(/bin/sh)
2017-07-15 12:32:22 +00:00
fi
fi
2021-05-25 11:27:38 +00:00
docker "${docker_args[@]}" "$host" "${prog[@]}"
2016-07-20 15:41:52 +00:00
}
2016-06-21 23:23:19 +00:00
2018-11-20 15:35:05 +00:00
alias dm='docker-machine'
2021-05-25 11:27:38 +00:00
dmc() { eval "$(docker-machine env "$1")"; }
2016-09-01 13:22:49 +00:00
# ZFS aliases
alias zfs='sudo zfs'
alias zpool='sudo zpool'
alias zp=zpool
2021-05-25 11:27:38 +00:00
zl() { (set -o pipefail; command zfs list "$@" | grep -Ev 'docker/[0-9a-f]{64}' | column -t -R 2,3,4); return $?; }
_zl() { _zfs "list $*"; }
2016-09-01 13:22:49 +00:00
2016-03-31 02:03:55 +00:00
# General Aliases
2021-05-25 11:27:38 +00:00
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"
2022-02-21 20:44:17 +00:00
alias polybarc="\$EDITOR \$XDG_CONFIG_HOME/polybar/config.ini; systemctl --user reload polybar@i3bar"
2018-10-31 21:51:52 +00:00
2017-10-03 10:49:23 +00:00
alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'"
2016-03-31 02:03:55 +00:00
2019-01-19 13:14:05 +00:00
# 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*//'"
2020-08-11 08:30:48 +00:00
# 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 }
2016-09-01 13:50:36 +00:00
# vim: ft=sh