aboutsummaryrefslogtreecommitdiff
path: root/dot_config/nushell/autoload/completer.nu
blob: 910305e2cb4d86df7b67bd274c606099e21e2c01 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#let fish_completer = {|spans|
#    fish --command $"complete '--do-complete=($spans | str replace --all "'" "\\'" | str join ' ')'"
#    | from tsv --flexible --noheaders --no-infer
#    | rename value description
#    | update value {|row|
#      let value = $row.value
#      let need_quote = ['\' ',' '[' ']' '(' ')' ' ' '\t' "'" '"' "`"] | any {$in in $value}
#      if ($need_quote and ($value | path exists)) {
#        let expanded_path = if ($value starts-with ~) {$value | path expand --no-symlink} else {$value}
#        $'"($expanded_path | str replace --all "\"" "\\\"")"'
#      } else {$value}
#    }
#}
#
#
#let carapace_completer = {|spans: list<string>|
#    carapace $spans.0 nushell ...$spans
#    | from json
#    | if ($in | default [] | any {|| $in.display | str starts-with "ERR"}) { null } else { $in }
#}
#
## This completer will use carapace by default
#let external_completer = {|spans|
#    let expanded_alias = scope aliases
#    | where name == $spans.0
#    | get -o 0.expansion
#
#    let spans = if $expanded_alias != null {
#        $spans
#        | skip 1
#        | prepend ($expanded_alias | split row ' ' | take 1)
#    } else {
#        $spans
#    }
#
#    match $spans.0 {
#        # carapace completions are incorrect for nu
#        nu => $fish_completer
#        # fish completes commits and branch names in a nicer way
#        git => $fish_completer
#        # carapace doesn't have completions for asdf
#        asdf => $fish_completer
#        _ => $carapace_completer
#    } | do $in $spans
#}
#
#$env.config = {
#    # ...
#    completions: {
#        external: {
#            enable: true
#            completer: $external_completer
#        }
#    }
#    # ...
#}