From 38bd89bcfeb7dbba18f4b70ee911da76ab3f68e1 Mon Sep 17 00:00:00 2001 From: Jacob Chapman <7908073+chapmanjacobd@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:01:07 -0500 Subject: [PATCH] add Windows command_not_found example (#1576) --- book/hooks.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/book/hooks.md b/book/hooks.md index 023d8cd76b..a2e63b5fdd 100644 --- a/book/hooks.md +++ b/book/hooks.md @@ -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) + } + } + ) + } + } +} +```