1
0
mirror of https://github.com/frebib/dotfiles.git synced 2024-06-14 12:57:23 +00:00
dotfiles/aliases

288 lines
8.1 KiB
Bash

# Common Aliases
alias -g ...=../..
alias -g ....=../../..
alias -g .....=../../../..
alias -g ......=../../../../..
alias ..la="cd ..;la"
alias ..ll="cd..;ll"
alias ..l="..ll"
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 -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"
mcd(){ mkdir -p -- $@ && cd -- $@; }
alias -- -='cd -'
alias cdt='cd `mktemp -d`'
alias grep='grep --color'
alias -g H='| head'
alias -g T='| tail'
alias -g G='| grep'
alias -g L="| less"
alias -g C="| wc -l"
alias -g S="| sort"
alias -g U="| uniq"
alias -g count="| wc -l"
alias -g NO="1> /dev/null"
alias -g NE="2> /dev/null"
alias -g NUL="&> /dev/null"
alias -g BG="&;disown"
alias -g COL="| column -t"
alias -g CLIP="| xclip -i -selection primary -f | xclip -i -selection clipboard"
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 -E '
alias open=xdg-open
# Command rewrites
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -ir'
alias pacman='pacman --color=always'
alias pacaur='pacaur --color=always'
alias tree='tree --dirsfirst -C -F'
alias make="make -j$(nproc)"
alias dd='dd status=progress'
alias ssh="ssh -tt"
alias wget="wget --hsts-file=$XDG_DATA_HOME/wget/hsts-file"
vim --version 2>/dev/null | command grep -q +clientserver && \
alias vim="vim --servername vim -p"
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'
exists gopass && alias pass='gopass'
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
# Function aliases
env() { command env $@ | stripansi | sort; }
# System aliases
alias s="sudo systemctl"
alias j=journalctl
exists pacman && alias p=yay
alias ps='ps aux'
alias catn='tail -n +1 --'
alias kl='killall -s 9'
alias chx='chmod +x'
# File default aliases
alias -s pdf="open"
alias -s zip="unzip -l"
alias -s rar="unrar l"
alias -s tar="tar tf"
alias -s gz="tar tf"
alias -s jar="java -jar"
alias -s git="git clone --recursive"
# Git Aliases
alias g=git
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 master"
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 gc="git commit"
alias gcm="gc -m"
gcmst() { git stash -u -k && git commit -m "$1" && git stash pop; }
alias gca="git commit --amend"
alias gcn="git commit --no-edit"
alias gcan="git commit --amend --no-edit"
alias gcam="git commit --amend -m"
alias gst="git status"
alias gm="git merge"
alias gma="git merge --abort"
alias grb="git rebase"
alias grba="grb --abort"
alias grbc="grb --continue"
alias gf="git fetch"
alias gp="git push"
alias gpf="gp --force"
alias gpsu="git push --set-upstream"
alias gpsuom="git push --set-upstream origin master"
alias gpall="git remote | xargs -L1 git push"
alias gl="git pull --rebase"
alias glp="gl && gp"
gd() {
local commit=$1
if [ -z "$commit" ] || [ ${commit:0:1} != '@' ]; then
git diff $@
else
git diff "@~${commit:1}^!"
fi
}
alias gds="git diff --staged"
alias gsh="git show"
alias glg="git log --stat --color"
alias glog="git log --oneline --decorate --color --graph"
alias grst="git reset"
alias gundo="git reset @~1"
alias gclean="git clean"
alias gbr="git branch"
alias gr="git remote"
alias grv="git remote -v"
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'
alias dpsa='docker ps -a'
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'
dklrm() { docker kill $@ ; docker rm $@ }
alias dst='docker stop'
alias drst='docker restart'
alias dnet='docker network'
alias dvol='docker volume'
alias dlg='docker logs -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'
alias dsh='_CMD=dsh _dsh 2 exec'
alias drsh='_CMD=drsh _dsh 4 run --rm --entrypoint='
_dsh() {
minargs=$1
shift
if [ $# -lt $minargs ]; then
echo "Usage: ${_CMD:-$0} [user@]container [program [args]]" >&2
return 64
fi
local dowhat="$1"
local docker_args=()
shift
while [ "${1:0:1}" = '-' ]; do
if [ "${1:0:2}" != '--' ]; then
docker_args+=("$1")
shift
fi
docker_args+=("$1")
shift
done
local user="$(echo "$1" | cut -d'@' -f1 -s)"
local prog="${@:2:$#}"
local usercmd=""
if [ -z "$user" ]; then
host="$1"
else
host=`echo $1 | cut -d'@' -f2 -s`
usercmd="--user=$user"
fi
if [ "$dowhat" = 'exec' -a -z "$(docker ps -q -f name="$host")" <&- ]; then
echo "No such container $host" >&2
return 5
fi
if [ -z "$prog" ]; then
shell_args=()
if [ "$dowhat" = 'run' ]; then
shell_args=(--rm --entrypoint=)
fi
for shell in bash sh; do
shell_path="$(set -o pipefail; docker $dowhat ${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 [ -z "$prog" ]; then
echo "Warning: No shell found in path.. trying /bin/sh" >&2
prog=/bin/sh
fi
fi
docker $dowhat ${docker_args[@]} -ti $usercmd $host $(xargs <<< $prog)
}
alias dm='docker-machine'
dm-con() { eval $(docker-machine env $1); }
alias dmc=dm-con
alias dc='docker-compose'
# ZFS aliases
alias zfs='sudo zfs'
alias zpool='sudo zpool'
alias z=zfs
alias zp=zpool
zl() { (set -o pipefail; command zfs list $@ | grep -Ev 'docker/[0-9a-f]{64}'); return $?; }
_zl() { _zfs "list $@" }
# General Aliases
alias ssha='eval `ssh-agent` ; ssh-add'
alias aliases="$EDITOR $DOTFILES/aliases ; 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 $DOTFILES"
alias i3c="$EDITOR $XDG_CONFIG_HOME/i3/config ; i3-msg restart"
alias i3bc="$EDITOR $XDG_CONFIG_HOME/i3/blocks/config ; i3-msg restart"
i3b() { $EDITOR $XDG_CONFIG_HOME/i3/blocks/$@; }
alias sf=screenfetch
alias nf=neofetch
randstr() { tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w $1 | head -n 1; }
alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'"
# vim: ft=sh