composer.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # ------------------------------------------------------------------------------
  2. # FILE: composer.plugin.zsh
  3. # DESCRIPTION: oh-my-zsh composer plugin file.
  4. # AUTHOR: Daniel Gomes (me@danielcsgomes.com)
  5. # VERSION: 1.0.0
  6. # ------------------------------------------------------------------------------
  7. # Composer basic command completion
  8. _composer_get_command_list () {
  9. composer --no-ansi | sed "1,/Available commands/d" | awk '/^ [a-z]+/ { print $1 }'
  10. }
  11. _composer_get_required_list () {
  12. composer show -s --no-ansi | sed '1,/requires/d' | awk 'NF > 0 && !/^requires \(dev\)/{ print $1 }'
  13. }
  14. _composer () {
  15. local curcontext="$curcontext" state line
  16. typeset -A opt_args
  17. _arguments \
  18. '1: :->command'\
  19. '*: :->args'
  20. if [ -f composer.json ]; then
  21. case $state in
  22. command)
  23. compadd `_composer_get_command_list`
  24. ;;
  25. *)
  26. compadd `_composer_get_required_list`
  27. ;;
  28. esac
  29. else
  30. compadd create-project init search selfupdate show
  31. fi
  32. }
  33. compdef _composer composer
  34. # Aliases
  35. alias c='composer'
  36. alias csu='composer self-update'
  37. alias cu='composer update'
  38. alias ci='composer install'
  39. alias ccp='composer create-project'
  40. alias cdu='composer dump-autoload'
  41. # install composer in the current directory
  42. alias cget='curl -s https://getcomposer.org/installer | php'
  43. # Add Composer's global binaries to PATH
  44. export PATH=$PATH:~/.composer/vendor/bin