def zsh_script
cli@0.2.0.0 · cli.bend:7005
import cli@0.2.0.0/cli.bend as Cli
import Base
7005def zsh_script(+name: String, +items: List<&2, Item>) -> String:
7006 +lists = place_lists(all_places(items), [])
7007 +id = String.append("_", ident(name))
7008 text_lines(List.concat(&2, String, [
7009 [String.append("#compdef ", name), "", String.append(id, "() {"),
7010 " local curcontext=$curcontext state line"],
7011 zsh_arrays(lists),
7012 zsh_cmd(items, [], lists, name, [],
7013 zsh_arms(items, global_items(items), lists, name, [], " "),
7014 " "),
7015 ["}",
7016 "",
7017 String.concat(["if [[ $funcstack[1] == ", Sh.quote(String.append("_",
7018 name)), " ]]; then"]),
7019 String.concat([" ", id, " \"$@\""]),
7020 "else",
7021 String.concat([" compdef ", id, " ", Sh.quote(name)]),
7022 "fi"],
7023 ]))