feat(Nushell): trancate diractory path to git root

This commit is contained in:
2026-05-29 22:32:33 +08:00
parent b8c94de6c6
commit fe6a79626f
2 changed files with 104 additions and 8 deletions
+18
View File
@@ -59,6 +59,23 @@ def --env --wrapped __zoxide_zi [...rest:string] {
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
}
# Jump to git repository root when currently inside a repository.
def --env __zoxide_zg [] {
if (which ^git | is-empty) {
return
}
let top = (^git rev-parse --show-toplevel | complete)
if ($top.exit_code != 0) {
return
}
let root = ($top.stdout | str trim -r -c "\n")
if ($root != "") {
cd $root
}
}
# =============================================================================
#
# Commands for zoxide. Disable these using --no-cmd.
@@ -66,6 +83,7 @@ def --env --wrapped __zoxide_zi [...rest:string] {
export alias z = __zoxide_z
export alias zi = __zoxide_zi
export alias zg = __zoxide_zg
# =============================================================================
#