dotfiles/home/.bash_aliases
2021-08-26 10:46:26 +02:00

120 lines
2.7 KiB
Bash

# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias lla='ll -A'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'
alias rm='rm -I'
alias mv='mv -i'
alias cp='cp -i'
alias psa='ps aux'
alias psag='ps aux | grep'
alias ka=killall
alias s=sudo
alias g=git
alias k=kubectl
alias a=ansible
alias c=code
alias e=$EDITOR
alias h=helm
alias d=docker
alias r=rancher
alias n="c ~/workspace/notes"
# Some shortcuts for me
function jumphost() {
DEST=$1
while read PATTERN JUMPHOST; do
echo $DEST | grep -q $PATTERN && echo $JUMPHOST
done <~/.ssh/jumphosts
}
function tunnel() {
IFS=: read DEST PORT <<<$1
PORT_LOCAL=${2:-$PORT}
HOP=${3:-$(jumphost $DEST)}
[ -z "$HOP" ] || [ -z "$PORT" ] || [ -z "$PORT_LOCAL" ] && \
{ echo "usage: $FUNCNAME destination:port [local_port [tunnel_host]]"; return 1; }
ssh $HOP -L $PORT_LOCAL:$DEST:$PORT -N -o ExitOnForwardFailure=yes -f
PID=$(ssh $HOP -O check 2>&1 | sed -re "s/.*\(pid=(.*)\)+/\1/")
echo "Destination: $DEST:$PORT"
echo "Tunnelhost: $HOP"
echo "Local port: $PORT_LOCAL"
echo "SSH Tunnel PID: $PID"
}
function rdp-tunnel() {
IFS=: read DEST PORT <<<$1
HOP=${2:-$(jumphost $DEST)}
PORT=${PORT:-3389}
PORT_LOCAL=$((RANDOM%100+42325))
[ -z "$DEST" ] || [ -z "$HOP" ] && \
{ echo "usage: $FUNCNAME destination[:port] [tunnel_host]"; return 1; }
tunnel $DEST:$PORT $PORT_LOCAL $HOP && rdp localhost:$PORT_LOCAL
}
function rdp() {
PORT=3389
IFS=: read DEST PORT <<<$1
[ -n "$DEST" ] || \
{ echo "usage: $FUNCNAME destination:port"; return 1; }
if [[ "$OSTYPE" == "darwin"* ]]; then
open rdp://full%20address=s:$DEST:$PORT
else
rdesktop -P -k de -a 32 -z $DEST:$PORT
fi
}
function aws() {
local PASS=$(pass providers/aws)
local AWS=$(which aws)
# Start original aws executable with short-lived keys
AWS_ACCESS_KEY_ID=$(sed -En 's/^Access-Key: (.*)/\1/p' <<< "$PASS") \
AWS_SECRET_ACCESS_KEY=$(sed -En 's/^Secret-Key: (.*)/\1/p' <<< "$PASS") \
$AWS $@
}
function restic() {
local RESTIC=$(which restic)
# Start original restic executable with short-lived keys
AWS_ACCESS_KEY_ID=restic \
AWS_SECRET_ACCESS_KEY=$(pass s3/minio-restic | head -n1) \
RESTIC_PASSWORD="$(pass restic/macbook | head -n1)" \
$RESTIC $@
}
function oath() {
ykman oath accounts code -s $1 | wl-copy
}
alias acs-pass='PASSWORD_STORE_DIR=~/workspace/rwth/acs/lab/passwords pass'
alias chaos-family-invite='kubectl --context=nulll --namespace=ssb exec svc/pub -- sbot invite.create 1 | jq -r . | pbcopy'
alias new-mac=$'openssl rand -hex 6 | sed \'s/\(..\)/\1:/g; s/.$//\' | xargs sudo ifconfig en0 ether'
if type xdg-open > /dev/null 2>&1; then
alias open=xdg-open
fi
alias chrome="chromium-browser --enable-features=UseOzonePlatform --ozone-platform=wayland"
. ~/.homesick/repos/dotfiles/z.sh