-
Notifications
You must be signed in to change notification settings - Fork 205
/
fuzzy_command_search.nu
38 lines (33 loc) · 1.23 KB
/
fuzzy_command_search.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# calculate required tabs/spaces to get a nicely aligned table
let tablen = 8
let max-len = (help commands | get subcommands | each { $it.name | str length } | math max)
let max-indent = ($max-len / $tablen | into int)
def pad-tabs [input-name] {
let input-length = ($input-name| str length)
let required-tabs = $max-indent - ($"($input-length / $tablen | into int)" | str to-int)
echo $"( seq $required-tabs | reduce -f "" {$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
def fuzzy-command-search [] {
help (echo (help commands | get subcommands | each {
let name = ($it.name | str trim | ansi strip)
$"(
$name
)( pad-tabs $name
)(
$it.description
)"
}) (
help commands | reject subcommands | each {
let name = ($it.name | str trim | ansi strip)
$"(
$name
)(
pad-tabs $name
)(
$it.description
)"
}) | str collect (char nl) | fzf | split column (char tab)| get Column1 | clip; paste )
}