Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Windows command_not_found example #1576

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions book/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,40 @@ $env.config = {
}
}
```



### `command_not_found` Hook in _Windows_

The following hook uses the `ftype` command, to find program paths in _Windows_ that might be relevant to the user for `alias`-ing.

```nu
$env.config = {
...other config...

hooks: {
...other hooks...

command_not_found: {
|cmd_name| (
try {
let attrs = (
ftype | find $cmd_name | to text | lines | reduce -f [] { |line, acc|
$line | parse "{type}={path}" | append $acc
} | group-by path | transpose key value | each { |row|
{ path: $row.key, types: ($row.value | get type | str join ", ") }
}
)
let len = ($attrs | length)

if $len == 0 {
return null
} else {
return ($attrs | table --collapse)
}
}
)
}
}
}
```