Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2010
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.74 KB | None | 0 0
  1. #compdef packer
  2.  
  3. # copy this file to /usr/share/zsh/site-functions/_packer
  4.  
  5. typeset -A opt_args
  6.  
  7. # options for passing to _arguments: main packer commands
  8. _packer_opts_commands=(
  9.     '-Ss[Search for a package.]:*:search text:->sync_search'
  10.     '-S[Install a package.]'
  11.     '-Syu[Sync with repositories.]'
  12.     '-Si[Show information for a package.]'
  13.         '-G[Just download and extract AUR tarball]'
  14.     '-h[Show packer usage.]'
  15. )
  16.  
  17. # options for passing to _arguments: options common to all commands
  18. _packer_opts_common=(
  19.     '--ignore[Ignore packages listed here.]'
  20.     '--noconfirm[Do not ask user for confirmation.]'
  21.     '--noedit[Do not ask user if he wants to edit files.]'
  22.     '--auronly[Only perform commands for the AUR.]'
  23.     '--devel[Update development packages. (cvs, git, ...)]'
  24.     '--skipinteg[Skip the integrity checks.]'
  25. )
  26.  
  27. # handles cases where no subcommand has yet been given
  28. _packer_action_none() {
  29.     _arguments -s : \
  30.         "$_packer_opts_commands[@]"
  31. }
  32.  
  33. # handles -h subcommand
  34. _packer_action_help() {
  35.     # no further arguments
  36.     return 0
  37. }
  38.  
  39. # handles -S* and -G subcommand
  40. _packer_action_sync() {
  41.     local context state line
  42.     typeset -A opt_args
  43.  
  44.     case $state in
  45.         sync_search)
  46.             _arguments -s : \
  47.                 "$_packer_opts_common[@]" \
  48.                 '*:search text: '
  49.                 ;;
  50.         *)
  51.             _arguments -s : \
  52.                 "$_packer_opts_common[@]" \
  53.                 '*:package:_packer_completions_all_packages'
  54.                 ;;
  55.     esac
  56. }
  57.  
  58. # stolen from zsh-packer written by Phrodo_00
  59. #
  60. # provides completions for packages available from repositories
  61. # these can be specified as either 'package' or 'repository/package'
  62. _packer_completions_all_packages() {
  63.     local -a cmd packages repositories packages_long
  64.  
  65.     repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
  66.     typeset -U repositories
  67.     packages_long=(/var/lib/pacman/sync/${^repositories}/*(/))
  68.     packages=(${(o)${${packages_long/\/var\/lib\/pacman\/sync\//}#*/}%-*-*} )
  69.     typeset -U packages
  70.     _wanted packages expl "packages" compadd - "${(@)packages}"
  71.     if [[ $PREFIX != */* ]] ; then
  72.         repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
  73.         typeset -U repositories
  74.         _wanted repo_packages expl "repository/package" compadd -S "/" $repositories
  75.     else
  76.         compset -P '*/'
  77.         packages_long=(/var/lib/pacman/sync/$IPREFIX*(/))
  78.         packages=(${(o)${${packages_long/\/var\/lib\/pacman\/sync\//}#*/}%-*-*} )
  79.         typeset -U packages
  80.         _wanted repo_packages expl "repository/package" compadd ${(@)packages}
  81.     fi
  82. }
  83.  
  84. # main dispatcher
  85. _packer() {
  86.     case $words[2] in
  87.         -S*)  _packer_action_sync     ;;
  88.         -G*)  _packer_action_sync     ;;
  89.         -h*)  _packer_action_help     ;;
  90.         -  )  _packer_action_none     ;;
  91.         *  )  return 1                ;;
  92.     esac
  93. }
  94.  
  95. # run the main dispatcher
  96. _packer "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement