refactor nushell zoxide bootstrap and windows path normalization
This commit is contained in:
@@ -41,6 +41,20 @@ export-env {
|
|||||||
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
# When using zoxide with --no-cmd, alias these internal functions as desired.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def _pj_normalize_windows_drive [path: string] {
|
||||||
|
if (($nu.os-info.name | str downcase) != "windows") {
|
||||||
|
return $path
|
||||||
|
}
|
||||||
|
|
||||||
|
let parsed = ($path | parse --regex '^(?<drive>[a-zA-Z]):(?<rest>.*)$')
|
||||||
|
if ($parsed | is-empty) {
|
||||||
|
return $path
|
||||||
|
}
|
||||||
|
|
||||||
|
let item = ($parsed | first)
|
||||||
|
$"(($item.drive | str upcase)):($item.rest)"
|
||||||
|
}
|
||||||
|
|
||||||
# Jump to a directory using only keywords.
|
# Jump to a directory using only keywords.
|
||||||
def --env --wrapped __zoxide_z [...rest: string] {
|
def --env --wrapped __zoxide_z [...rest: string] {
|
||||||
let path = match $rest {
|
let path = match $rest {
|
||||||
@@ -51,12 +65,13 @@ def --env --wrapped __zoxide_z [...rest: string] {
|
|||||||
zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
|
zoxide query --exclude $env.PWD -- ...$rest | str trim -r -c "\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cd $path
|
cd (_pj_normalize_windows_drive $path)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Jump to a directory using interactive search.
|
# Jump to a directory using interactive search.
|
||||||
def --env --wrapped __zoxide_zi [...rest:string] {
|
def --env --wrapped __zoxide_zi [...rest:string] {
|
||||||
cd $'(zoxide query --interactive -- ...$rest | str trim -r -c "\n")'
|
let path = (zoxide query --interactive -- ...$rest | str trim -r -c "\n")
|
||||||
|
cd (_pj_normalize_windows_drive $path)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Jump to git repository root when currently inside a repository.
|
# Jump to git repository root when currently inside a repository.
|
||||||
@@ -72,7 +87,7 @@ def --env __zoxide_zg [] {
|
|||||||
|
|
||||||
let root = ($top.stdout | str trim -r -c "\n")
|
let root = ($top.stdout | str trim -r -c "\n")
|
||||||
if ($root != "") {
|
if ($root != "") {
|
||||||
cd $root
|
cd (_pj_normalize_windows_drive $root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user