• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2use builtin;
3use str;
4
5set edit:completion:arg-completer[my-app] = {|@words|
6    fn spaces {|n|
7        builtin:repeat $n ' ' | str:join ''
8    }
9    fn cand {|text desc|
10        edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
11    }
12    var command = 'my-app'
13    for word $words[1..-1] {
14        if (str:has-prefix $word '-') {
15            break
16        }
17        set command = $command';'$word
18    }
19    var completions = [
20        &'my-app'= {
21            cand --single-quotes 'Can be ''always'', ''auto'', or ''never'''
22            cand --double-quotes 'Can be "always", "auto", or "never"'
23            cand --backticks 'For more information see `echo test`'
24            cand --backslash 'Avoid ''\n'''
25            cand --brackets 'List packages [filter]'
26            cand --expansions 'Execute the shell command with $SHELL'
27            cand -h 'Print help'
28            cand --help 'Print help'
29            cand -V 'Print version'
30            cand --version 'Print version'
31            cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never'''
32            cand cmd-double-quotes 'Can be "always", "auto", or "never"'
33            cand cmd-backticks 'For more information see `echo test`'
34            cand cmd-backslash 'Avoid ''\n'''
35            cand cmd-brackets 'List packages [filter]'
36            cand cmd-expansions 'Execute the shell command with $SHELL'
37            cand help 'Print this message or the help of the given subcommand(s)'
38        }
39        &'my-app;cmd-single-quotes'= {
40            cand -h 'Print help'
41            cand --help 'Print help'
42        }
43        &'my-app;cmd-double-quotes'= {
44            cand -h 'Print help'
45            cand --help 'Print help'
46        }
47        &'my-app;cmd-backticks'= {
48            cand -h 'Print help'
49            cand --help 'Print help'
50        }
51        &'my-app;cmd-backslash'= {
52            cand -h 'Print help'
53            cand --help 'Print help'
54        }
55        &'my-app;cmd-brackets'= {
56            cand -h 'Print help'
57            cand --help 'Print help'
58        }
59        &'my-app;cmd-expansions'= {
60            cand -h 'Print help'
61            cand --help 'Print help'
62        }
63        &'my-app;help'= {
64            cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never'''
65            cand cmd-double-quotes 'Can be "always", "auto", or "never"'
66            cand cmd-backticks 'For more information see `echo test`'
67            cand cmd-backslash 'Avoid ''\n'''
68            cand cmd-brackets 'List packages [filter]'
69            cand cmd-expansions 'Execute the shell command with $SHELL'
70            cand help 'Print this message or the help of the given subcommand(s)'
71        }
72        &'my-app;help;cmd-single-quotes'= {
73        }
74        &'my-app;help;cmd-double-quotes'= {
75        }
76        &'my-app;help;cmd-backticks'= {
77        }
78        &'my-app;help;cmd-backslash'= {
79        }
80        &'my-app;help;cmd-brackets'= {
81        }
82        &'my-app;help;cmd-expansions'= {
83        }
84        &'my-app;help;help'= {
85        }
86    ]
87    $completions[$command]
88}
89