Cli.fish_engine: def of cli@0.2.0.0 Import: import cli@0.2.0.0/cli.bend as Cli Lines 7223-7292 of cli@0.2.0.0/cli.bend: https://jend.leeeet.dev/read.txt?path=cli@0.2.0.0/cli.bend&start_line=7223&end_line=7292 import Base # The function every fish script shares, for function prefix id: it walks # the words before the cursor as the bash engine does. def fish_engine(+id: String) -> List<&2, String>: [ "", "# Succeeds when the words before the cursor reach path $argv[1] and the next", "# word can be one of $argv[2..-1]: n, an option or subcommand; h, a", "# subcommand after help; v, an option's value; p, positional slot k.", String.concat(["function ", id, "_is"]), " # fish 4 deprecates -o, which fish 3 needs.", " set -l words (commandline -xpc 2>/dev/null; or commandline -opc)", " set -e words[1]", " set -l path 0", String.concat([" set -l shape (", id, "_shape 0 | string split ' ')"]), " set -l want 0", " set -l end 0", " set -l help 0", " set -l n 0", " for word in $words", " if test $want = 1", " set want 0", " else if test $end = 0; and test \"$word\" = --", " set end 1", " else if test $end = 0; and string match -q -r -- '^--.' $word", String.concat([" if not string match -q -- '*=*' $word; and ", id, "_valued $path $word"]), " set want 1", " end", " else if test $end = 0; and string match -q -r -- '^-.' $word", " set -l chars (string split '' -- (string sub -s 2 -- $word))", " for i in (seq (count $chars))", String.concat([" if ", id, "_valued $path -$chars[$i]"]), " test $i = (count $chars); and set want 1", " break", " end", " end", " else if test $shape[1] = 1", " if test $end = 1", " return 1", " else if test $help = 0; and test \"$word\" = help", " set help 1", " else", String.concat([" set path (", id, "_dest $path $word); or return 1"]), String.concat([" set shape (", id, "_shape $path | string split ' ')"]), " end", " else", " # n counts the slots filled. The variadic slot stays open, but a", " # rest() value takes every later word, so nothing more completes.", " set n (math $n + 1)", " if test $n = $shape[2]; and test $shape[3] = 1", " set end 1", " else if test $n = $shape[2]", " set n (math $n - 1)", " end", " end", " end", " test $path = $argv[1]; or return 1", " set -l tags", " if test $want = 1", " set tags v", " else", " test $end = 0; and test $help = 0; and set -a tags n", " test $end = 0; and test $help = 1; and set -a tags h", " test $shape[1] = 0; and test $help = 0; and set -a tags p(math $n + 1)", " end", " for tag in $argv[2..-1]", " contains -- $tag $tags; and return 0", " end", " return 1", "end", ] Uses (3): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=String.concat