use builtin; use str; set edit:completion:arg-completer[fmerge] = {|@words| fn spaces {|n| builtin:repeat $n ' ' | str:join '' } fn cand {|text desc| edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc } var command = 'fmerge' for word $words[1..-1] { if (str:has-prefix $word '-') { break } set command = $command';'$word } var completions = [ &'fmerge'= { cand -e 'enables experimental features' cand --experimental 'enables experimental features' cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' cand man 'Renders the manual.' cand autocomplete 'Renders shell completion scripts.' cand merge 'Merge.' cand help 'Print this message or the help of the given subcommand(s)' } &'fmerge;man'= { cand -o 'o' cand --out 'out' cand -f 'f' cand --format 'format' cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' } &'fmerge;autocomplete'= { cand -o 'o' cand --out 'out' cand -s 's' cand --shell 'shell' cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' } &'fmerge;merge'= { cand -f 'f' cand --file 'file' cand -r 'r' cand --regex 'regex' cand -h 'Print help' cand --help 'Print help' cand -V 'Print version' cand --version 'Print version' } &'fmerge;help'= { cand man 'Renders the manual.' cand autocomplete 'Renders shell completion scripts.' cand merge 'Merge.' cand help 'Print this message or the help of the given subcommand(s)' } &'fmerge;help;man'= { } &'fmerge;help;autocomplete'= { } &'fmerge;help;merge'= { } &'fmerge;help;help'= { } ] $completions[$command] }