bower.plugin.zsh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. alias bi="bower install"
  2. alias bl="bower list"
  3. alias bs="bower search"
  4. _bower_installed_packages () {
  5. bower_package_list=$(bower ls --no-color 2>/dev/null| awk 'NR>3{print p}{p=$0}'| cut -d ' ' -f 2|sed 's/#.*//')
  6. }
  7. _bower ()
  8. {
  9. local -a _1st_arguments _no_color _dopts _save_dev _force_lastest _production
  10. local expl
  11. typeset -A opt_args
  12. _no_color=('--no-color[Do not print colors (available in all commands)]')
  13. _dopts=(
  14. '(--save)--save[Save installed packages into the project"s bower.json dependencies]'
  15. '(--force)--force[Force fetching remote resources even if a local copy exists on disk]'
  16. )
  17. _save_dev=('(--save-dev)--save-dev[Save installed packages into the project"s bower.json devDependencies]')
  18. _force_lastest=('(--force-latest)--force-latest[Force latest version on conflict]')
  19. _production=('(--production)--production[Do not install project devDependencies]')
  20. _1st_arguments=(
  21. 'cache-clean:Clean the Bower cache, or the specified package caches' \
  22. 'help:Display help information about Bower' \
  23. 'info:Version info and description of a particular package' \
  24. 'init:Interactively create a bower.json file' \
  25. 'install:Install a package locally' \
  26. 'link:Symlink a package folder' \
  27. 'lookup:Look up a package URL by name' \
  28. 'register:Register a package' \
  29. 'search:Search for a package by name' \
  30. 'uninstall:Remove a package' \
  31. 'update:Update a package' \
  32. {ls,list}:'[List all installed packages]'
  33. )
  34. _arguments \
  35. $_no_color \
  36. '*:: :->subcmds' && return 0
  37. if (( CURRENT == 1 )); then
  38. _describe -t commands "bower subcommand" _1st_arguments
  39. return
  40. fi
  41. case "$words[1]" in
  42. install)
  43. _arguments \
  44. $_dopts \
  45. $_save_dev \
  46. $_force_lastest \
  47. $_no_color \
  48. $_production
  49. ;;
  50. update)
  51. _arguments \
  52. $_dopts \
  53. $_no_color \
  54. $_force_lastest
  55. _bower_installed_packages
  56. compadd "$@" $(echo $bower_package_list)
  57. ;;
  58. uninstall)
  59. _arguments \
  60. $_no_color \
  61. $_dopts
  62. _bower_installed_packages
  63. compadd "$@" $(echo $bower_package_list)
  64. ;;
  65. *)
  66. $_no_color \
  67. ;;
  68. esac
  69. }
  70. compdef _bower bower