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

Compare commits

..

5 Commits

Author SHA1 Message Date
6ceb993208
aliases: fix all shellcheck warnings
Most of these changes have no semantic bearing, but some of the warnings
specifically related to quoting fix some word-splitting and globbing
issues with certain scripts.

Signed-off-by: Joe Groocock <me@frebib.net>
2021-05-25 11:27:38 +00:00
4e505c23c6
aliases: replace cdt alias with function
This adds an optional argument to `cdt` to allow specifying the
temporary directory prefix instead of the default `tmp`. This also
shortens the random character string from 10 (GNU mktemp) to 8.

Signed-off-by: Joe Groocock <me@frebib.net>
2021-05-25 11:01:14 +00:00
92c8dbc019
aliases: consistently quote ls/directory aliases
Consistency is key.

Signed-off-by: Joe Groocock <me@frebib.net>
2021-05-25 11:00:48 +00:00
315f6b6b9a
aliases: remove unused global aliases
I used to use these occasionally, but now I increasingly find myself
typing the commands out in full. They really don't save much time at
all.

Signed-off-by: Joe Groocock <me@frebib.net>
2021-05-25 10:59:34 +00:00
c1903f5726
aliases: remove ssh pseudo-tty override
Sometimes SSH needs to be called without a pty as it breaks some
non-interactive workflows, such as `docker save | ssh .. docker load`.

Signed-off-by: Joe Groocock <me@frebib.net>
2021-05-25 09:59:40 +00:00

133
aliases
View File

@ -1,7 +1,7 @@
case "$(basename "$(readlink -f /proc/$$/exe)")" in case "$(basename "$(readlink -f /proc/$$/exe)")" in
zsh) thisfile="$(readlink -f "${(%):-%N}")";; zsh) thisfile="$(readlink -f "${(%):-%N}")";;
bash) thisfile="$(readlink -f "${BASH_SOURCE[0]}")";; bash) thisfile="$(readlink -f "${BASH_SOURCE[0]}")";;
*) thisfile="$(find /proc/$$/fd/ | xargs -n1 -r readlink -f | grep aliases | head -n1)";; *) thisfile="$(find /proc/$$/fd/ -print0 | xargs -0 -n1 -r readlink -f | grep aliases | head -n1)";;
esac esac
# Global aliases for ZSH # Global aliases for ZSH
@ -10,49 +10,32 @@ if alias -g 2>/dev/null; then
alias -g ....=../../.. alias -g ....=../../..
alias -g .....=../../../.. alias -g .....=../../../..
alias -g ......=../../../../.. alias -g ......=../../../../..
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 NO="1> /dev/null"
alias -g NE="2> /dev/null" alias -g NE="2> /dev/null"
alias -g NUL="&> /dev/null" alias -g NUL="&> /dev/null"
alias -g BG="&;disown" alias -g BG="&;disown"
alias -g COL="| column -t"
alias -g CLIP="| xclip -i -selection primary -f | xclip -i -selection clipboard"
fi fi
# File default aliases # File default aliases
if alias -s 2>/dev/null; then if alias -s 2>/dev/null; then
alias -s pdf="open" 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 jar="java -jar"
alias -s git="git clone --recursive" alias -s git="git clone --recursive"
fi fi
alias ..la="cd ..;la"
alias ..ll="cd..;ll"
alias ..l="..ll"
alias l=ll alias l=ll
alias ls='ls --color=auto' alias ls='ls --color=auto'
alias ll="ls -lFh --group-directories-first" alias ll='ls -lFh --group-directories-first'
alias la="ls -lAFh --group-directories-first" alias la='ls -lAFh --group-directories-first'
alias lt='ls -lAFh --sort=time' alias lt='ls -lFh --sort=time'
alias lat='ls -lAFh --sort=time'
alias lsz='ls -lAFh --sort=size' alias lsz='ls -lAFh --sort=size'
alias al=la # No, I don't need the Mono Assembly Linker alias al=la # No, I don't need the Mono Assembly Linker
alias md="mkdir -p" alias md='mkdir -p'
alias rd="rmdir -p" alias rd='rmdir -p'
alias -- -='cd -' alias -- -='cd -'
alias cdt='cd `mktemp -d`' cdt() { cd "$(mktemp -d "${1:-tmp}.XXXXXXXX")"; }
alias svi=sudoedit alias svi=sudoedit
alias svim=sudoedit alias svim=sudoedit
@ -68,22 +51,21 @@ alias mv='mv -i'
alias cp='cp -ir' alias cp='cp -ir'
alias scp='scp -r' alias scp='scp -r'
alias dd='dd status=progress' alias dd='dd status=progress'
alias ssh="ssh -tt" alias wget='wget --hsts-file=$XDG_DATA_HOME/wget/hsts-file'
alias wget="wget --hsts-file=$XDG_DATA_HOME/wget/hsts-file"
alias vi=vim alias vi=vim
alias grip='grip --user=frebib --pass=$GRIP_API_KEY' 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 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 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 \ alias alpine-sdk="docker run -ti --rm \
-e USER \ -e USER \
-e UID="$(id -u)" \ -e UID=\"\$(id -u)\" \
-e PWD \ -e PWD \
-e HOME \ -e HOME \
-w $PWD \ -w \$PWD \
-v $PWD:$PWD \ -v \$PWD:\$PWD \
-v ~/.abuild:$HOME/.abuild \ -v ~/.abuild:\$HOME/.abuild \
-v ~/.abuild/distfiles:/var/cache/distfiles \ -v ~/.abuild/distfiles:/var/cache/distfiles \
frebib/alpine-sdk:edge' frebib/alpine-sdk:edge"
alias abuild='alpine-sdk abuild' alias abuild='alpine-sdk abuild'
alias abuild-sign='alpine-sdk abuild-sign' alias abuild-sign='alpine-sdk abuild-sign'
alias apk='alpine-sdk apk' alias apk='alpine-sdk apk'
@ -107,9 +89,9 @@ vim --version 2>/dev/null | command grep -q +clientserver && \
alias vim="vim --servername vim -p" alias vim="vim --servername vim -p"
# Function aliases # Function aliases
env() { command env $@ | stripansi | sort; } env() { command env "$@" | stripansi | sort; }
mcd(){ mkdir -p -- $@ && cd -- $@; } mcd(){ mkdir -p -- "$@" && cd -- "$@"; }
randstr() { tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w $1 | head -n 1; } randstr() { tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$1" | head -n 1; }
# System aliases # System aliases
alias sc="systemctl" alias sc="systemctl"
@ -139,7 +121,7 @@ alias gaa="ga -A"
alias grm="git rm" alias grm="git rm"
alias gc="git commit -s" alias gc="git commit -s"
alias gcm="git commit -s -em" alias gcm="git commit -s -em"
alias gca="git commit -s --amend --date=\"$(date -R)\"" alias gca="git commit -s --amend --date=\"\$(date -R)\""
alias gcn="git commit -s --no-edit" alias gcn="git commit -s --no-edit"
alias gcan="gca -s --no-edit" alias gcan="gca -s --no-edit"
alias gcam="gca -s -m" alias gcam="gca -s -m"
@ -206,7 +188,7 @@ 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 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 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" 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; } 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 din='docker inspect'
alias drm='docker rm' alias drm='docker rm'
alias drmi='docker rmi' alias drmi='docker rmi'
@ -225,20 +207,21 @@ alias dalpine='docker run -ti --rm spritsail/alpine /bin/sh'
alias drm-stopped='docker container prune' alias drm-stopped='docker container prune'
alias drmi-untag='docker image prune' alias drmi-untag='docker image prune'
alias dprune='docker system prune -f' alias dprune='docker system prune -f'
dsh() { do_dsh 2 exec $@; return $?; } dsh() { do_dsh 2 exec "$@"; return $?; }
_dsh() { __docker_complete_running_containers $@; } _dsh() { __docker_complete_running_containers "$@"; }
drsh() { do_dsh 4 run --rm --entrypoint= $@; return $?; } drsh() { do_dsh 4 run --rm --entrypoint= "$@"; return $?; }
_drsh() { __docker_container_subcommand $@; } _drsh() { __docker_container_subcommand "$@"; }
do_dsh() { do_dsh() {
local minargs=$1 local minargs=$1
shift shift
if [ $# -lt $minargs ]; then if [ $# -lt "$minargs" ]; then
# shellcheck disable=SC2154
echo "Usage: ${funcstack[2]} [user@]container [program [args]]" >&2 echo "Usage: ${funcstack[2]} [user@]container [program [args]]" >&2
return 64 return 64
fi fi
local dowhat="$1" local dowhat="$1"
local docker_args=() local docker_args=("$dowhat" -ti)
shift shift
while [ "${1:0:1}" = '-' ]; do while [ "${1:0:1}" = '-' ]; do
@ -250,68 +233,74 @@ do_dsh() {
shift shift
done done
local user="$(echo "$1" | cut -d'@' -f1 -s)" local user
local prog="${@:2:$#}" user="$(echo "$1" | cut -d@ -f1 -s)"
local usercmd=""
declare -a prog
prog=("${@:2:$#}")
if [ -z "$user" ]; then if [ -z "$user" ]; then
host="$1" host="$1"
else else
host=`echo $1 | cut -d'@' -f2 -s` host="$(cut -d@ -f2 -s <<< "$1")"
usercmd="--user=$user" docker_args+=("--user=$user")
fi fi
if [ "$dowhat" = 'exec' -a -z "$(docker ps -q -f name="$host")" <&- ]; then if [ "$dowhat" = exec ] && [ -z "$(docker ps -q -f name="$host" <&-)" ]; then
echo "No such container $host" >&2 echo "No such container $host" >&2
return 5 return 5
fi fi
if [ "$dowhat" = run ]; then
docker image pull "$host"
fi
if [ -z "$prog" ]; then if [ ${#prog[@]} = 0 ]; then
shell_args=() shell_args=("$dowhat")
if [ "$dowhat" = 'run' ]; then if [ "$dowhat" = 'run' ]; then
shell_args=(--rm --entrypoint=) shell_args+=(--rm --entrypoint=)
fi fi
for shell in bash sh; do for shell in bash sh; do
shell_path="$(set -o pipefail; docker $dowhat ${shell_args[@]} "$host" which "$shell" <&- | sed 's|[\r\n]||g')" shell_path="$(set -o pipefail; docker "${shell_args[@]}" "$host" which "$shell" <&- | sed 's|[\r\n]||g')"
retval=$? retval=$?
if [ $retval -eq 0 ]; then if [ $retval -eq 0 ]; then
prog="$shell_path" prog=("$shell_path")
break break
elif [ $retval -ge 125 ]; then elif [ $retval -ge 125 ]; then
return return
fi fi
done done
if [ -z "$prog" ]; then if [ ${#prog[@]} = 0 ]; then
echo "Warning: No shell found in path.. trying /bin/sh" >&2 echo "Warning: No shell found in path.. trying /bin/sh" >&2
prog=/bin/sh prog=(/bin/sh)
fi fi
fi fi
docker $dowhat ${docker_args[@]} -ti $usercmd $host $(xargs <<< $prog) docker "${docker_args[@]}" "$host" "${prog[@]}"
} }
alias dc='docker-compose' alias dc='docker-compose'
alias dm='docker-machine' alias dm='docker-machine'
dmc() { eval $(docker-machine env $1); } dmc() { eval "$(docker-machine env "$1")"; }
# ZFS aliases # ZFS aliases
alias zfs='sudo zfs' alias zfs='sudo zfs'
alias zpool='sudo zpool' alias zpool='sudo zpool'
alias zp=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() { (set -o pipefail; command zfs list "$@" | grep -Ev 'docker/[0-9a-f]{64}' | column -t -R 2,3,4); return $?; }
_zl() { _zfs "list $@"; } _zl() { _zfs "list $*"; }
# General Aliases # General Aliases
alias ssha='eval `ssh-agent` ; ssh-add' alias ssha="eval \"\$(ssh-agent)\"; ssh-add"
alias aliases="$EDITOR $thisfile ; exec zsh" # shellcheck disable=SC2139
alias vimrc="$EDITOR $VIMRC" alias aliases="\$EDITOR $thisfile ; exec zsh"
alias zshrc="$EDITOR ${ZDOTDIR:-$HOME}/.zshrc ; exec zsh" alias vimrc="\$EDITOR \$VIMRC"
alias gitrc="$EDITOR $XDG_CONFIG_HOME/git/config" alias zshrc="\$EDITOR \${ZDOTDIR:-\$HOME}/.zshrc ; exec zsh"
alias xinitrc="$EDITOR $XDG_CONFIG_HOME/X11/xinitrc" alias gitrc="\$EDITOR \$XDG_CONFIG_HOME/git/config"
alias xresources="$EDITOR $XDG_CONFIG_HOME/X11/xresources ; xrdb merge $XDG_CONFIG_HOME/X11/xresources" alias xinitrc="\$EDITOR \$XDG_CONFIG_HOME/X11/xinitrc"
alias sshc="$EDITOR ~/.ssh/config" alias xresources="\$EDITOR \$XDG_CONFIG_HOME/X11/xresources ; xrdb merge \$XDG_CONFIG_HOME/X11/xresources"
alias dotfiles="cd $XDG_CONFIG_HOME" alias sshc="\$EDITOR ~/.ssh/config"
alias i3c="$EDITOR $XDG_CONFIG_HOME/i3/config; systemctl --user reload i3" alias dotfiles="cd \$XDG_CONFIG_HOME"
alias polybarc="$EDITOR $XDG_CONFIG_HOME/polybar/config; systemctl --user reload polybar@i3bar" alias i3c="\$EDITOR \$XDG_CONFIG_HOME/i3/config; systemctl --user reload i3"
alias polybarc="\$EDITOR \$XDG_CONFIG_HOME/polybar/config; systemctl --user reload polybar@i3bar"
alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'" alias rot13="tr '[A-Za-z]' '[N-ZA-Mn-za-m]'"