Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #compdef packer
- # copy this file to /usr/share/zsh/site-functions/_packer
- typeset -A opt_args
- # options for passing to _arguments: main packer commands
- _packer_opts_commands=(
- '-Ss[Search for a package.]:*:search text:->sync_search'
- '-S[Install a package.]'
- '-Syu[Sync with repositories.]'
- '-Si[Show information for a package.]'
- '-G[Just download and extract AUR tarball]'
- '-h[Show packer usage.]'
- )
- # options for passing to _arguments: options common to all commands
- _packer_opts_common=(
- '--ignore[Ignore packages listed here.]'
- '--noconfirm[Do not ask user for confirmation.]'
- '--noedit[Do not ask user if he wants to edit files.]'
- '--auronly[Only perform commands for the AUR.]'
- '--devel[Update development packages. (cvs, git, ...)]'
- '--skipinteg[Skip the integrity checks.]'
- )
- # handles cases where no subcommand has yet been given
- _packer_action_none() {
- _arguments -s : \
- "$_packer_opts_commands[@]"
- }
- # handles -h subcommand
- _packer_action_help() {
- # no further arguments
- return 0
- }
- # handles -S* and -G subcommand
- _packer_action_sync() {
- local context state line
- typeset -A opt_args
- case $state in
- sync_search)
- _arguments -s : \
- "$_packer_opts_common[@]" \
- '*:search text: '
- ;;
- *)
- _arguments -s : \
- "$_packer_opts_common[@]" \
- '*:package:_packer_completions_all_packages'
- ;;
- esac
- }
- # stolen from zsh-packer written by Phrodo_00
- #
- # provides completions for packages available from repositories
- # these can be specified as either 'package' or 'repository/package'
- _packer_completions_all_packages() {
- local -a cmd packages repositories packages_long
- repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
- typeset -U repositories
- packages_long=(/var/lib/pacman/sync/${^repositories}/*(/))
- packages=(${(o)${${packages_long/\/var\/lib\/pacman\/sync\//}#*/}%-*-*} )
- typeset -U packages
- _wanted packages expl "packages" compadd - "${(@)packages}"
- if [[ $PREFIX != */* ]] ; then
- repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
- typeset -U repositories
- _wanted repo_packages expl "repository/package" compadd -S "/" $repositories
- else
- compset -P '*/'
- packages_long=(/var/lib/pacman/sync/$IPREFIX*(/))
- packages=(${(o)${${packages_long/\/var\/lib\/pacman\/sync\//}#*/}%-*-*} )
- typeset -U packages
- _wanted repo_packages expl "repository/package" compadd ${(@)packages}
- fi
- }
- # main dispatcher
- _packer() {
- case $words[2] in
- -S*) _packer_action_sync ;;
- -G*) _packer_action_sync ;;
- -h*) _packer_action_help ;;
- - ) _packer_action_none ;;
- * ) return 1 ;;
- esac
- }
- # run the main dispatcher
- _packer "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement