Diff
1diff --git a/plugins/gh/.gitignore b/plugins/gh/.gitignore
2new file mode 100644
3index 0000000000000000000000000000000000000000..fa1244ab5f4170c2cbe2956a50b294706b251b04
4--- /dev/null
5+++ b/plugins/gh/.gitignore
6@@ -0,0 +1 @@
7+_gh
8diff --git a/plugins/gh/README.md b/plugins/gh/README.md
9new file mode 100644
10index 0000000000000000000000000000000000000000..54e046a1cd048af24ab2f1836d94159a79e2ba06
11--- /dev/null
12+++ b/plugins/gh/README.md
13@@ -0,0 +1,23 @@
14+# GitHub CLI plugin
15+
16+This plugin adds completion for the [GitHub CLI](https://cli.github.com/).
17+
18+To use it, add `gh` to the plugins array in your zshrc file:
19+
20+```zsh
21+plugins=(... gh)
22+```
23+
24+This plugin does not add any aliases.
25+
26+## Cache
27+
28+This plugin caches the completion script and is automatically updated when the
29+plugin is loaded, which is usually when you start up a new terminal emulator.
30+
31+The cache is stored at:
32+
33+- `$ZSH/plugins/gh/_gh` completions script
34+
35+- `$ZSH_CACHE_DIR/gh_version` version of GitHub CLI, used to invalidate
36+ the cache.
37diff --git a/plugins/gh/gh.plugin.zsh b/plugins/gh/gh.plugin.zsh
38new file mode 100644
39index 0000000000000000000000000000000000000000..8e055ec3535170e53417a68e01dc0d9e0fc2e93d
40--- /dev/null
41+++ b/plugins/gh/gh.plugin.zsh
42@@ -0,0 +1,13 @@
43+# Autocompletion for the GitHub CLI (gh).
44+
45+if (( $+commands[gh] )); then
46+ if [[ ! -r "$ZSH_CACHE_DIR/gh_version" \
47+ || "$(gh --version)" != "$(< "$ZSH_CACHE_DIR/gh_version")"
48+ || ! -f "$ZSH/plugins/gh/_gh" ]]; then
49+ gh completion --shell zsh > $ZSH/plugins/gh/_gh
50+ gh --version > $ZSH_CACHE_DIR/gh_version
51+ fi
52+ autoload -Uz _gh
53+ _comps[gh]=_gh
54+fi
55+