From 8865dee1e9c51138cabc90d4c7a27de5f29a8224 Mon Sep 17 00:00:00 2001 From: Dict Xiong Date: Sat, 15 Nov 2025 14:48:19 +0800 Subject: [PATCH] feat: add bnd and nor and completions --- .zshrc2 | 27 ++++++++++++++++++++++++--- functions/_nixos_config_hosts | 3 +++ functions/_sagt | 3 +++ functions/_use | 3 +++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 functions/_nixos_config_hosts create mode 100644 functions/_sagt create mode 100644 functions/_use diff --git a/.zshrc2 b/.zshrc2 index 5679b0f..0b92a98 100644 --- a/.zshrc2 +++ b/.zshrc2 @@ -9,6 +9,7 @@ else fi export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) export PATH="$PATH:$DOTFILES/scripts" +fpath=($DOTFILES/functions $fpath) export EDITOR='vim' # env for apps export PYTHONIOENCODING='UTF-8' @@ -130,9 +131,29 @@ alias "jcf"='jc -f' alias "jcfu"='jc -fu' alias "sc"='systemctl' alias "t"='tmux' -gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX } -sagt() { eval "$($DOTFILES/tools/sagent.sh $@)" } -use() { nix --experimental-features nix-command --extra-experimental-features flakes shell "${(*)@/#%(#b)([^#]#)/nixpkgs#$match}" } +gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX ; } +sagt() { eval "$($DOTFILES/tools/sagent.sh $@)" ; } +## nixos +use() { nix --experimental-features nix-command --extra-experimental-features flakes shell "${(*)@/#%(#b)([^#]#)/nixpkgs#$match}" ; } +bnd() { + if [[ -n "$1" && -d "./hosts/$1" ]]; then + nixos-rebuild --flake .#$1 build + nix-diff /opt/NixOS-Config/results/hosts/$1 ./result --color=always | less + else + echo host $1 does not exist + fi +} +nor() { + test -n "$1" || { echo fatal: no verb given; return 1; } + nixos-rebuild "$1" --flake .${2:+#}$2 +} +alias 'nors'='nor switch' +alias 'norbt'='nor boot' +alias 'nort'='nor test' +alias 'norb'='nor build' +alias 'nordb'='nor dry-build' +alias 'norda'='nor dry-activate' + # key bindings bindkey "^b" beginning-of-line # ctrl+b diff --git a/functions/_nixos_config_hosts b/functions/_nixos_config_hosts new file mode 100644 index 0000000..368457c --- /dev/null +++ b/functions/_nixos_config_hosts @@ -0,0 +1,3 @@ +#compdef bnd nor + +compadd -- /root/NixOS-Config/hosts/*(/:t) \ No newline at end of file diff --git a/functions/_sagt b/functions/_sagt new file mode 100644 index 0000000..d5b4ed9 --- /dev/null +++ b/functions/_sagt @@ -0,0 +1,3 @@ +#compdef sagt + +compadd -- kill ls op piv reset \ No newline at end of file diff --git a/functions/_use b/functions/_use new file mode 100644 index 0000000..6df6fdb --- /dev/null +++ b/functions/_use @@ -0,0 +1,3 @@ +#compdef use + +compadd -- $(nix eval --impure --expr 'builtins.attrNames ( (import ) {} )' 2>/dev/null | tr '[]"' ' ') \ No newline at end of file