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 \ LIBDIR=${LIBDIR:-'@libdir@'}
initialcmd maintainercmd movecmd querycmd pullcmd pushcmd removecmd \ # LIBDIR='/usr/share/artools/lib'
repocmd showcmd teamcmd topiccmd transfercmd versioncmd
_regex_words maintainer '' \
'-a' \
'--adopt' \
'-h' \
'--help' \
'-o' \
'--orphan'
maintainercmd=("$reply[@]")
_regex_words query '' \ ARTIX_DB=(
'-h' \ "system-goblins"
'--help' \ "system-gremlins"
'-m' \ "system"
'-t' "world-goblins"
querycmd=("$reply[@]") "world-gremlins"
"world"
"lib32-goblins"
"lib32-gremlins"
"lib32"
"galaxy-goblins"
"galaxy-gremlins"
"galaxy"
)
_regex_words team '' \ ARTIX_DB_MAP=(
'-a' \ "goblins"
'--add' \ "gremlins"
'-c' \ "stable"
'--check' \ )
'-h' \
'--help' \
'-r' \
'--remove'
teamcmd=("$reply[@]")
_regex_words topic '' \ AGENTS=(
'-a' \ "orion"
'--add' \ "taurus"
'-d' \ )
'--delete' \
'-h' \
'--help' \
'-j' \
'--jobs' \
'-r' \
'--remove'
topiccmd=("$reply[@]")
_regex_words transfer '' \ ARTIX_TEAMS=(
'-h' \ "system"
'--help' "world"
transfercmd=("$reply[@]") "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 '' \ admin_transfer() { # DONE
'-h:Help text' \ local state
'--help:Help text' \ local -a transfer_subcommands
'maintainer:Manage repo maintainer:$maintainercmd' \ transfer_subcommands=(
'query:Query maintainers and topics:$querycmd' \ "-h:Show this help text"
'team:Manage repo team:$teamcmd' \ "--help:Show this help text"
'topic:Manage topics:$topiccmd' \ )
'transfer:Transfer obsolete repositories to landfill:$transfercmd' local -a localpkgs
admincmd=("$reply[@]") localpkgs=(${(z)$(_artixpkg_pkgbase)})
_regex_words ci '' \ _arguments \
'-a' \ '1:transfer-cmd:->transfer-subcmd' \
'--agent' \ '*::transfer-arg:->transfer-args'
'-h' \
'--help'
cicmd=("$reply[@]")
_regex_words clone '' \ case $state in
'-a' \ transfer-subcmd)
'--agent' \ _describe 'transfer-cmd' transfer_subcommands -- localpkgs
'--all' \ ;;
'-h' \ transfer-args)
'--help' \ case $words[@] in
'-j' \ *)
'--jobs' \ _describe 'transfer_else-cmd' transfer_subcommands -- localpkgs
'-m' \ ;;
'--maintainer' \ esac
'--protocol' \ ;;
'-s' \ esac
'--search' \ }
'-t' \
'--team'
clonecmd=("$reply[@]")
_regex_words config '' \ _git_clone() { # DONE
'-h' \ local state
'--help' \ local -a remotepkgs
'-j' \ local -a clone_subcommands
'--jobs' \ clone_subcommands=(
'--protocol' "-h:Show this help text"
configcmd=("$reply[@]") "--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 '' \ _arguments \
'-a' \ '1:clone-cmd:->clone-subcmd' \
'--agent' \ '*::clone-arg:->clone-args'
'-c' \
'--create' \
'-h' \
'--help' \
'-t' \
'--team'
createcmd=("$reply[@]")
_regex_words pull '' \ case $state in
'--all' \ clone-subcmd)
'-h' \ remotepkgs=(${(z)$(_artixpkg_remotepkgbase)})
'--help' \
'-j' \
'--jobs' \
'-m' \
'--maintainer' \
'-t' \
'--topic'
pullcmd=("$reply[@]")
_regex_words push '' \ _describe 'clone-cmd' clone_subcommands -- remotepkgs
'-h' \ ;;
'--help' \ clone-args)
'-j' \ case $words[@] in
'--jobs' \ *)
'-m' \ remotepkgs=(${(z)$(_artixpkg_remotepkgbase)})
'--maintainer' \ _describe 'cloneall-cmd' clone_subcommands -- remotepkgs
'-t' \ ;;
'--topic' esac
pushcmd=("$reply[@]") ;;
esac
}
_regex_words git '' \ _git_config() { # DONE
'ci:Configure CI agent:$cicmd' \ local state
'clone:Clone a package:$clonecmd' \ local -a localpkgs
'config:Configure a clone:$configcmd' \ localpkgs=(${(z)$(_artixpkg_pkgbase)})
'create:Create a new gitea package repository:$createcmd' \ local -a config_subcommands
'-h:Help text' \ config_subcommands=(
'--help:Help text' \ "-h:Show this help text"
'pull:Pull a package repository:$pullcmd' \ "--help:Show this help text"
'push:Push a package repository:$pushcmd' "--jobs:Run up to N jobs in parallel (default: 4)"
gitcmd=("$reply[@]") "-j:Run up to N jobs in parallel (default: 4)"
"--protocol:Configure remote url to use https"
)
_regex_words add '' \ _arguments \
'-h' \ '1:config-cmd:->config-subcmd' \
'--help' \ '*::config-arg:->config-args'
'-n' \
'--nocheck' \
'-p' \
'--push' \
'-r' \
'--rebuild'
addcmd=("$reply[@]")
_regex_words import '' \ case $state in
'--del' \ config-subcmd)
'-h' \ _describe 'config-cmd' config_subcommands -- localpkgs
'--help' \ ;;
'--tag' config-args)
importcmd=("$reply[@]") 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 '' \ _git_create() { # DONE
'-h' \ local state
'--help' \ local -a create_subcommands
'-p' \ create_subcommands=(
'--push' "-h:Show this help text"
movecmd=("$reply[@]") "--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 '' \ _arguments \
'-h' \ '1:create-cmd:->create-subcmd' \
'--help' \ '*::create-arg:->create-args'
'-p' \
'--push'
removecmd=("$reply[@]")
_regex_words show '' \ case $state in
'-b' \ create-subcmd)
'--base' \ _describe 'create-cmd' create_subcommands
'-h' \ ;;
'--help' \ create-args)
'-p' \ if [[ ${words[CURRENT-1]} == "-t" || ${words[CURRENT-1]} == "--topic" ]] then
'--pkgs' _describe 'teams-cmd' ARTIX_TEAMS
showcmd=("$reply[@]") else
_describe 'create-cmd' create_subcommands
fi
esac
}
_regex_words repo '' \ _git_pull() { # DONE
'add:Add pkgbase to repo:$addcmd' \ local state
'-h:Help text' \ local -a localpkgs
'--help:Help text' \ localpkgs=(${(z)$(_artixpkg_pkgbase)})
'import:Import latest tag from arch upstream:$importcmd' \ local -a pull_subcommands
'move:Move pkgbase between repos:$movecmd' \ pull_subcommands=(
'remove:Remove pkgbase from repo:$removecmd' \ "-h:Show this help text"
'show:Show pkgbase repo db:$showcmd' "--help:Show this help text"
repocmd=("$reply[@]") "--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 '' \ _arguments \
'-h' \ '1:pull-cmd:->pull-subcmd' \
'--help' '*::pull-arg:->pull-args'
versioncmd=("$reply[@]")
_regex_words initial '' \ case $state in
'admin:Manage topics:$admincmd' \ pull-subcmd)
'git:Manage git:$gitcmd' \ _describe 'pull-cmd' pull_subcommands -- localpkgs
'-h:Help text' \ ;;
'--help:Help text' \ pull-args)
'repo:Pacman database modification:$repocmd' \ if [[ ${words[CURRENT-1]} == "--all" ]] then
'version:Show artixpkg version:$versioncmd' return 0
initialcmd=("$reply[@]") 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 "$@" _artixpkg "$@"