From 7dec0745a6a16db7c7f454a326cd225128978108 Mon Sep 17 00:00:00 2001 From: Ahwx Date: Fri, 2 Jan 2026 11:36:33 +0100 Subject: [PATCH] feat: adds more zsh functions (cdfile/get-git-root/cd-git-root/pushd-git-root-widget) --- modules/home/zsh.nix | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/home/zsh.nix b/modules/home/zsh.nix index 244bd07..54f020d 100644 --- a/modules/home/zsh.nix +++ b/modules/home/zsh.nix @@ -128,6 +128,38 @@ printf "%s\n" "''${url}" } + function cd() { + if [ -f "$1" ]; then + ${pkgs.zoxide}/bin/zoxide "$(dirname "$1")" + return + fi + + ${pkgs.zoxide}/bin/zoxide $@ + } + + get-git-root() { + echo "$(${pkgs.git}/bin/git rev-parse --show-toplevel 2>/dev/null)" + } + + cd-git-root() { + pushd "$(get-git-root)" + } + + pushd-git-root-widget() { + setopt localoptions pipefail no_aliases 2> /dev/null + local dir="$(eval "get-git-root")" + if [[ -z "$dir" ]]; then + zle redisplay + return 0 + fi + zle push-line + BUFFER="builtin pushd -- ''${(q)dir}" + zle accept-line + local ret=$? + zle reset-prompt + return $ret + } + function nixcd () { PACKAGE_NAME="$1" if [[ "$PACKAGE_NAME" = "" ]]; then