prometheus / prometheus/alertmanager
`amtool` ZSH completion is broken
@siavashs is already working on this.
Since Jun 19, 2026.
- Dominant language
- Go
- Stars
- 8.6k
- Forks
- 2.5k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 61
Description
What did you do?
amtool --completion-script-zsh >> ~/.zshrc
What did you expect to see?
Proper tab-completion of subcommands similar to that of Bash
What did you see instead? Under which circumstances?
amtool <TAB> results in:
amtool: error: expected command but got ""
Environment
- System information:
Linux 4.14.336-256.559.amzn2.x86_64 x86_64, but applies to all OSes afaik.
- Alertmanager version:
amtool, version 0.27.0 (branch: HEAD, revision: 0aa3c2aad14cff039931923ab16b26b7481783b5)
build user: root@22cd11f671e9
build date: 20240228-11:51:20
go version: go1.21.7
platform: linux/amd64
tags: netgo
-
Prometheus version: N/A
-
Alertmanager configuration file: N/A
-
Prometheus configuration file: N/A
-
Logs: N/A
Solution:
The issue seems to be the way ZSH slices arrays which includes the end index. This is contrary to bash where the end index is not included. Therefore, when $CURRENT-1 is the total number of words, the last word (which is an empty string for a command line ending with space) is included. This causes amtool --completion-bash to receive an extra empty argument.
This is fixed by subtracting 2 instead of 1, like so:
_amtool() {
local matches
matches=($( ${words[1]} --completion-bash "${words[@]:1:$CURRENT-2}" ))
compadd -a matches
if [[ $compstate[nmatches] -eq 0 && $words[$CURRENT] != -* ]]; then
_files
fi
}
compdef _amtool amtool
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.