-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for zsh shell completions
This also fixes `rr ls` not to list pre-installed files as traces.
- Loading branch information
1 parent
679bbd4
commit 84b7de5
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#compdef rr | ||
|
||
_rr() { | ||
# allow overridding rr with another command (e.g. if multiple versions are installed) | ||
zstyle -s :completion${curcontext}options command rr | ||
: ${rr:=rr} | ||
|
||
_rr_subcommands() { | ||
$rr --list-commands | cut -s -d ' ' -f 3 | ||
} | ||
_rr_traces() { | ||
$rr ls | grep -v '^cpu_lock$' | ||
} | ||
|
||
_arguments -C \ | ||
'1:subcommand:($(_rr_subcommands))' \ | ||
'*::arg:->args' | ||
|
||
case $state in | ||
args) ;; | ||
*) return;; | ||
esac | ||
|
||
# different subcommands can have different options. show the appropriate options for each. | ||
# this is not ideal; `reply=` forces zsh to rerun `rr help` each time you hit tab. | ||
# the alternative though is rewriting half the code in _arguments. | ||
zstyle -e ':completion:*:*:rr:*:options' command \ | ||
'reply=( '${(q)service}' help ${words:#-*} )' | ||
|
||
case $line[1] in | ||
# complete a command, then delegate to that command's completion script | ||
# -A means "don't use _normal until we've completed a non-option" | ||
record) _arguments -A '-*' '1:command: _precommand' '*:: :_normal -p $service' --;; | ||
replay|rerun|ps|sources|traceinfo|pack|dump) _arguments '*:trace:($(_rr_traces))' --;; | ||
help) _arguments ':subcommand:($(_rr_subcommands))' --;; | ||
explicit-sources|filename) _gnu_generic;; | ||
*) _arguments --; | ||
esac | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters