Skip to content

Commit a316ef7

Browse files
committed
jc: add magic command completions and clean up parsing
1 parent 41b1e95 commit a316ef7

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

asd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foofoofoofoo

modules/jc/mod.nu

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,37 @@ def --env "nu-complete jc" [] {
44
}
55

66
let options = try {
7-
let options = ^jc --help
8-
| collect
9-
| parse "{_}Parsers:\n{_}\n\nOptions:\n{inherent}\n\nSlice:{_}"
10-
| get 0
11-
12-
let parsers = ^jc --about
7+
let about = ^jc --about
138
| from json
9+
10+
let magic = $about
11+
| get parsers
12+
| each { { value: $in.magic_commands?, description: $in.description } }
13+
| where value != null
14+
| flatten
15+
16+
let parsers = $about
1417
| get parsers
1518
| select argument description
1619
| rename value description
1720

18-
let inherent = $options.inherent
21+
let inherent = ^jc --help
1922
| lines
20-
| parse " {short}, {long} {description}"
23+
| split list "" # Group with empty lines as boundary.
24+
| where { $in.0? == "Options:" } | get 0 # Get the first section that starts with "Options:"
25+
| skip 1 # Remove header
26+
| each { str trim }
27+
| parse "{short}, {long} {description}"
2128
| update description { str trim }
2229
| each {|record|
2330
[[value, description];
2431
[$record.short, $record.description],
25-
[$record.long, $record.description]]
32+
[$record.long, $record.description],
33+
]
2634
}
2735
| flatten
2836

29-
$parsers ++ $inherent
37+
$magic ++ $parsers ++ $inherent
3038
} catch {
3139
[]
3240
}

0 commit comments

Comments
 (0)