From 554cb3181908abbc24fdd7e7bc7f2d8243a0b64f Mon Sep 17 00:00:00 2001 From: Christofer <77406318+csc530@users.noreply.github.com> Date: Sun, 7 Apr 2024 08:46:35 -0400 Subject: [PATCH] add windows compatibility for command not found hook (#811) the hook (did_you_mean.nu) had stopped working for me recently, I added an if branch for Windows to use their `Path` env var (not `PATH`) and only list files that match in the `PATHEXT` env var to resolve my issue --- .../nu-hooks/command_not_found/did_you_mean.nu | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/nu-hooks/nu-hooks/command_not_found/did_you_mean.nu b/nu-hooks/nu-hooks/command_not_found/did_you_mean.nu index acfa9c8b..3ab6f828 100644 --- a/nu-hooks/nu-hooks/command_not_found/did_you_mean.nu +++ b/nu-hooks/nu-hooks/command_not_found/did_you_mean.nu @@ -18,9 +18,18 @@ # ``` {|cmd| let commands_in_path = ( - $env.PATH | each {|directory| - if ($directory | path exists) { - ls $directory | get name | path parse | update parent "" | path join + if ($nu.os-info.name == windows) { + $env.Path | each {|directory| + if ($directory | path exists) { + let cmd_exts = $env.PATHEXT | str downcase | split row ';' | str trim --char . + ls $directory | get name | path parse | where {|it| $cmd_exts | any {|ext| $ext == ($it.extension | str downcase)} } | get stem + } + } + } else { + $env.PATH | each {|directory| + if ($directory | path exists) { + ls $directory | get name | path parse | update parent "" | path join + } } } | flatten