Skip to content

Commit e8df70a

Browse files
authored
Port before_v0.60/fuzzy, before_v0.60/ls-mods and before_v0.60/nu_101 (nushell#845)
This PR is part of porting all old scripts nushell#221 and includes a set of modules: - fuzzy -> `modules/fuzzy/fuzzy_command_search.nu` - ls-mods -> `modules/ls-mods`: `ls-less.nu`, `ls-wide.nu` and `ls-wide-with-color.nu` - nu_101 -> `modules/nu_101`: `nothing.nu` and `inner_outer_loop.nu` Edit: `fuzzy` and `nu_101` have been moved to `sourced`
1 parent 7a5424d commit e8df70a

File tree

16 files changed

+177
-230
lines changed

16 files changed

+177
-230
lines changed

before_v0.60/fuzzy/fuzzy_command_search.nu

Lines changed: 0 additions & 38 deletions
This file was deleted.

before_v0.60/fuzzy/fuzzy_history_search.nu

Lines changed: 0 additions & 1 deletion
This file was deleted.

before_v0.60/ls_mods/ls-hidden.nu

Lines changed: 0 additions & 6 deletions
This file was deleted.

before_v0.60/ls_mods/ls-wide-with-color.nu

Lines changed: 0 additions & 95 deletions
This file was deleted.

before_v0.60/ls_mods/ls-wide.nu

Lines changed: 0 additions & 54 deletions
This file was deleted.

before_v0.60/nu_101/README.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

before_v0.60/nu_101/demo.nu

Lines changed: 0 additions & 5 deletions
This file was deleted.

before_v0.60/fuzzy/README.md renamed to modules/fuzzy/README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,17 @@ want to search commands/your history interactively, which is where [fzf](https:/
1212
`./fuzzy_command_search.nu` searches both commands and subcommands for both a) names and b) their description, and, after pressing `enter`, copies the selected command into the clipboard
1313

1414
To use them in your day-to-day workflow, add
15+
1516
```
16-
[
17-
"source <absolute-path-to-nu_script>/fuzzy/fuzzy_history_search.nu",
18-
"source <absolute-path-to-nu_script>/fuzzy/fuzzy_command_search.nu"
19-
]
17+
source <absolute-path-to-nu_scripts>/fuzzy/fuzzy_history_search.nu
18+
source <absolute-path-to-nu_scripts>/fuzzy/fuzzy_command_search.nu
2019
```
2120

22-
23-
to your `startup` array in you config `.toml`.
21+
to your `config.nu`
2422

2523
It's likely a good idea to also add some short and sweet aliases, e.g.
2624

2725
```
2826
alias hi = fuzzy-history-search
2927
alias hf = fuzzy-command-search
3028
```
31-
32-
To your config
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const tablen = 8
2+
3+
# calculate required tabs/spaces to get a nicely aligned table
4+
def pad-tabs [input_name max_indent] {
5+
let input_length = ($input_name | str length)
6+
let required_tabs = $max_indent - ($input_length / $tablen | into int)
7+
seq 0 $required_tabs | reduce -f "" {|it, acc| $acc + (char tab)}
8+
}
9+
10+
# fuzzy search a) commands b) subcommands
11+
# on selection, will display `help` for the commands
12+
# and paste command into clipboard for you to paste right away
13+
14+
15+
export def fuzzy-command-search [] {
16+
let max_len = (help commands | each { $in.name | str length } | math max)
17+
let max_indent = ($max_len / $tablen | into int)
18+
let command = ((help commands | each {|it|
19+
let name = ($it.name | str trim | ansi strip)
20+
$"($name)(pad-tabs $name $max_indent)($it.usage)"
21+
}) | str join (char nl) | fzf | split column (char tab) | get column1.0)
22+
if ($command | is-not-empty) {
23+
help $command
24+
}
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export def fuzzy-history-search [] { cat $nu.history-path | fzf | clip }

0 commit comments

Comments
 (0)