1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00
nu_scripts/modules/fuzzy/fuzzy_command_search.nu
ff2400t b5385a2af0
in commands table rename usage to description (#990)
`usage` column under the `scope commands` table has been renamed to
description since nushell version 0.98.0
2024-12-08 07:27:33 -06:00

25 lines
954 B
Text

const tablen = 8
# calculate required tabs/spaces to get a nicely aligned table
def pad-tabs [input_name max_indent] {
let input_length = ($input_name | str length)
let required_tabs = $max_indent - ($input_length / $tablen | into int)
seq 0 $required_tabs | reduce -f "" {|it, acc| $acc + (char tab)}
}
# fuzzy search a) commands b) subcommands
# on selection, will display `help` for the commands
# and paste command into clipboard for you to paste right away
export def fuzzy-command-search [] {
let max_len = (help commands | each { $in.name | str length } | math max)
let max_indent = ($max_len / $tablen | into int)
let command = ((help commands | each {|it|
let name = ($it.name | str trim | ansi strip)
$"($name)(pad-tabs $name $max_indent)($it.description)"
}) | str join (char nl) | fzf | split column (char tab) | get column1.0)
if ($command | is-not-empty) {
help $command
}
}