Skip to content

Commit

Permalink
add Windows command_not_found example (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
chapmanjacobd authored Oct 4, 2024
1 parent afc86c2 commit 38bd89b
Showing 1 changed file with 37 additions and 0 deletions.
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)
}
}
)
}
}
}
```

0 comments on commit 38bd89b

Please sign in to comment.