Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ For breaking changes, check [here](#breaking-changes).

## Unreleased

- zsh completion: offer a command's options without typing a dash first, by opting the registered program names out of zsh's `prefix-needed` style

## 0.12.83

- Populate `:msg` in the `:error-fn` data for `dispatch` command errors (`:no-match`, `:input-exhausted`), like option errors already carry it
- zsh completion: classify an option without a `:desc` as an option. It was added as a value, which offered it where zsh hides described options

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@babashka/cli",
"version": "0.12.80",
"version": "0.12.83",
"description": "Turn functions into command line interfaces.",
"exports": {
".": "./index.mjs"
Expand Down
6 changes: 6 additions & 0 deletions src/babashka/cli.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,9 @@
fn (str "_babashka_cli_complete_" (str/replace program-name #"[^a-zA-Z0-9_]+" "_"))
names-sp (str/join " " names)
names-csv (str/join "," names)
names-zstyle (str/join "\n"
(map #(str "zstyle ':completion:*:*:" % ":*:options' prefix-needed false")
names))
names-nu (str "[" (str/join " " (map #(str "\"" % "\"") names)) "]")]
(case shell
:bash (str fn "()
Expand Down Expand Up @@ -1743,6 +1746,9 @@ complete -F " fn " " names-sp "
[[ -n $do_files ]] && { _files; ret=0; }
return $ret
}
# zsh hides options until a dash is typed. After a command there is usually
# nothing else to complete, so opt out for these programs only
" names-zstyle "
# register the bare name(s); zsh's _normal completes ./name and /abs/name via the basename
compdef " fn " " names-sp "
")
Expand Down
10 changes: 9 additions & 1 deletion test/babashka/cli/completion_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@
(is (not (str/includes? zsh "elif [[ $v == -* ]]"))))
(testing "an option without a description is added under the options tag"
(is (str/includes? zsh "bareopt+=(\"$v\")"))
(is (str/includes? zsh "_describe -t options option bareopt")))))
(is (str/includes? zsh "_describe -t options option bareopt")))
(testing "options are offered without typing a dash first"
(is (str/includes? zsh "zstyle ':completion:*:*:myprogram:*:options' prefix-needed false")))))

(deftest zsh-snippet-prefix-needed-per-name-test
(testing "every registered name opts out of prefix-needed"
(let [zsh (snippet-via-cmd cmd-table {:prog "x"} "zsh" "--prog" "sq" "--prog" "squint")]
(is (str/includes? zsh "zstyle ':completion:*:*:sq:*:options' prefix-needed false"))
(is (str/includes? zsh "zstyle ':completion:*:*:squint:*:options' prefix-needed false")))))

(defn- complete-out
"Run the completion handler for `cmdline` and return its emitted
Expand Down
3 changes: 3 additions & 0 deletions test/resources/completion/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ _babashka_cli_complete_myprogram() {
[[ -n $do_files ]] && { _files; ret=0; }
return $ret
}
# zsh hides options until a dash is typed. After a command there is usually
# nothing else to complete, so opt out for these programs only
zstyle ':completion:*:*:myprogram:*:options' prefix-needed false
# register the bare name(s); zsh's _normal completes ./name and /abs/name via the basename
compdef _babashka_cli_complete_myprogram myprogram
2 changes: 1 addition & 1 deletion version.edn
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{:major 0, :minor 12, :release 80}
{:major 0, :minor 12, :release 83}