home: Add zsh
This imports my (historically evolved) functions. I have to clean them up sometime.
This commit is contained in:
parent
ff74abc107
commit
bb95194619
|
@ -93,10 +93,6 @@
|
|||
neovim-remote # controlling another neovim process
|
||||
universal-ctags # ctags
|
||||
|
||||
# direnv
|
||||
direnv # per-directory environment
|
||||
nix-direnv # per-directory environment for nix
|
||||
|
||||
# git
|
||||
gitAndTools.delta # nicer diff
|
||||
gitAndTools.git-annex
|
||||
|
@ -112,8 +108,4 @@
|
|||
bandwhich.enable = true;
|
||||
iotop.enable = true;
|
||||
};
|
||||
|
||||
environment.pathsToLink = [
|
||||
"/share/nix-direnv"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ in
|
|||
./modules/xcompose.nix
|
||||
./modules/xdg.nix
|
||||
./modules/zathura.nix
|
||||
./modules/zsh.nix
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
156
users/simon/files/zsh/docker.zsh
Normal file
156
users/simon/files/zsh/docker.zsh
Normal file
|
@ -0,0 +1,156 @@
|
|||
# Docker function definitions
|
||||
|
||||
function speedtest() {
|
||||
docker run --init --rm tianon/speedtest --accept-license --accept-gdpr -p $@
|
||||
}
|
||||
|
||||
function vobsub2srt() {
|
||||
docker run \
|
||||
--rm \
|
||||
-v $PWD:/data \
|
||||
-w /data \
|
||||
-u $(id -u) \
|
||||
sbruder/vobsub2srt \
|
||||
--blacklist '„“”|’/\`_~<>flfiff' \
|
||||
$@
|
||||
}
|
||||
|
||||
function aucdtect() {
|
||||
docker run \
|
||||
--rm \
|
||||
-v "$PWD:/home/aucdtect/:ro" \
|
||||
-e uid=$(id -u) \
|
||||
-e gid=$(id -g) \
|
||||
sbruder/aucdtect \
|
||||
$@
|
||||
}
|
||||
|
||||
function unrar () {
|
||||
docker run \
|
||||
-it \
|
||||
--rm \
|
||||
-v "$PWD:/data" \
|
||||
-w /data \
|
||||
-u $(id -u) \
|
||||
r.sbruder.de/unrar \
|
||||
$@
|
||||
}
|
||||
|
||||
function waifu2x() {
|
||||
docker run \
|
||||
--rm \
|
||||
--init \
|
||||
-it \
|
||||
-v "$PWD:/data" \
|
||||
-w /data \
|
||||
-v "$HOME/.waifu2x:/home/waifu2x/.waifu2x" \
|
||||
-e HOME=/home/waifu2x \
|
||||
-u $(id -u) \
|
||||
--group-add $(getent group video|cut -d: -f3) \
|
||||
--group-add $(getent group render|cut -d: -f3) \
|
||||
--device /dev/dri \
|
||||
r.sbruder.de/waifu2x-converter-cpp \
|
||||
$@
|
||||
}
|
||||
|
||||
function waifu2x-photo() {
|
||||
waifu2x --model-dir /usr/local/share/waifu2x-converter-cpp-photo $@
|
||||
}
|
||||
|
||||
function dive() {
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
wagoodman/dive \
|
||||
$@
|
||||
}
|
||||
|
||||
function vapoursynth() {
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-e WAYLAND_DISPLAY \
|
||||
-e QT_QPA_PLATFORM \
|
||||
-e XDG_RUNTIME_DIR \
|
||||
-u $(id -u) \
|
||||
-v ${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}:${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY} \
|
||||
-v "$HOME/.config/:/home/vapoursynth/.config/" \
|
||||
-v "$PWD:/data/" \
|
||||
-w /data/ \
|
||||
--group-add $(getent group video|cut -d: -f3) \
|
||||
--group-add $(getent group render|cut -d: -f3) \
|
||||
--device /dev/dri \
|
||||
--device /dev/kfd \
|
||||
r.sbruder.de/vapoursynth \
|
||||
$@
|
||||
}
|
||||
|
||||
function yuuno() {
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-u $(id -u) \
|
||||
-v "$PWD:/data/" \
|
||||
-w /data/ \
|
||||
-p 8087:8087 \
|
||||
--group-add $(getent group video|cut -d: -f3) \
|
||||
--group-add $(getent group render|cut -d: -f3) \
|
||||
--device /dev/dri \
|
||||
--device /dev/kfd \
|
||||
r.sbruder.de/vapoursynth \
|
||||
jupyter notebook --ip 0.0.0.0 --port 8087
|
||||
}
|
||||
|
||||
function aegisub() {
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
--device /dev/dri \
|
||||
--group-add $(getent group video|cut -d: -f3) \
|
||||
--group-add $(getent group video|cut -d: -f3) \
|
||||
-e DISPLAY \
|
||||
-e PULSE_COOKIE=/run/pulse/cookie \
|
||||
-e PULSE_SERVER=/run/user/$(id -u)/pulse/native \
|
||||
-u $(id -u) \
|
||||
-v $HOME/.aegisub/:/home/aegisub/.aegisub/ \
|
||||
-v $HOME/.config/pulse/cookie:/run/pulse/cookie \
|
||||
-v $HOME/.fonts/:/home/aegisub/.fonts/ \
|
||||
-v $PWD:/home/aegisub/data/ \
|
||||
-v /run/user/$(id -u)/pulse/native:/run/user/$(id -u)/pulse/native \
|
||||
-v /tmp/.X11-unix:/tmp/.X11-unix \
|
||||
r.sbruder.de/aegisub \
|
||||
$@
|
||||
}
|
||||
|
||||
function ctop {
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
--name=ctop \
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
|
||||
quay.io/vektorlab/ctop
|
||||
}
|
||||
|
||||
function gcloud {
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-e TERM=xterm-256color \
|
||||
-v $HOME/.config/gcloud/:/root/.config/gcloud/ \
|
||||
-v $HOME/.config/gcloud-ssh/:/root/.ssh/ \
|
||||
google/cloud-sdk \
|
||||
gcloud "$@"
|
||||
}
|
||||
|
||||
function netlify() {
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
--init \
|
||||
-v $HOME/.netlify:/home/node/.netlify \
|
||||
-v $PWD:/data/ \
|
||||
-w /data/ \
|
||||
r.sbruder.de/netlify-cli \
|
||||
"$@"
|
||||
}
|
151
users/simon/files/zsh/functions.zsh
Normal file
151
users/simon/files/zsh/functions.zsh
Normal file
|
@ -0,0 +1,151 @@
|
|||
# pass wrappers
|
||||
|
||||
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 $@
|
||||
)
|
||||
|
||||
# Helpers
|
||||
|
||||
## resync pulseaudio bluetooth connection
|
||||
function btsync() (
|
||||
card=$(pactl list cards short|grep -E -o "bluez_card.*[[:space:]]")
|
||||
pacmd set-card-profile $card off
|
||||
pacmd set-card-profile $card a2dp_sink
|
||||
)
|
||||
|
||||
## get field from pass entry
|
||||
function pass-field() {
|
||||
pass "$1"|grep "$2"|cut -d: -f2-|tr -d ' '
|
||||
}
|
||||
|
||||
## Helper to create nix-shell direnv
|
||||
function nixify() {
|
||||
if [ ! -e ./.envrc ]; then
|
||||
echo "use nix" > .envrc
|
||||
direnv allow
|
||||
fi
|
||||
if [[ ! -e shell.nix ]] && [[ ! -e default.nix ]]; then
|
||||
cat > shell.nix << EOF
|
||||
{ pkgs ? import <nixpkgs> {} }:
|
||||
|
||||
pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
];
|
||||
}
|
||||
EOF
|
||||
vim shell.nix
|
||||
fi
|
||||
}
|
||||
|
||||
## 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
|
||||
paplay ~/Documents/sound/ringtones/Bergentrückung.wav
|
||||
else
|
||||
echo "The sleep command failed. Please check the options." >&2
|
||||
return 3
|
||||
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))
|
||||
)
|
||||
|
||||
function urlencode() {
|
||||
python3 -c "import urllib.parse; print(urllib.parse.quote(open(0, 'rb').read()))"
|
||||
}
|
||||
|
||||
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() {
|
||||
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
|
||||
)
|
||||
|
||||
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
|
||||
)
|
|
@ -231,4 +231,6 @@ in
|
|||
xdg.configFile = {
|
||||
"nvim/UltiSnips".source = ../files/nvim/UltiSnips;
|
||||
};
|
||||
|
||||
home.sessionVariables.EDITOR = "nvim";
|
||||
}
|
||||
|
|
|
@ -217,15 +217,13 @@ in
|
|||
};
|
||||
|
||||
# Start on tty1
|
||||
home.file = {
|
||||
".zprofile".text = ''
|
||||
if [[ -z $WAYLAND_DISPLAY ]] && [[ $(tty) = /dev/tty1 ]] && command -v sway >/dev/null ; then
|
||||
systemctl --user start graphical-session.target
|
||||
export XDG_SESSION_TYPE="wayland"
|
||||
exec sway
|
||||
fi
|
||||
'';
|
||||
};
|
||||
programs.zsh.profileExtra = ''
|
||||
if [[ -z $WAYLAND_DISPLAY ]] && [[ $(tty) = /dev/tty1 ]] && command -v sway >/dev/null ; then
|
||||
systemctl --user start graphical-session.target
|
||||
export XDG_SESSION_TYPE="wayland"
|
||||
exec sway
|
||||
fi
|
||||
'';
|
||||
|
||||
home.packages = with pkgs; [
|
||||
alacritty # terminal
|
||||
|
|
62
users/simon/modules/zsh.nix
Normal file
62
users/simon/modules/zsh.nix
Normal file
|
@ -0,0 +1,62 @@
|
|||
{ pkgs, ... }:
|
||||
let
|
||||
dircolors-solarized = pkgs.fetchFromGitHub {
|
||||
owner = "seebi";
|
||||
repo = "dircolors-solarized";
|
||||
rev = "65d4d595ceca96166139862131a006fa3079e00a";
|
||||
sha256 = "1nl5rs24gi7zqg7nqsbf9fa94yggwzqf3n3imxgfywl8jny3cj1q";
|
||||
};
|
||||
in
|
||||
{
|
||||
programs = {
|
||||
fzf.enable = true;
|
||||
direnv = {
|
||||
enable = true;
|
||||
enableNixDirenvIntegration = true;
|
||||
};
|
||||
starship = {
|
||||
enable = true;
|
||||
settings = {
|
||||
add_newline = false;
|
||||
};
|
||||
};
|
||||
zsh = {
|
||||
enable = true;
|
||||
plugins = [
|
||||
{
|
||||
name = "zsh-nix-shell";
|
||||
file = "nix-shell.plugin.zsh";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "chisui";
|
||||
repo = "zsh-nix-shell";
|
||||
rev = "v0.1.0";
|
||||
sha256 = "0snhch9hfy83d4amkyxx33izvkhbwmindy0zjjk28hih1a9l2jmx";
|
||||
};
|
||||
}
|
||||
];
|
||||
shellAliases = {
|
||||
exa = "exa --git --binary";
|
||||
l = "exa -l";
|
||||
la = "exa -la";
|
||||
ll = "exa -l";
|
||||
ls = "exa";
|
||||
ipy = "ipython3";
|
||||
vim = "nvim";
|
||||
vimdiff = "nvim -d";
|
||||
userctl = "systemctl --user";
|
||||
};
|
||||
envExtra = ''
|
||||
export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on"
|
||||
'';
|
||||
initExtraBeforeCompInit = ''
|
||||
source ${pkgs.grml-zsh-config}/etc/zsh/zshrc
|
||||
'';
|
||||
initExtra = ''
|
||||
eval $(${pkgs.coreutils}/bin/dircolors -b ${dircolors-solarized}/dircolors.ansi-universal)
|
||||
|
||||
source ${../files/zsh/functions.zsh}
|
||||
source ${../files/zsh/docker.zsh}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue