bower.plugin.zsh 2.4 KB

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