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
19 changes: 19 additions & 0 deletions book/src/shell_completion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Shell Completion

## Zsh

prr ships a zsh completion function in completions/\_prr.
Install it into a directory in your `$fpath` (for example `~/.zsh/completions`):

`sh
mkdir -p ~/.zsh/completions
cp completions/\_prr ~/.zsh/completions/
`

In your `~/.zshrc`:

```sh
fpath=(~/.zsh/completions $fpath)
autoload -Uz compinit
compinit
```
94 changes: 94 additions & 0 deletions completions/_prr
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#compdef prr

_prr_reviews() {
local -a reviews
local handle r_status file

if (( ${_PRR_IN_COMPLETION:-0} )); then
return 1
fi

local _PRR_IN_COMPLETION=1

while IFS=' ' read -r handle r_status file _; do
[[ -z $handle ]] && continue
reviews+=("${handle}:${r_status} ${file}")
done < <(prr status --no-titles 2>/dev/null)

(( ${#reviews[@]} )) || return 1

_describe -t reviews 'review' reviews
}

_prr() {
local -a commands
local curcontext="$curcontext" state line

commands=(
'get:Get a pull request and begin a review'
'edit:Open an existing review in $EDITOR'
'submit:Submit a review'
'apply:Apply a pull request to the working directory'
'status:Print a status summary of all known reviews'
'remove:Remove a review'
)

_arguments -C \
'(-h --help)'{-h,--help}'[Print help information]' \
'(-V --version)'{-V,--version}'[Print version information]' \
'--config[Path to config file]:config file:_files' \
'1: :->cmd' \
'*:: :->args'

case $state in
cmd)
_describe -t commands 'prr command' commands
;;

args)
case $line[1] in
get)
_arguments \
'(-h --help)'{-h,--help}'[Print help information]' \
'(-f --force)'{-f,--force}'[Ignore unsubmitted review checks]' \
'--open[Open review file in $EDITOR after download]' \
'1:pull request (eg. danobi/prr/24):'
;;

edit)
_arguments \
'(-h --help)'{-h,--help}'[Print help information]' \
'1:review to edit:_prr_reviews'
;;

submit)
_arguments \
'(-h --help)'{-h,--help}'[Print help information]' \
'(-d --debug)'{-d,--debug}'[Print debug output while submitting]' \
'1:review to submit:_prr_reviews'
;;

apply)
_arguments \
'(-h --help)'{-h,--help}'[Print help information]' \
'1:pull request (eg. danobi/prr/24):'
;;

status)
_arguments \
'(-h --help)'{-h,--help}'[Print help information]' \
'(-n --no-titles)'{-n,--no-titles}'[Hide column titles from output]' \
'1::status argument:'
;;

remove)
_arguments \
'(-h --help)'{-h,--help}'[Print help information]' \
'(-f --force)'{-f,--force}'[Ignore unsubmitted review checks]' \
'(-s --submitted)'{-s,--submitted}'[Remove submitted reviews in addition to provided reviews]' \
'1:review to remove:_prr_reviews'
;;
esac
;;
esac
}