Reorganize zsh config

This commit is contained in:
Felix Bargfeldt 2023-07-28 16:10:32 +02:00
parent 54ded64bdf
commit fc7c73c697
Signed by: Defelo
GPG key ID: 2A05272471204DD3
14 changed files with 185 additions and 179 deletions

1
.gitattributes vendored
View file

@ -1 +1,2 @@
**/secrets/** diff=sopsdiffer
/home/zsh/p10k.zsh linguist-vendored

View file

@ -8,7 +8,7 @@ let
./helix
./nix-index.nix
./tmux.nix
./zsh.nix
./zsh
];
in {
user =
@ -39,6 +39,7 @@ in {
./waybar.nix
./xournalpp.nix
./yubikey.nix
./zsh/full.nix
];
root = common;

View file

@ -8,7 +8,7 @@
Install.WantedBy = ["default.target"];
Unit.After = ["sops-nix.service" "dunst.service"];
Service = {
ExecStart = "${pkgs.bash}/bin/bash ${../scripts/ntfy-sub.sh} ${config.sops.secrets.ntfy.path}";
ExecStart = "${pkgs.bash}/bin/bash ${./scripts/ntfy-sub.sh} ${config.sops.secrets.ntfy.path}";
Environment = "PATH=${pkgs.lib.makeBinPath (with pkgs; [coreutils jq dunst xdg-utils ntfy-sh])}";
};
};

View file

@ -146,7 +146,7 @@ in {
cmd = pkgs.writeShellScript "rofipass-wrapped.sh" ''
export PASSWORD_STORE_DIR=${pkgs.lib.escapeShellArg config.programs.password-store.settings.PASSWORD_STORE_DIR}
export PATH=${pkgs.lib.escapeShellArg (pkgs.lib.makeBinPath (with pkgs; [pass wl-clipboard rofi-wayland dunst clipman]))}:$PATH
exec -a rofipass.sh ${../scripts/rofipass.sh} "$@"
exec -a rofipass.sh ${./scripts/rofipass.sh} "$@"
'';
in "exec ${cmd}";
"${mod}+P" = "exec ${alacritty} -e python";

View file

@ -1,176 +0,0 @@
{
pkgs,
_pkgs,
...
}: {
programs.zsh = {
enable = true;
enableAutosuggestions = true;
syntaxHighlighting.enable = true;
defaultKeymap = "viins";
autocd = true;
history.share = false;
initExtra = ''
# p10k instant prompt
P10K_INSTANT_PROMPT="$XDG_CACHE_HOME/p10k-instant-prompt-''${(%):-%n}.zsh"
[[ ! -r "$P10K_INSTANT_PROMPT" ]] || source "$P10K_INSTANT_PROMPT"
source ${../p10k.zsh}
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
bindkey '^ ' autosuggest-accept
zstyle ':completion:*' menu select
setopt autopushd
d() { dirs -v | tac }
mkcd() { mkdir -p "$1"; cd "$1" }
temp() { (d=$(mktemp -d); cd "$d"; zsh && rm -rf "$d") }
deltemp() {
d=$(pwd)
[[ $(echo $d | cut -d/ -f2) != "tmp" ]] && return
cd
rm -rf /tmp/$(echo $d | cut -d/ -f3)
}
clip() { xclip -selection clipboard }
skg() {
f=$(mktemp -u)
ssh-keygen -t ed25519 -C "" -P "" -f $f
cat $f
cat $f.pub
rm $f $f.pub
}
wgpeer() {
key=$(wg genkey)
echo "# Private Key: $key\n[Peer]\nPublicKey = $(wg pubkey <<< $key)\nPresharedKey = $(wg genpsk)\nAllowedIPs = "
}
_rebuild() {
sudo nixos-rebuild "''${1:-switch}" --flake ~/nixos
}
_update() {
nix flake update --commit-lock-file ~/nixos && _rebuild
}
t() {
p="$1"
if [[ "$1" = "sudo" ]]; then p="$2"; fi
if [[ "$1" = "-p" ]]; then
p="$2"
shift 2
fi
NIXPKGS_ALLOW_UNFREE=1 nix shell --impure "nixpkgs#$p" -c "$@"
}
shot() {
file=$(mktemp --suffix .png)
${_pkgs.termshot}/bin/termshot -f $file $TERMSHOT_FLAGS -- "$@" \
&& ${pkgs.imagemagick}/bin/convert $file -crop 0x0+81+191 -crop -113-140 $file \
&& ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png -i $file \
&& ${pkgs.gnome.eog}/bin/eog $file
}
cshot() { TERMSHOT_FLAGS="-c" shot "$@"; }
jupyter_export(){
base=$(basename "$1" .ipynb)
jupyter nbconvert "$1" --to pdf --output "''${base}.pdf"
}
latex() {
dir=$(mktemp -d)
pdflatex -output-directory="$dir" "$1" || return $?
pdflatex -output-directory="$dir" "$1" || return $?
mv "$dir"/*.pdf .
rm -rf "$dir"
}
latex_preview() {
dir=$(mktemp -d)
pdflatex -output-directory="$dir" "$1" || return $?
(
${pkgs.inotify-tools}/bin/inotifywait -m -e modify "$1" | \
while read; do
pdflatex -halt-on-error -output-directory="$dir" "$1"
done
) &
pid=$!
${pkgs.okular}/bin/okular "$dir"/*.pdf
kill $pid
rm -rf "$dir"
}
conf() {
tmux new -d -s nixos -c ~/nixos hx flake.nix && tmux split -h -t nixos -c ~/nixos -d -l '50%'
if [[ -n "$TMUX" ]]; then
tmux switch-client -t nixos
else
tmux a -t nixos
fi
}
s() {
tmux new -d -c ~ -s "$1"
if [[ -n "$TMUX" ]]; then
tmux switch-client -t "$1"
else
tmux a -t "$1"
fi
}
mitm() {
${pkgs.mitmproxy}/bin/mitmweb -q &
pid=$!
${pkgs.proxychains}/bin/proxychains4 -f ${builtins.toFile "proxychains.conf" "quiet_mode\n[ProxyList]\nhttp 127.0.0.1 8080"} zsh
kill $pid
}
'';
plugins = [
{
name = "powerlevel10k";
src = pkgs.zsh-powerlevel10k;
file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
}
];
shellAliases = {
"." = "source";
ls = "${_pkgs.exa}/bin/exa -g --git --group-directories-first";
l = "ls -aal";
tre = "ls -alT";
c = "clear";
h = "cd;c";
grep = "grep --color=auto";
f = "cd $(pwd -P)";
curl = "curl -L";
cif = "curl ifconfig.co";
ciff = "curl httpbin.org/ip";
cf = "ping 1.1.1.1";
bt = "bluetoothctl";
cal = "cal -m";
vlc = "vlc -I ncurses";
py = "python";
diff = "git diff --no-index";
sshx = "ssh -o UserKnownHostsFile=/dev/null";
sftpx = "sftp -o UserKnownHostsFile=/dev/null";
lsblk = "lsblk -M";
type = "which";
j = "just";
qmv = "qmv -f destination-only";
mnt = "source ${../scripts/mount.sh}";
tt = "${../scripts/timetracker.sh}";
beamer = "${../scripts/beamer.sh}";
drss = "${../scripts/download_rss.sh}";
sys-rebuild = "_rebuild && source /etc/zshrc && source ~/.zshrc";
sys-update = "_update && source /etc/zshrc && source ~/.zshrc";
repl = "nix repl -f '<nixpkgs>'";
backup = "sudo systemctl start borgbackup-job-data.service && sudo journalctl -fu borgbackup-job-data.service";
};
};
}

97
home/zsh/default.nix Normal file
View file

@ -0,0 +1,97 @@
{
pkgs,
_pkgs,
lib,
...
}: let
aliases = {
"." = "source";
ls = "${_pkgs.exa}/bin/exa -g --git --group-directories-first";
l = "ls -aal";
tre = "ls -alT";
c = "clear";
h = "cd;c";
grep = "grep --color=auto";
f = "cd $(pwd -P)";
curl = "curl -L";
cif = "curl ifconfig.co";
ciff = "curl httpbin.org/ip";
cf = "ping 1.1.1.1";
cal = "cal -m";
py = "python";
diff = "git diff --no-index";
sshx = "ssh -o UserKnownHostsFile=/dev/null";
sftpx = "sftp -o UserKnownHostsFile=/dev/null";
lsblk = "lsblk -M";
type = "which";
j = "just";
qmv = "qmv -f destination-only";
repl = "nix repl -f '<nixpkgs>'";
};
functions = {
d = "dirs -v | tac";
mkcd = ''mkdir -p "$1"; cd "$1"'';
temp = ''(d=$(mktemp -d); cd "$d"; zsh && rm -rf "$d")'';
deltemp = ''
d=$(pwd)
[[ $(echo $d | cut -d/ -f2) != "tmp" ]] && return
cd
rm -rf /tmp/$(echo $d | cut -d/ -f3)
'';
skg = ''
f=$(mktemp -u)
ssh-keygen -t ed25519 -C "" -P "" -f $f
cat $f
cat $f.pub
rm $f $f.pub
'';
wgpeer = ''
key=$(wg genkey)
echo "# Private Key: $key\n[Peer]\nPublicKey = $(wg pubkey <<< $key)\nPresharedKey = $(wg genpsk)\nAllowedIPs = "
'';
s = ''
tmux new -d -c ~ -s "$1"
if [[ -n "$TMUX" ]]; then
tmux switch-client -t "$1"
else
tmux a -t "$1"
fi
'';
};
in {
programs.zsh = {
enable = true;
enableAutosuggestions = true;
syntaxHighlighting.enable = true;
defaultKeymap = "viins";
autocd = true;
history.share = false;
plugins = [
{
name = "powerlevel10k";
src = pkgs.zsh-powerlevel10k;
file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme";
}
];
initExtra = ''
# p10k instant prompt
P10K_INSTANT_PROMPT="$XDG_CACHE_HOME/p10k-instant-prompt-''${(%):-%n}.zsh"
[[ ! -r "$P10K_INSTANT_PROMPT" ]] || source "$P10K_INSTANT_PROMPT"
source ${./p10k.zsh}
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
bindkey '^ ' autosuggest-accept
zstyle ':completion:*' menu select
setopt autopushd
# custom functions
${(builtins.concatStringsSep "\n" (lib.mapAttrsToList (k: v: "${k}() {\n${v}\n}") functions))}
'';
shellAliases = aliases;
};
}

83
home/zsh/full.nix Normal file
View file

@ -0,0 +1,83 @@
{
pkgs,
_pkgs,
lib,
...
}: let
aliases = {
bt = "bluetoothctl";
vlc = "vlc -I ncurses";
mnt = "source ${../scripts/mount.sh}";
tt = "${../scripts/timetracker.sh}";
beamer = "${../scripts/beamer.sh}";
drss = "${../scripts/download_rss.sh}";
sys-rebuild = "_rebuild && source /etc/zshrc && source ~/.zshrc";
sys-update = "_update && source /etc/zshrc && source ~/.zshrc";
backup = "sudo systemctl start borgbackup-job-data.service && sudo journalctl -fu borgbackup-job-data.service";
};
functions = {
_rebuild = ''
sudo nixos-rebuild "''${1:-switch}" --flake ~/nixos
'';
_update = ''
nix flake update --commit-lock-file ~/nixos && _rebuild
'';
conf = ''
tmux new -d -s nixos -c ~/nixos hx flake.nix && tmux split -h -t nixos -c ~/nixos -d -l '50%'
if [[ -n "$TMUX" ]]; then
tmux switch-client -t nixos
else
tmux a -t nixos
fi
'';
shot = ''
file=$(mktemp --suffix .png)
${_pkgs.termshot}/bin/termshot -f $file $TERMSHOT_FLAGS -- "$@" \
&& ${pkgs.imagemagick}/bin/convert $file -crop 0x0+81+191 -crop -113-140 $file \
&& ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png -i $file \
&& ${pkgs.gnome.eog}/bin/eog $file
'';
cshot = ''TERMSHOT_FLAGS="-c" shot "$@";'';
jupyter_export = ''
base=$(basename "$1" .ipynb)
jupyter nbconvert "$1" --to pdf --output "''${base}.pdf"
'';
latex = ''
dir=$(mktemp -d)
pdflatex -output-directory="$dir" "$1" || return $?
pdflatex -output-directory="$dir" "$1" || return $?
mv "$dir"/*.pdf .
rm -rf "$dir"
'';
latex_preview = ''
dir=$(mktemp -d)
pdflatex -output-directory="$dir" "$1" || return $?
(
${pkgs.inotify-tools}/bin/inotifywait -m -e modify "$1" | \
while read; do
pdflatex -halt-on-error -output-directory="$dir" "$1"
done
) &
pid=$!
${pkgs.okular}/bin/okular "$dir"/*.pdf
kill $pid
rm -rf "$dir"
'';
mitm = ''
${pkgs.mitmproxy}/bin/mitmweb -q &
pid=$!
${pkgs.proxychains}/bin/proxychains4 -f ${builtins.toFile "proxychains.conf" "quiet_mode\n[ProxyList]\nhttp 127.0.0.1 8080"} zsh
kill $pid
'';
};
in {
imports = [./.];
programs.zsh = {
initExtra = builtins.concatStringsSep "\n" (lib.mapAttrsToList (k: v: "${k}() {\n${v}\n}") functions);
shellAliases = aliases;
};
}

View file