completion: document installation and usage in README Add a "Shell Completion" section to README.md to document how to install and use `completion.bash` and `completion.zsh`. Change-Id: Ibf6c81043af6c24d45ea2dc6a6caa26d98ab7374 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/581261 Tested-by: Gavin Mak <gavinmak@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com>
diff --git a/README.md b/README.md index 258491b..b8c6696 100644 --- a/README.md +++ b/README.md
@@ -49,6 +49,43 @@ $ chmod a+rx ~/.bin/repo ``` +## Shell Completion + +Repo includes completion scripts for Bash and Zsh. + +### Bash + +To enable completion in Bash, source `completion.bash` in your `~/.bashrc`: + +```sh +source /path/to/git-repo/completion.bash +``` + +### Zsh + +To enable completion in Zsh, you can either: + +1. Copy or symlink `completion.zsh` to a file named `_repo` in a directory in your `$fpath`: + ```sh + mkdir -p ~/.zsh/completion + # You can copy the file: + cp /path/to/git-repo/completion.zsh ~/.zsh/completion/_repo + # Or symlink it: + ln -s /path/to/git-repo/completion.zsh ~/.zsh/completion/_repo + ``` + Then add that directory to your `fpath` in `~/.zshrc` before `compinit`: + ```zsh + fpath=(~/.zsh/completion $fpath) + autoload -Uz compinit + compinit + ``` + +2. Or source the file directly and call `compdef` in your `~/.zshrc`: + ```zsh + source /path/to/git-repo/completion.zsh + compdef _repo repo + ``` + [new-bug]: https://issues.gerritcodereview.com/issues/new?component=1370071 [issue tracker]: https://issues.gerritcodereview.com/issues?q=is:open%20componentid:1370071