Advertisement
Guest User

Untitled

a guest
Aug 27th, 2011
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. #compdef packer packer.static=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.]:package:_packer_completions_all_packages'
  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 --sync subcommand
  34. _packer_action_sync() {
  35. local context state line
  36. typeset -A opt_args
  37.  
  38. # _arguments -s : \
  39. # "$_packer_opts_common[@]" \
  40. # "$_packer_opts_sync_actions[@]" #\
  41. # #"$_packer_opts_sync_modifiers[@]"
  42.  
  43. case $state in
  44. sync_search)
  45. _arguments -s : \
  46. "$_packer_opts_common[@]" \
  47. '*:search text: '
  48. ;;
  49. *)
  50. _arguments -s : \
  51. "$_packer_opts_common[@]" \
  52. '*:package:_packer_completions_all_packages'
  53. ;;
  54. esac
  55. }
  56.  
  57. # provides completions for package groups
  58. _packer_completions_all_groups() {
  59. local -a cmd groups
  60. _packer_get_command
  61. groups=( $(_call_program groups $cmd[@] -Sg) )
  62. typeset -U groups
  63. compadd "$@" -a groups
  64. }
  65.  
  66. # provides completions for packages available from repositories
  67. # these can be specified as either 'package' or 'repository/package'
  68. _packer_completions_all_packages() {
  69. local -a cmd packages repositories packages_long
  70. _packer_get_command
  71.  
  72. if compset -P1 '*/*'; then
  73. packages=( $(_call_program packages $cmd[@] -Sql ${words[CURRENT]%/*}) )
  74. typeset -U packages
  75. _wanted repo_packages expl "repository/package" compadd ${(@)packages}
  76. else
  77. packages=( $(_call_program packages $cmd[@] -Sql) )
  78. typeset -U packages
  79. _wanted packages expl "packages" compadd - "${(@)packages}"
  80.  
  81. repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
  82. typeset -U repositories
  83. _wanted repo_packages expl "repository/package" compadd -S "/" $repositories
  84. fi
  85. }
  86.  
  87. # provides completions for package groups
  88. _packer_completions_installed_groups() {
  89. local -a cmd groups
  90. _packer_get_command
  91. groups=(${(o)${(f)"$(_call_program groups $cmd[@] -Qg)"}% *})
  92. typeset -U groups
  93. compadd "$@" -a groups
  94. }
  95.  
  96. # provides completions for installed packages
  97. _packer_completions_installed_packages() {
  98. local -a cmd packages packages_long
  99. packages_long=(/var/lib/pacman/local/*(/))
  100. packages=( ${${packages_long#/var/lib/pacman/local/}%-*-*} )
  101. compadd "$@" -a packages
  102. }
  103.  
  104. # provides completions for repository names
  105. _packer_completions_repositories() {
  106. local -a cmd repositories
  107. repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
  108. # Uniq the array
  109. typeset -U repositories
  110. compadd "$@" -a repositories
  111. }
  112.  
  113. # builds command for invoking pacman in a _call_program command - extracts
  114. # relevant options already specified (config file, etc)
  115. # $cmd must be declared by calling function
  116. _packer_get_command() {
  117. # this is mostly nicked from _perforce
  118. cmd=( "pacman" )
  119. integer i
  120. for (( i = 2; i < CURRENT - 1; i++ )); do
  121. if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then
  122. cmd+=( ${words[i,i+1]} )
  123. fi
  124. done
  125. }
  126.  
  127. # main dispatcher
  128. _packer() {
  129. case $words[2] in
  130. -S*) _packer_action_sync ;;
  131. -G*) _packer_action_sync ;;
  132. - ) _packer_action_none ;;
  133. * ) return 1 ;;
  134. esac
  135. }
  136.  
  137. # run the main dispatcher
  138. _packer "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement