Compare commits

...

2 Commits

Author SHA1 Message Date
Luka Zeljko
405a4501fc More complete version of zsh autocompletion
All checks were successful
Artools shellcheck / lint (pull_request) Successful in 1m3s
- Mimics bash autocompletion with addition of descriptions of every command and option on tabbing
2025-11-24 14:21:17 +01:00
Luka Zeljko
c2bc4ee01c Rewritten zsh autocompletion script.
- Added all core commands, subcommands and options available in the tooling
- Packages and maintainers now dynamically shown on tabbing
2025-11-23 22:18:06 +01:00

View File

@@ -1,205 +1,748 @@
#compdef artixpkg
#compdef _artixpkg artixpkg
local -a addcmd admincmd cicmd clonecmd configcmd createcmd gitcmd importcmd \
initialcmd maintainercmd movecmd querycmd pullcmd pushcmd removecmd \
repocmd showcmd teamcmd topiccmd transfercmd versioncmd
_regex_words maintainer '' \
'-a' \
'--adopt' \
'-h' \
'--help' \
'-o' \
'--orphan'
maintainercmd=("$reply[@]")
LIBDIR=${LIBDIR:-'@libdir@'}
# LIBDIR='/usr/share/artools/lib'
_regex_words query '' \
'-h' \
'--help' \
'-m' \
'-t'
querycmd=("$reply[@]")
ARTIX_DB=(
"system-goblins"
"system-gremlins"
"system"
"world-goblins"
"world-gremlins"
"world"
"lib32-goblins"
"lib32-gremlins"
"lib32"
"galaxy-goblins"
"galaxy-gremlins"
"galaxy"
)
_regex_words team '' \
'-a' \
'--add' \
'-c' \
'--check' \
'-h' \
'--help' \
'-r' \
'--remove'
teamcmd=("$reply[@]")
ARTIX_DB_MAP=(
"goblins"
"gremlins"
"stable"
)
_regex_words topic '' \
'-a' \
'--add' \
'-d' \
'--delete' \
'-h' \
'--help' \
'-j' \
'--jobs' \
'-r' \
'--remove'
topiccmd=("$reply[@]")
AGENTS=(
"orion"
"taurus"
)
_regex_words transfer '' \
'-h' \
'--help'
transfercmd=("$reply[@]")
ARTIX_TEAMS=(
"system"
"world"
"lib32"
"galaxy"
)
_artixpkg_remotepkgbase() {
curl -s "https://checkupdates.artixlinux.org/api/1.0/packages?startswith=$1"
}
_artixpkg_maintainers() {
curl -s "https://checkupdates.artixlinux.org/api/1.0/maintainers"
}
_artixpkg_pkgbase() {
source "${LIBDIR}/pkg/util.sh"
ls -1 "${TREE_DIR_ARTIX}" | tr '\n' ' '
}
function _artixpkg { # DONE
_arguments -C \
'1:command:->subcmd' \
'*::args:->args'
case $state in
subcmd)
local -a subcmds
subcmds=(
"--help:Show help text"
"-h:Show help text"
"admin:Manage topics, teams and obsolete repos"
"git:Manage Git packaging repositories and their configuration"
"repo:Pacman database modification for package updates, moves, etc."
"version:Show artixpkg version information"
)
_describe 'command' subcmds
return
;;
args)
case $words[1] in
admin)
_admin
;;
git)
_git
;;
repo)
_repo
;;
version)
_arguments \
'-h[Show help text]' \
'--help[Show help text]'
;;
esac
;;
esac
}
_admin() { #DONE
local state
_arguments -C \
'1:admin-cmd:->admin-subcmd' \
'*::admin-arg:->admin-args'
case $state in
admin-subcmd)
local -a admin_subcommands
admin_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"maintainer:Manage repo maintainer"
"query:Query maintainers and topics"
"team:Manage repo team"
"topic:Manage topics"
"transfer:Transfer obsolete repository to landfill"
)
_describe 'admin-cmd' admin_subcommands
return
;;
admin-args)
case $words[1] in
maintainer)
_admin_maintainer
;;
query)
_admin_query
;;
team)
_admin_team
;;
topic)
_admin_topic
;;
transfer)
admin_transfer
;;
esac
;;
esac
}
_git() { # DONE
local state
_arguments \
'1:git-cmd:->git-subcmd' \
'*::git-arg:->git-args'
case $state in
git-subcmd)
local -a git_subcommands
git_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"clone:Clone a package repository"
"config:Configure a clone according to artix specs"
"create:Create a new Gitea package repository"
"pull:Pull a package repository"
"push:Push a package repository"
)
_describe 'git-cmd' git_subcommands
return
;;
git-args)
case $words[1] in
clone)
_git_clone
;;
config)
_git_config
;;
create)
_git_create
;;
pull)
_git_pull
;;
push)
_git_push
;;
esac
;;
esac
}
_repo() { # DONE
local state
_arguments \
'1:repo-cmd:->repo-subcmd' \
'*::repo-arg:->repo-args'
case $state in
repo-subcmd)
local -a repo_subcommands
repo_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"add:Add built pkgbase to repo"
"move:Move built pkgbase between repos"
"remove:Remove built pkgbase from repo"
"import:Import latest tag from arch upstream"
"show:Show the pkgbase's repo db"
)
_describe 'repo-cmd' repo_subcommands
;;
repo-args)
case $words[1] in
add)
_repo_add
;;
move)
_repo_move
;;
remove)
_repo_remove
;;
import)
_repo_import
;;
show)
_repo_show
;;
esac
;;
esac
}
_admin_maintainer() { # DONE
local state
_arguments \
'1:maintainer-cmd:->maintainer-subcmd' \
'*::maintainer-arg:->maintainer-args'
case $state in
maintainer-subcmd)
local -a maintainer_subcommands
maintainer_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--adopt:Adopt repo"
"-a:Adopt repo"
"--orphan:Orphan repo"
"-o:Orphan repo"
)
_describe 'maintainer-cmd' maintainer_subcommands
;;
maintainer-args)
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
case $words[1] in
--adopt|-a|--orphan|-o)
_describe 'locals-cmd' localpkgs
;;
esac
;;
esac
}
_admin_query() { # DONE
local state
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
local -a query_subcommands
query_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--maintainer:Query for packages of the named maintainer"
"-m:Query for packages of the named maintainer"
"--topic:Query for packages of the named topic"
"-t:Query for packages of the named topic"
)
_arguments \
'1:query-cmd:->query-subcmd' \
'*::query-arg:->query-args'
case $state in
query-subcmd)
_describe 'query-cmd' query_subcommands -- localpkgs
;;
query-args)
local -a maintainers
maintainers=("${(z)$(_artixpkg_maintainers)}")
if [[ ${words[CURRENT-1]} == "-m" || ${words[CURRENT-1]} == "--maintainer" ]] then
_describe 'maintainers-cmd' maintainers
elif [[ ${words[CURRENT-1]} == "-t" || ${words[CURRENT-1]} == "--topic" ]] then
return 0
else
_describe 'query-cmd' query_subcommands -- localpkgs
fi
;;
esac;
}
_admin_team() { # DONE
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
local state
local -a team_subcommands
team_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--check:Check if team is assigned"
"-c:Check if team is assigned"
"--list:List repo teams"
"-l:List repo teams"
"--add:Add team to repo"
"-a:Add team to repo"
"--remove:Remove team from repo"
"-r:Remove team from repo"
)
_arguments \
'1:team-cmd:->team-subcmd' \
'*::team-arg:->team-args'
case $state in
team-subcmd)
_describe 'team-cmd' team_subcommands -- localpkgs
;;
team-args)
local -a maintainers
maintainers=("${(z)$(_artixpkg_maintainers)}")
if [[ ${words[CURRENT-1]} == "-a" || ${words[CURRENT-1]} == "--add" || ${words[CURRENT-1]} == "-r" || ${words[CURRENT-1]} == "--remove" ]] then
_describe 'elses cmd' ARTIX_TEAMS
else
_describe 'query-cmd' team_subcommands -- localpkgs
fi
;;
esac
}
_admin_topic() { # DONE
local state
local -a localpkgs
local -a topic_subcommands
topic_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--add:Add a topic to repo"
"-a:Add a topic to repo"
"--remove:Remove a topic from repo"
"-r:Remove a topic from repo"
"--delete:Delete all topics from repo"
"-d:Delete all topics from repo"
"--jobs:Run up to N jobs in parallel (default: 4)"
"-j:Run up to N jobs in parallel (default: 4)"
)
localpkgs=(${(z)$(_artixpkg_pkgbase)})
_arguments \
'1:topic-cmd:->topic-subcmd' \
'*::topic-arg:->topic-args'
case $state in
topic-subcmd)
_describe 'topic-cmd' topic_subcommands -- localpkgs
;;
topic-args)
if [[ ${words[CURRENT-1]} == "-j" || ${words[CURRENT-1]} == "--jobs" || ${words[CURRENT-1]} == "-h" || ${words[CURRENT-1]} == "--help" || ${words[CURRENT-1]} == "-a" || ${words[CURRENT-1]} == "--add" || ${words[CURRENT-1]} == "-r" || ${words[CURRENT-1]} == "--remove" || ${words[CURRENT-1]} == "-d" || ${words[CURRENT-1]} == "--delete" ]] then
return 0
else
_describe 'topic-cmd' topic_subcommands -- localpkgs
fi
;;
esac
}
_regex_words admin '' \
'-h:Help text' \
'--help:Help text' \
'maintainer:Manage repo maintainer:$maintainercmd' \
'query:Query maintainers and topics:$querycmd' \
'team:Manage repo team:$teamcmd' \
'topic:Manage topics:$topiccmd' \
'transfer:Transfer obsolete repositories to landfill:$transfercmd'
admincmd=("$reply[@]")
admin_transfer() { # DONE
local state
local -a transfer_subcommands
transfer_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
)
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
_regex_words ci '' \
'-a' \
'--agent' \
'-h' \
'--help'
cicmd=("$reply[@]")
_arguments \
'1:transfer-cmd:->transfer-subcmd' \
'*::transfer-arg:->transfer-args'
_regex_words clone '' \
'-a' \
'--agent' \
'--all' \
'-h' \
'--help' \
'-j' \
'--jobs' \
'-m' \
'--maintainer' \
'--protocol' \
'-s' \
'--search' \
'-t' \
'--team'
clonecmd=("$reply[@]")
case $state in
transfer-subcmd)
_describe 'transfer-cmd' transfer_subcommands -- localpkgs
;;
transfer-args)
case $words[@] in
*)
_describe 'transfer_else-cmd' transfer_subcommands -- localpkgs
;;
esac
;;
esac
}
_regex_words config '' \
'-h' \
'--help' \
'-j' \
'--jobs' \
'--protocol'
configcmd=("$reply[@]")
_git_clone() { # DONE
local state
local -a remotepkgs
local -a clone_subcommands
clone_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--maintainer:Clone all packages of the named maintainer"
"-m:Clone all packages of the named maintainer"
"--search:Clone all packages of the named topic"
"-s:Clone all packages of the named topic"
"--team:Assign team name (default: world)"
"-t:Assign team name (default: world)"
"--jobs:Run up to N jobs in parallel (default: 4)"
"-j:Run up to N jobs in parallel (default: 4)"
"--protocol https:Clone the repository over https"
"--all:Clone all existing packages, useful for cache warming"
)
_regex_words create '' \
'-a' \
'--agent' \
'-c' \
'--create' \
'-h' \
'--help' \
'-t' \
'--team'
createcmd=("$reply[@]")
_arguments \
'1:clone-cmd:->clone-subcmd' \
'*::clone-arg:->clone-args'
_regex_words pull '' \
'--all' \
'-h' \
'--help' \
'-j' \
'--jobs' \
'-m' \
'--maintainer' \
'-t' \
'--topic'
pullcmd=("$reply[@]")
case $state in
clone-subcmd)
remotepkgs=(${(z)$(_artixpkg_remotepkgbase)})
_regex_words push '' \
'-h' \
'--help' \
'-j' \
'--jobs' \
'-m' \
'--maintainer' \
'-t' \
'--topic'
pushcmd=("$reply[@]")
_describe 'clone-cmd' clone_subcommands -- remotepkgs
;;
clone-args)
case $words[@] in
*)
remotepkgs=(${(z)$(_artixpkg_remotepkgbase)})
_describe 'cloneall-cmd' clone_subcommands -- remotepkgs
;;
esac
;;
esac
}
_regex_words git '' \
'ci:Configure CI agent:$cicmd' \
'clone:Clone a package:$clonecmd' \
'config:Configure a clone:$configcmd' \
'create:Create a new gitea package repository:$createcmd' \
'-h:Help text' \
'--help:Help text' \
'pull:Pull a package repository:$pullcmd' \
'push:Push a package repository:$pushcmd'
gitcmd=("$reply[@]")
_git_config() { # DONE
local state
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
local -a config_subcommands
config_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--jobs:Run up to N jobs in parallel (default: 4)"
"-j:Run up to N jobs in parallel (default: 4)"
"--protocol:Configure remote url to use https"
)
_regex_words add '' \
'-h' \
'--help' \
'-n' \
'--nocheck' \
'-p' \
'--push' \
'-r' \
'--rebuild'
addcmd=("$reply[@]")
_arguments \
'1:config-cmd:->config-subcmd' \
'*::config-arg:->config-args'
_regex_words import '' \
'--del' \
'-h' \
'--help' \
'--tag'
importcmd=("$reply[@]")
case $state in
config-subcmd)
_describe 'config-cmd' config_subcommands -- localpkgs
;;
config-args)
if [[ ${words[CURRENT-1]} == "--protocol" ]] then
all_completions=(
'https:HTTPS protocol'
)
_describe 'protocl val' all_completions
elif [[ ${words[CURRENT-1]} == "-j" || ${words[CURRENT-1]} == "--jobs" ]] then
return 0
else
_describe 'localpkgs-cmd' config_subcommands -- localpkgs
fi
;;
esac
}
_regex_words move '' \
'-h' \
'--help' \
'-p' \
'--push'
movecmd=("$reply[@]")
_git_create() { # DONE
local state
local -a create_subcommands
create_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--clone:Clone the Git repository after creation"
"-c:Clone the Git repository after creation"
"--team:Assign team name (default: world)"
"-t:Assign team name (default: world)"
)
_regex_words remove '' \
'-h' \
'--help' \
'-p' \
'--push'
removecmd=("$reply[@]")
_arguments \
'1:create-cmd:->create-subcmd' \
'*::create-arg:->create-args'
_regex_words show '' \
'-b' \
'--base' \
'-h' \
'--help' \
'-p' \
'--pkgs'
showcmd=("$reply[@]")
case $state in
create-subcmd)
_describe 'create-cmd' create_subcommands
;;
create-args)
if [[ ${words[CURRENT-1]} == "-t" || ${words[CURRENT-1]} == "--topic" ]] then
_describe 'teams-cmd' ARTIX_TEAMS
else
_describe 'create-cmd' create_subcommands
fi
esac
}
_regex_words repo '' \
'add:Add pkgbase to repo:$addcmd' \
'-h:Help text' \
'--help:Help text' \
'import:Import latest tag from arch upstream:$importcmd' \
'move:Move pkgbase between repos:$movecmd' \
'remove:Remove pkgbase from repo:$removecmd' \
'show:Show pkgbase repo db:$showcmd'
repocmd=("$reply[@]")
_git_pull() { # DONE
local state
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
local -a pull_subcommands
pull_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--maintainer:Pull all packages of the named maintainer"
"-m:Pull all packages of the named maintainer"
"--topic:Pull all packages of the named topic"
"-t:Pull all packages of the named topic"
"--jobs:Run up to N jobs in parallel (default: 4)"
"-j:Run up to N jobs in parallel (default: 4)"
"--all:Pull all existing packages"
)
_regex_words version '' \
'-h' \
'--help'
versioncmd=("$reply[@]")
_arguments \
'1:pull-cmd:->pull-subcmd' \
'*::pull-arg:->pull-args'
_regex_words initial '' \
'admin:Manage topics:$admincmd' \
'git:Manage git:$gitcmd' \
'-h:Help text' \
'--help:Help text' \
'repo:Pacman database modification:$repocmd' \
'version:Show artixpkg version:$versioncmd'
initialcmd=("$reply[@]")
case $state in
pull-subcmd)
_describe 'pull-cmd' pull_subcommands -- localpkgs
;;
pull-args)
if [[ ${words[CURRENT-1]} == "--all" ]] then
return 0
elif [[ ${words[CURRENT-1]} == "-m" || ${words[CURRENT-1]} == "--maintainer" ]] then
local -a maintainers
maintainers=("${(z)$(_artixpkg_maintainers)}")
_describe 'maintainers-cmd' maintainers
elif [[ ${words[CURRENT-1]} == "-j" || ${words[CURRENT-1]} == "--jobs" || ${words[CURRENT-1]} == "-t" || ${words[CURRENT-1]} == "--topic" ]] then
return 0
else
_describe 'pull-cmd' pull_subcommands -- localpkgs
fi
;;
esac
}
_git_push() {
local state
local -a push_subcommands
push_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--maintainer:Push all packages of the named maintainer"
"-m:Push all packages of the named maintainer"
"--topic:Push all packages of the named topic"
"-t:Push all packages of the named topic"
)
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
_arguments \
'1:push-cmd:->push-subcmd' \
'*::push-arg:->push-args'
case $state in
push-subcmd)
_describe 'push-cmd' push_subcommands -- localpkgs
;;
push-args)
if [[ ${words[CURRENT-1]} == "-m" || ${words[CURRENT-1]} == "--maintainer" ]] then
local -a maintainers
maintainers=("${(z)$(_artixpkg_maintainers)}")
_describe 'maintainers-cmd' maintainers
elif [[ ${words[CURRENT-1]} == "-t" || ${words[CURRENT-1]} == "--topic" ]] then
return 0
else
_describe 'push-cmd' push_subcommands -- localpkgs
fi
;;
esac
}
_repo_add() { # DONE
local state
local -a add_subcommands
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
local -a combined_db
combined_db=("${ARTIX_DB[@]}" "${ARTIX_DB_MAP[@]}")
add_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--push:Push pkgbase"
"-p:Push pkgbase"
"--rebuild:Triggers a rebuild"
"-r:Triggers a rebuild"
"--nocheck:Disable the check function"
"-n:Disable the check function"
"--agent:Set the CI agent"
"-a:Set the CI agent"
)
_arguments \
'1:add-cmd:->add-subcmd' \
'*::add-arg:->add-args'
case $state in
add-subcmd)
_describe 'add_cmd' add_subcommands -- ARTIX_DB -- ARTIX_DB_MAP
;;
add-args)
intersections=(${words:*combined_db})
if [[ ${words[CURRENT-1]} == "-a" || ${words[CURRENT-1]} == "--agent" ]] then
_describe 'add_cmd' AGENTS
elif [[ ${#intersections} > 0 ]] then
_describe 'push-cmd' add_subcommands -- localpkgs
else
_describe 'add_cmd' add_subcommands -- combined_db
fi
;;
esac
}
_repo_move() { # DONE
local state
local -a move_subcommands
local -a intersections
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
move_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--push:Push pkgbase"
"-p:Push pkgbase"
"--agent:Set the CI agent"
"-a:Set the CI agent"
)
local -a combined_db
combined_db=("${ARTIX_DB[@]}" "${ARTIX_DB_MAP[@]}")
_arguments \
'1:move-cmd:->move-subcmd' \
'*::move-arg:->move-args'
case $state in
move-subcmd)
_describe 'move_cmd' move_subcommands -- ARTIX_DB -- ARTIX_DB_MAP
;;
move-args)
intersections=(${words:*combined_db})
if [[ ${words[CURRENT-1]} == "-a" || ${words[CURRENT-1]} == "--agent" ]] then
_describe 'add_cmd' AGENTS
elif (( ${#intersections} > 1 )) then
_describe 'push-cmd' move_subcommands -- localpkgs
else
_describe 'add_cmd' move_subcommands -- ARTIX_DB -- ARTIX_DB_MAP
fi
;;
esac
}
_repo_remove() { # DONE
local state
local -a remove_subcommands
local -a intersections
remove_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--push:Push pkgbase"
"-p:Push pkgbase"
"--agent:Set the CI agent"
"-a:Set the CI agent"
)
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
local -a combined_db
combined_db=("${ARTIX_DB[@]}" "${ARTIX_DB_MAP[@]}")
_arguments \
'1:remove-cmd:->remove-subcmd' \
'*::remove-arg:->remove-args'
case $state in
remove-subcmd)
_describe 'remove_cmd' remove_subcommands -- combined_db
;;
remove-args)
intersections=(${words:*combined_db})
if [[ ${words[CURRENT-1]} == "-a" || ${words[CURRENT-1]} == "--agent" ]] then
_describe 'add_cmd' AGENTS
elif [[ ${#intersections} > 0 ]] then
_describe 'push-cmd' remove_subcommands -- localpkgs
else
_describe 'add_cmd' remove_subcommands -- combined_db
fi
;;
esac
}
_repo_import() {
local state
local -a import_subcommands
import_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--tag:Switch the current workspace to a specified version tag"
"--del:Delete files before rsync import"
"--no-patch:No patch import"
"-n:No patch import"
)
local -a localpkgs
localpkgs=(${(z)$(_artixpkg_pkgbase)})
_arguments \
'1:import-cmd:->import-subcmd' \
'*::import-arg:->import-args'
case $state in
import-subcmd)
_describe 'import-cmd' import_subcommands -- localpkgs
;;
import-args)
if [[ ${words[CURRENT-1]} == "--tag" || ${words[CURRENT-1]} == "-tag" ]] then
return 0
else
_describe 'import-cmd' import_subcommands -- localpkgs
fi
;;
esac
}
_repo_show() {
local state
_arguments \
'1:show-cmd:->show-subcmd' \
'*::show-arg:->show-args'
case $state in
*)
local -a show_subcommands
show_subcommands=(
"-h:Show this help text"
"--help:Show this help text"
"--base:Show srcinfo base"
"-b:Show srcinfo base"
"--pkgs:Show srcinfo pkgs"
"-p:Show srcinfo pkgs"
)
_describe 'show-cmd' show_subcommands
;;
esac
}
_regex_arguments _artixpkg /$'[^\0]##\0'/ "${initialcmd[@]}"
_artixpkg "$@"