#compdef glx
# glx — GitLab repos from the terminal (glab, dressed). Its own verbs complete
# here, with project paths / .gitignore templates / license keys / groups read
# live through glx's cached `--_repos` `--_templates` `--_licenses` `--_groups`
# feeds. Anything else is a glab command passed through untouched, so it is
# handed to glab's own completer (`_glab`, generated by `glab completion -s
# zsh`, lives beside this file).
_glx_repos() { local -a r; r=( ${(f)"$(glx --_repos 2>/dev/null)"} ); _describe -t repos 'project' r }
_glx_templates() { local -a t; t=( ${(f)"$(glx --_templates 2>/dev/null)"} ); _describe -t templates '.gitignore template' t }
_glx_licenses() { local -a l; l=( ${(f)"$(glx --_licenses 2>/dev/null)"} ); _describe -t licenses 'license' l }
_glx_groups() { local -a g; g=( ${(f)"$(glx --_groups 2>/dev/null)"} ); _describe -t groups 'group' g }
_glx_setkeys() {
local -a keys=(
'public:visibility' 'private:visibility' 'internal:visibility'
'desc=:description' 'name=:display name' 'path=:rename the URL path' 'branch=:default branch'
'topics=:replace topics a,b' 'topics+=:add topics' 'topics-=:remove topics'
'issues=:on/off/members' 'wiki=:on/off/members' 'mr=:merge requests on/off/members'
'ci=:CI/CD on/off/members' 'snippets=:on/off/members' 'pages=:on/off/members'
'registry=:container registry' 'packages=:package registry' 'releases=:on/off/members'
'forking=:on/off/members' 'analytics=:on/off/members' 'environments=:on/off/members'
'lfs=:on/off' 'requests=:access requests on/off' 'shared-runners=:on/off'
'method=:merge | ff | rebase' 'squash=:never | always | on | off'
'delete-branch=:remove source branch after merge' 'pipeline-must-pass=:on/off'
'threads-resolved=:on/off' 'archive:read-only' 'unarchive:writable again'
'raw\:=:any /projects field, as-is'
)
_describe -t keys 'setting' keys -S ''
}
_glx() {
local -a verbs=(
'new:create a project — 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 projects at a glance'
'info:one project — settings, activity, URLs'
'set:change settings — visibility, topics, features, merging …'
'open:open in the browser'
'clone:git clone by the preferred URL'
'rm:schedule deletion (--now: permanent)'
'restore:bring back a project scheduled for deletion'
'templates:.gitignore templates for -g'
'licenses:license keys for -l'
'whoami:account, host, protocol'
'pick:fzf picker → group/name'
'help:usage'
)
if (( CURRENT == 2 )); then
_describe -t verbs 'glx verb' verbs
_dispatch glab glab # glab'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 members]' \
'(--public --private --internal)--internal[any signed-in user]' \
'(-d --desc)'{-d,--desc}'[description]:text:' \
'(-g --gitignore)'{-g,--gitignore}'[.gitignore template]:template:_glx_templates' \
'(-l --license)'{-l,--license}'[license]:license:_glx_licenses' \
'--readme[add a README.md]' \
'*'{-t,--topic}'[topics a,b,c]:topics:' \
'(-b --branch)'{-b,--branch}'[default branch]:branch:(main master trunk)' \
'--no-issues[disable issues]' '--no-wiki[disable wiki]' \
'(-G --group)'{-G,--group}'[create under a group]:group:_glx_groups' \
'--here[publish this directory (empty project + remote, no push)]' \
'(-s --source)'{-s,--source}'[source directory]:dir:_files -/' \
'(-r --remote)'{-r,--remote}'[remote name]:name:(origin gitlab 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]' \
'(-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:_glx_repos' ;;
remote|wire|r)
_arguments -s '(-r --remote -n --name)'{-r,--remote,-n,--name}'[remote name]:name:(origin gitlab upstream)' \
'(-f --force)'{-f,--force}'[replace the URL of an existing remote]' '--ssh[ssh URL]' '--https[https URL]' '1:repo:_glx_repos' ;;
ls|l|list|repos)
_arguments -s '(-L --limit)'{-L,--limit}'[how many]:n:' '(-a --all)'{-a,--all}'[up to 1000]' \
'(-m --member)'{-m,--member}'[every project you are a member of]' '--starred[starred projects]' \
'--public' '--private' '--internal' '--archived' '--no-archived' \
'(-q --search)'{-q,--search}'[search by name]:text:' '1:group:_glx_groups' ;;
info|i|view|show|open|o|browse|web)
_arguments '1:repo:_glx_repos' ;;
clone)
_arguments '1:repo:_glx_repos' '2:directory:_files -/' ;;
rm|del|delete)
_arguments '(-y --yes)'{-y,--yes}'[skip the confirmation]' '--now[delete permanently, at once]' '1:repo:_glx_repos' ;;
restore|undelete)
_arguments '1:repo:' ;;
set|s|edit)
if (( CURRENT == 3 )); then
_alternative 'repos:project:_glx_repos' 'keys:setting:_glx_setkeys'
else
_glx_setkeys
fi ;;
templates|template|gitignore|gi)
_glx_templates ;;
help)
_values 'topic' new set ;;
*)
_dispatch glab glab ;;
esac
}
_glx "$@"