composer.plugin.zsh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. $_comp_command1 --no-ansi 2>/dev/null | sed "1,/Available commands/d" | awk '/^[ \t]*[a-z]+/ { print $1 }'
  10. }
  11. _composer_get_required_list () {
  12. $_comp_command1 show -s --no-ansi 2>/dev/null | 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. case $state in
  21. command)
  22. compadd $(_composer_get_command_list)
  23. ;;
  24. *)
  25. compadd $(_composer_get_required_list)
  26. ;;
  27. esac
  28. }
  29. compdef _composer composer
  30. compdef _composer composer.phar
  31. # Aliases
  32. alias c='composer'
  33. alias csu='composer self-update'
  34. alias cu='composer update'
  35. alias cr='composer require'
  36. alias crm='composer remove'
  37. alias ci='composer install'
  38. alias ccp='composer create-project'
  39. alias cdu='composer dump-autoload'
  40. alias cdo='composer dump-autoload --optimize-autoloader'
  41. alias cgu='composer global update'
  42. alias cgr='composer global require'
  43. alias cgrm='composer global remove'
  44. # install composer in the current directory
  45. alias cget='curl -s https://getcomposer.org/installer | php'
  46. # Add Composer's global binaries to PATH
  47. export PATH=$PATH:$(composer global config bin-dir --absolute 2>/dev/null)