2018-03-14 14:36:23 +01:00
|
|
|
# Programming languages
|
|
|
|
|
|
|
|
## Go
|
2018-04-09 16:38:38 +02:00
|
|
|
export GOPATH="$HOME/go"
|
2019-02-11 15:07:15 +01:00
|
|
|
export PATH="$PATH:$GOPATH/bin"
|
2018-03-14 14:36:23 +01:00
|
|
|
|
|
|
|
## Python (pip)
|
2019-04-04 15:54:43 +02:00
|
|
|
export PATH="$HOME/.local/bin:$PATH"
|
2018-03-14 14:36:23 +01:00
|
|
|
|
2019-08-07 03:10:45 +02:00
|
|
|
## Rust (cargo)
|
|
|
|
export PATH="$HOME/.cargo/bin:$PATH"
|
|
|
|
|
2018-03-14 14:36:23 +01:00
|
|
|
# Misc
|
|
|
|
|
|
|
|
## Local binaries
|
2019-02-11 15:07:15 +01:00
|
|
|
export PATH="$HOME/bin:$PATH"
|
2018-03-14 14:36:23 +01:00
|
|
|
|
2020-08-18 15:58:54 +02:00
|
|
|
# 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
|
|
|
|
2018-10-28 13:16:17 +01:00
|
|
|
## Terminal font
|
2019-06-14 16:59:16 +02:00
|
|
|
function tfont() (
|
|
|
|
[ -z "$1" ] && font="Terminess Powerline" || font="$1"
|
|
|
|
[ -z "$2" ] && fontsize=18 || fontsize="$2"
|
|
|
|
echo -en "\033]710;xft:$font:pixelsize=$fontsize\007"
|
|
|
|
)
|
2018-10-28 13:16:17 +01:00
|
|
|
|
2019-02-08 14:22:15 +01:00
|
|
|
## resync pulseaudio bluetooth connection
|
2019-06-14 16:59:16 +02:00
|
|
|
function btsync() (
|
2019-06-14 17:15:58 +02:00
|
|
|
card=$(pactl list cards short|grep -E -o "bluez_card.*[[:space:]]")
|
2019-06-14 16:59:16 +02:00
|
|
|
pacmd set-card-profile $card off
|
2019-09-05 17:33:57 +02:00
|
|
|
pacmd set-card-profile $card a2dp_sink
|
2019-06-14 16:59:16 +02:00
|
|
|
)
|
2019-02-08 14:22:15 +01:00
|
|
|
|
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
|
|
|
|
2018-03-14 14:36:23 +01:00
|
|
|
## Color switcher
|
|
|
|
alias dynamic-colors="~/.dynamic-colors/bin/dynamic-colors"
|
|
|
|
|
2020-08-18 15:58:33 +02:00
|
|
|
## Support for nix-shell
|
|
|
|
source $HOME/.zsh/zsh-nix-shell/nix-shell.plugin.zsh
|
|
|
|
|
2020-08-18 16:38:34 +02:00
|
|
|
# Per-directory environment
|
|
|
|
command -v direnv >/dev/null && eval "$(direnv hook zsh)"
|
|
|
|
|
|
|
|
nixify() {
|
|
|
|
if [ ! -e ./.envrc ]; then
|
|
|
|
echo "use nix" > .envrc
|
|
|
|
direnv allow
|
|
|
|
fi
|
|
|
|
if [[ ! -e shell.nix ]] && [[ ! -e default.nix ]]; then
|
|
|
|
cat > default.nix << EOF
|
|
|
|
{ pkgs ? import <nixpkgs> {} }:
|
|
|
|
|
|
|
|
pkgs.mkShell {
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
|
|
];
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
${EDITOR:-vim} default.nix
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-06-04 20:32:36 +02:00
|
|
|
## Timer
|
2019-06-14 16:59:16 +02:00
|
|
|
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
|
2019-06-14 16:59:16 +02:00
|
|
|
else
|
|
|
|
echo "The sleep command failed. Please check the options." >&2
|
|
|
|
return 3
|
|
|
|
fi
|
|
|
|
)
|
2018-06-04 20:32:36 +02:00
|
|
|
|
2019-02-09 21:21:30 +01:00
|
|
|
## Wallpaper switcher
|
2019-06-14 16:59:16 +02:00
|
|
|
function wp() (
|
|
|
|
if [ -z "$1" ] || ([ "$1" = "rand" ] && [ -z "$2" ]); then
|
|
|
|
echo "USAGE: $0 rand|restore|default [path]"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [ "$1" = "default" ];then
|
|
|
|
feh --bg-fill /usr/share/wallpapers/wallpaper.jpg
|
|
|
|
fi
|
|
|
|
if [ "$1" = "rand" ]; then
|
2019-09-08 17:50:54 +02:00
|
|
|
base="$HOME/Pictures/wallpaper"
|
2019-06-14 16:59:16 +02:00
|
|
|
rand=$(shuf -n1 -e $base/$2/*)
|
|
|
|
[ -z "$rand" ] || feh --bg-fill "$rand"
|
|
|
|
fi
|
|
|
|
if [ "$1" = "restore" ]; then
|
|
|
|
~/.fehbg
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-06-22 19:27:53 +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
|
2020-01-12 22:32:15 +01:00
|
|
|
mv -n "$file" "$(dirname $file)/$(printf %0${digits}d $i).${file##*.}"
|
2019-06-22 19:27:53 +02:00
|
|
|
i=$((i+1))
|
|
|
|
done
|
|
|
|
)
|
|
|
|
|
2019-06-12 14:48:51 +02:00
|
|
|
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/")
|
2019-06-12 14:48:51 +02:00
|
|
|
}
|
|
|
|
|
2019-11-04 14:21:18 +01:00
|
|
|
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 -
|
|
|
|
}
|
|
|
|
|
2019-09-07 17:58:30 +02:00
|
|
|
function mullvad() (
|
|
|
|
if (( $# < 1 )); then
|
|
|
|
echo "USAGE: $0 LOCATION|off" >&2
|
|
|
|
fi
|
2019-11-02 16:55:32 +01:00
|
|
|
current_interfaces="$(ip -o a|grep -oE '[0-9]*:\ mullvad-(v6-)?[a-z][a-z][0-9]*'|uniq|cut -d: -f2|tr -d ' ')"
|
2019-09-07 17:58:30 +02:00
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2019-06-10 17:13:58 +02:00
|
|
|
# Audacious does not support symlinks; hack around that
|
2019-06-14 16:59:16 +02:00
|
|
|
function audacious-hack() (
|
2019-10-31 23:51:40 +01:00
|
|
|
audtool playlist-clear
|
2019-06-14 16:59:16 +02:00
|
|
|
IFS=$'\n'
|
2019-07-18 16:43:07 +02:00
|
|
|
for dir in $@; do
|
|
|
|
/bin/ls -1 $dir/**/*.(flac|m4a|mp3|ogg|opus)(@)
|
2019-10-31 23:51:40 +01:00
|
|
|
done|sort -Vd|tr '\n' '\0'|xargs -0 -- audacious --enqueue
|
|
|
|
audacious --play
|
2019-06-14 16:59:16 +02:00
|
|
|
)
|
2019-06-10 17:13:58 +02:00
|
|
|
|
2018-03-14 14:36:23 +01:00
|
|
|
# Program aliases/env
|
|
|
|
|
|
|
|
## Aliases for programs
|
2018-04-30 19:53:42 +02:00
|
|
|
if which exa 2>&1 >> /dev/null;then
|
2020-07-04 22:31:10 +02:00
|
|
|
alias exa="exa --git --binary"
|
|
|
|
alias ls="exa"
|
2018-04-30 19:53:42 +02:00
|
|
|
fi
|
2018-06-21 13:54:22 +02:00
|
|
|
alias ipy="ipython3"
|
2019-03-21 23:13:55 +01:00
|
|
|
|
2020-05-17 15:39:31 +02:00
|
|
|
alias vim="nvim"
|
|
|
|
alias vimdiff="nvim -d"
|
|
|
|
export EDITOR=nvim
|
|
|
|
|
2020-06-19 19:26:12 +02:00
|
|
|
# Debian packages fd this as fdfind
|
|
|
|
alias fd="fdfind"
|
|
|
|
|
2018-03-14 14:36:23 +01:00
|
|
|
## Environment variables
|
2019-09-08 17:50:54 +02:00
|
|
|
export HVSC_BASE="$HOME/Documents/sound/HVSC/"
|
2019-06-14 17:15:58 +02:00
|
|
|
export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on" # force antialiasing in java
|
2018-03-28 01:24:21 +02:00
|
|
|
|
|
|
|
## include docker functions
|
|
|
|
source ~/.zshrc.docker
|
|
|
|
|
2018-03-28 17:25:59 +02:00
|
|
|
## drone ci
|
2018-05-18 21:42:42 +02:00
|
|
|
function drone-add-hub() {
|
2020-07-04 22:31:10 +02:00
|
|
|
drone secret add --name docker_username --data sbruder "$1"
|
|
|
|
drone secret add --name docker_password --data "$(pass devops/docker|head -n 1)" "$1"
|
2018-03-28 22:59:19 +02:00
|
|
|
}
|
|
|
|
|
2018-05-18 21:42:42 +02:00
|
|
|
function drone-add-registry() {
|
2020-07-04 22:31:10 +02:00
|
|
|
drone secret add --name docker_username --data simon "$1"
|
|
|
|
drone secret add --name docker_password --data "$(pass sbruder.de/account|head -n 1)" "$1"
|
2018-05-18 21:42:42 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 19:38:37 +02:00
|
|
|
function drone-add-netlify() {
|
2020-08-18 17:20:39 +02:00
|
|
|
drone secret add --name netlify_auth_token --data "$(pass-field web/netlify.com Drone-Key)" "$1"
|
2018-04-30 19:38:37 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 15:40:09 +02:00
|
|
|
function drone-add-s3() {
|
2020-07-04 22:31:10 +02:00
|
|
|
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"
|
2018-05-11 15:40:09 +02:00
|
|
|
}
|
|
|
|
|
2019-06-14 16:59:16 +02:00
|
|
|
function drone() (
|
2019-06-15 13:42:56 +02:00
|
|
|
export DRONE_SERVER="$(pass-field sbruder.de/drone Server)"
|
|
|
|
export DRONE_TOKEN="$(pass sbruder.de/drone|head -n 1)"
|
2020-07-04 22:31:10 +02:00
|
|
|
~/bin/drone $@
|
2019-06-14 16:59:16 +02:00
|
|
|
)
|
2018-05-18 21:42:42 +02:00
|
|
|
|
2019-06-14 17:15:58 +02:00
|
|
|
function docker-ls() (
|
2020-07-04 22:31:10 +02:00
|
|
|
export DOCKER_LS_PASSWORD="$(pass sbruder.de/account|head -n 1)"
|
2019-06-14 17:15:58 +02:00
|
|
|
~/bin/docker-ls $@
|
|
|
|
)
|
2018-05-18 21:42:42 +02:00
|
|
|
|
2019-06-14 17:15:58 +02:00
|
|
|
function docker-rm() (
|
2020-07-04 22:31:10 +02:00
|
|
|
export DOCKER_LS_PASSWORD="$(pass sbruder.de/account|head -n 1)"
|
2019-06-14 17:15:58 +02:00
|
|
|
~/bin/docker-rm $@
|
|
|
|
)
|
2019-06-14 16:53:16 +02:00
|
|
|
|
|
|
|
## lexicon
|
2019-06-14 16:59:16 +02:00
|
|
|
function lecicon() (
|
2019-06-14 17:15:58 +02:00
|
|
|
export LEXICON_HENET_USERNAME="$(pass-field management/he User)"
|
|
|
|
export LEXICON_HENET_PASSWORD="$(pass management/he|head -n 1)"
|
2019-06-14 16:53:16 +02:00
|
|
|
lexicon $@
|
2019-06-14 16:59:16 +02:00
|
|
|
)
|
2019-12-25 13:03:34 +01:00
|
|
|
|
|
|
|
# Completion
|
2020-04-15 00:59:46 +02:00
|
|
|
autoload -U bashcompinit
|
|
|
|
bashcompinit
|
2019-12-25 13:03:34 +01:00
|
|
|
|
|
|
|
## hcloud
|
2019-12-29 15:31:09 +01:00
|
|
|
command -v hcloud >/dev/null && source <(hcloud completion zsh)
|
2020-04-15 00:59:46 +02:00
|
|
|
|
2020-04-15 00:59:58 +02:00
|
|
|
## poetry
|
|
|
|
command -v poetry >/dev/null && ([ -e ~/.zfunc/_poetry ] || poetry completions zsh > ~/.zfunc/_poetry)
|
2020-06-01 00:46:27 +02:00
|
|
|
|
|
|
|
## rustup/cargo
|
|
|
|
command -v rustup >/dev/null && ([ -e ~/.zfunc/_cargo ] || rustup completions zsh cargo > ~/.zfunc/_cargo) && ([ -e ~/.zfunc/_rustup ] || rustup completions zsh rustup> ~/.zfunc/_rustup)
|