This repository has been archived on 2021-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/home/.zshrc.local

192 lines
5 KiB
Plaintext
Raw Normal View History

2020-08-19 23:10:57 +02:00
# Program aliases/env
## Aliases for programs
2020-08-20 00:20:17 +02:00
if command -v exa >/dev/null; then
2020-08-19 23:10:57 +02:00
alias exa="exa --git --binary"
2020-08-20 00:20:17 +02:00
alias l="exa -l"
alias la="exa -la"
alias ll="exa -l"
2020-08-19 23:10:57 +02:00
alias ls="exa"
fi
alias ipy="ipython3"
alias vim="nvim"
alias vimdiff="nvim -d"
2020-08-21 09:39:45 +02:00
alias userctl="systemctl --user"
2020-08-19 23:10:57 +02:00
2020-10-09 17:02:39 +02:00
## homeshick
source "$HOME/.homesick/repos/homeshick/homeshick.sh"
fpath=($HOME/.homesick/repos/homeshick/completions $fpath)
2020-08-20 00:20:17 +02:00
## Debian packages fd as fdfind
2020-08-19 23:10:57 +02:00
command -v fdfind >/dev/null && alias fd="fdfind"
## include docker functions
source ~/.zshrc.docker
## drone ci
function drone-add-hub() {
drone secret add --name docker_username --data sbruder "$1"
drone secret add --name docker_password --data "$(pass devops/docker|head -n 1)" "$1"
}
function drone-add-registry() {
drone secret add --name docker_username --data simon "$1"
drone secret add --name docker_password --data "$(pass sbruder.de/account|head -n 1)" "$1"
}
function drone-add-netlify() {
drone secret add --name netlify_auth_token --data "$(pass-field web/netlify.com Drone-Key)" "$1"
}
function drone-add-s3() {
drone secret add --name aws_access_key_id --data "$(pass-field sbruder.de/minio/personal User)" "$1"
drone secret add --name aws_secret_access_key --data "$(pass sbruder.de/minio/personal|head -n 1)" "$1"
}
function drone() (
export DRONE_SERVER="$(pass-field sbruder.de/drone Server)"
export DRONE_TOKEN="$(pass sbruder.de/drone|head -n 1)"
command drone $@
)
function docker-ls() (
export DOCKER_LS_PASSWORD="$(pass sbruder.de/account|head -n 1)"
command docker-ls $@
)
function docker-rm() (
export DOCKER_LS_PASSWORD="$(pass sbruder.de/account|head -n 1)"
command docker-rm $@
)
# Prompt
command -v starship >/dev/null && eval $(starship init zsh)
2019-06-14 17:15:58 +02:00
# Helpers
2018-03-14 14:36:23 +01:00
## resync pulseaudio bluetooth connection
function btsync() (
2019-06-14 17:15:58 +02:00
card=$(pactl list cards short|grep -E -o "bluez_card.*[[:space:]]")
pacmd set-card-profile $card off
pacmd set-card-profile $card a2dp_sink
)
2019-06-14 17:15:58 +02:00
## get field from pass entry
function pass-field() {
pass "$1"|grep "$2"|cut -d: -f2-|tr -d ' '
}
2018-03-14 14:36:23 +01:00
## dircolors
eval "$(dircolors -b $HOME/.dircolors)"
2018-10-28 13:34:37 +01:00
## fzf
2018-12-10 23:10:06 +01:00
[ -e /usr/share/doc/fzf/examples/key-bindings.zsh ] && source /usr/share/doc/fzf/examples/key-bindings.zsh
2020-08-18 14:43:19 +02:00
command -v fzf-share >/dev/null && source $(fzf-share)/key-bindings.zsh
2018-10-28 13:34:37 +01:00
2020-08-18 15:58:33 +02:00
## Support for nix-shell
source $HOME/.zsh/zsh-nix-shell/nix-shell.plugin.zsh
2020-08-20 00:20:17 +02:00
## Per-directory environment
2020-08-18 16:38:34 +02:00
command -v direnv >/dev/null && eval "$(direnv hook zsh)"
2020-08-20 00:20:17 +02:00
## Helper to create nix-shell direnv
function nixify() {
2020-08-18 16:38:34 +02:00
if [ ! -e ./.envrc ]; then
echo "use nix" > .envrc
direnv allow
fi
if [[ ! -e shell.nix ]] && [[ ! -e default.nix ]]; then
cat > shell.nix << EOF
2020-08-18 16:38:34 +02:00
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
2020-10-10 22:01:16 +02:00
buildInputs = with pkgs; [
2020-08-18 16:38:34 +02:00
];
}
EOF
vim shell.nix
2020-08-18 16:38:34 +02:00
fi
}
2018-06-04 20:32:36 +02:00
## Timer
function timer() (
if [ -z "$1" ] || [ -z "$2" ]; then
echo "USAGE: $0 [u|f] TIME/DURATION" >&2
return 1
fi
if [ "$1" != "u" ] && [ "$1" != "f" ]; then
echo "Invalid mode “$1” supplied. Valid modes are: u|f" >&2
return 2
fi
[ "$1" = "u" ] && mode="until"
[ "$1" = "f" ] && mode="for"
gosleep --${mode} "$2"
if [ "$?" = 0 ]; then
echo "Press CTRL-C to stop the alarm…" >&2
echo -en "\a" # highlight window
2019-09-08 17:50:54 +02:00
paplay ~/Documents/sound/ringtones/Bergentrückung.wav
else
echo "The sleep command failed. Please check the options." >&2
return 3
fi
)
2018-06-04 20:32:36 +02:00
function currency() (
amount=${1:-1}
fromcurrency=${2:-USD}
tocurrency=${3:-EUR}
rate=$(curl -s "https://api.exchangeratesapi.io/latest?base=$fromcurrency&symbols=$tocurrency"|jq ".rates.$tocurrency")
printf "$amount $fromcurrency: %.02f $tocurrency\n" $(($amount * $rate))
)
2019-05-27 21:34:50 +02:00
2019-06-01 13:00:48 +02:00
function urlencode() {
2019-06-14 17:15:58 +02:00
python3 -c "import urllib.parse; print(urllib.parse.quote(open(0, 'rb').read()))"
2019-06-01 13:00:48 +02:00
}
function renumber() (
if (( $# < 2 )); then
echo "USAGE: $0 DIGITS FILES"
return 1
fi
digits=$1
shift 1
i=1
for file in $@; do
mv -n "$file" "$(dirname $file)/$(printf %0${digits}d $i).${file##*.}"
i=$((i+1))
done
)
function mkvextract-all-attachments() {
2019-06-14 17:15:58 +02:00
mkvextract $1 attachments $(mkvmerge --identify $1|grep "Attachment ID"|sed "s/Attachment ID \([0-9]*\): .*/\1/")
}
function mkvpropedit-add-attachments() (
file="$1"
shift
for attachment in $@; do
mkvpropedit --attachment-mime-type font/sfnt --add-attachment "$attachment" "$file"
done
)
2019-08-10 18:48:21 +02:00
function ssim() {
ffmpeg -loglevel fatal -i "$1" -i "$2" -lavfi 'ssim=/dev/stdout' -f null -
}
function mullvad() (
if (( $# < 1 )); then
echo "USAGE: $0 LOCATION|off" >&2
fi
current_interfaces="$(ip -o a|grep -oE '[0-9]*:\ mullvad-(v6-)?[a-z][a-z][0-9]*'|uniq|cut -d: -f2|tr -d ' ')"
for current_interface in $current_interfaces; do
sudo wg-quick down "$current_interface"
done
if [ "$1" != "off" ]; then
sudo wg-quick up mullvad-$1
fi
)