#compdef ghx # ghx — GitHub repos from the terminal (gh, dressed). Its own verbs complete # here, with repo names / .gitignore templates / license keys read live through # ghx's cached `--_repos` `--_templates` `--_licenses` feeds. Anything else is a # gh command passed through untouched, so it is handed to gh's own completer # (`_gh`, generated by `gh completion -s zsh`, lives beside this file). _ghx_repos() { local -a r; r=( ${(f)"$(ghx --_repos 2>/dev/null)"} ); _describe -t repos 'repository' r } _ghx_templates() { local -a t; t=( ${(f)"$(ghx --_templates 2>/dev/null)"} ); _describe -t templates '.gitignore template' t } _ghx_licenses() { local -a l; l=( ${(f)"$(ghx --_licenses 2>/dev/null)"} ); _describe -t licenses 'license' l } _ghx_setkeys() { local -a keys=( 'public:visibility' 'private:visibility' 'internal:visibility (org)' 'desc=:description' 'homepage=:homepage URL' 'branch=:default branch' 'topics=:add topics a,b' 'topics+=:add topics' 'topics-=:remove topics' 'issues=:on/off' 'wiki=:on/off' 'projects=:on/off' 'discussions=:on/off' 'merge=:merge commits on/off' 'squash=:squash merge on/off' 'rebase=:rebase merge on/off' 'automerge=:on/off' 'delete-branch=:delete head branch on merge' 'squash-msg=:default | pr-title | pr-title-commits | pr-title-description' 'template=:template repository on/off' 'forking=:org: allow forking' 'update-branch=:org: allow update branch' 'secret-scanning=:on/off' 'push-protection=:on/off' 'advanced-security=:on/off' ) _describe -t keys 'setting' keys -S '' } _ghx() { local -a verbs=( 'new:create a repo — wizard for whatever you leave out' 'url:web / https / ssh URLs + the remote add line' 'remote:add it as a remote here (git or jj), no push' 'ls:your repositories at a glance' 'info:one repo — settings, activity, URLs' 'set:change settings — visibility, topics, features …' 'open:open in the browser' 'clone:gh repo clone, dressed' 'rm:delete on GitHub (asks you to type the name)' 'templates:.gitignore templates for -g' 'licenses:license keys for -l' 'whoami:account, scopes, protocol' 'pick:fzf picker → owner/name' 'help:usage' ) if (( CURRENT == 2 )); then _describe -t verbs 'ghx verb' verbs _dispatch gh gh # gh's own top-level commands join the list return fi case $words[2] in new|create|n|c) _arguments -s \ '(--public --private --internal)--public[anyone can see it]' \ '(--public --private --internal)--private[only you and collaborators]' \ '(--public --private --internal)--internal[members of the organisation]' \ '(-d --desc)'{-d,--desc}'[description]:text:' \ '(-g --gitignore)'{-g,--gitignore}'[.gitignore template]:template:_ghx_templates' \ '(-l --license)'{-l,--license}'[license]:license:_ghx_licenses' \ '--readme[add a README.md]' \ '*'{-t,--topic}'[topics a,b,c]:topics:' \ '--homepage[homepage URL]:url:_urls' \ '--no-issues[disable issues]' '--no-wiki[disable wiki]' \ '(-p --template)'{-p,--template}'[start from a template repo]:repo:_ghx_repos' \ '--include-all-branches[all branches of the template]' \ '--team[org team granted access]:team:' \ '--here[publish this directory (source + remote, no push)]' \ '(-s --source)'{-s,--source}'[source directory]:dir:_files -/' \ '(-r --remote)'{-r,--remote}'[remote name]:name:(origin upstream)' \ '--push[push local commits after --here]' \ '--wire[add as a remote in this directory]' \ '(-c --clone)'{-c,--clone}'[clone it afterwards]' \ '--copy[URL onto the clipboard]' '--open[open in the browser]' \ '--ssh[prefer the ssh URL]' '--https[prefer the https URL]' \ '(-o --org)'{-o,--org}'[owner / organisation]:owner:' \ '(-y --yes)'{-y,--yes}'[no questions]' \ '(-h --help)'{-h,--help}'[help]' \ '1:name:' ;; url|u|link) _arguments -s '--ssh[ssh URL]' '--https[https URL]' '--web[web URL]' '--all[every form]' \ '(-c --copy)'{-c,--copy}'[onto the clipboard]' '1:repo:_ghx_repos' ;; remote|wire|r) _arguments -s '(-r --remote -n --name)'{-r,--remote,-n,--name}'[remote name]:name:(origin upstream)' \ '(-f --force)'{-f,--force}'[replace the URL of an existing remote]' '--ssh[ssh URL]' '--https[https URL]' '1:repo:_ghx_repos' ;; ls|l|list|repos) _arguments -s '(-L --limit)'{-L,--limit}'[how many]:n:' '(-a --all)'{-a,--all}'[up to 1000]' \ '--public' '--private' '--internal' '--fork' '--source' '--archived' '--no-archived' \ '--lang[language]:language:' '(-t --topic)'{-t,--topic}'[topic]:topic:' \ '(-q --grep)'{-q,--grep}'[substring filter]:text:' '1:owner:' ;; info|i|view|show|open|o|browse|web) _arguments '1:repo:_ghx_repos' ;; clone) _arguments '1:repo:_ghx_repos' '2:directory:_files -/' ;; rm|del|delete) _arguments '(-y --yes)'{-y,--yes}'[skip the confirmation]' '1:repo:_ghx_repos' ;; set|s|edit) if (( CURRENT == 3 )); then _alternative 'repos:repository:_ghx_repos' 'keys:setting:_ghx_setkeys' else _ghx_setkeys fi ;; templates|template|gitignore|gi) _ghx_templates ;; help) _values 'topic' new set ;; *) _dispatch gh gh ;; esac } _ghx "$@"