composer.plugin.zsh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. '*:: :->subcmds'
  19. if (( CURRENT == 1 )) || ( ((CURRENT == 2)) && [ "$words[1]" = "global" ] ) ; then
  20. compadd $(_composer_get_command_list)
  21. else
  22. compadd $(_composer_get_required_list)
  23. fi
  24. }
  25. compdef _composer composer
  26. compdef _composer composer.phar
  27. # Aliases
  28. alias c='composer'
  29. alias csu='composer self-update'
  30. alias cu='composer update'
  31. alias cr='composer require'
  32. alias crm='composer remove'
  33. alias ci='composer install'
  34. alias ccp='composer create-project'
  35. alias cdu='composer dump-autoload'
  36. alias cdo='composer dump-autoload -o'
  37. alias cgu='composer global update'
  38. alias cgr='composer global require'
  39. alias cgrm='composer global remove'
  40. alias co='composer outdated'
  41. alias cod='composer outdated --direct'
  42. # install composer in the current directory
  43. alias cget='curl -s https://getcomposer.org/installer | php'
  44. # Add Composer's global binaries to PATH, using Composer if available.
  45. if (( $+commands[composer] )); then
  46. autoload -Uz _store_cache _retrieve_cache _cache_invalid
  47. _retrieve_cache composer
  48. if [[ -z $__composer_bin_dir ]]; then
  49. __composer_bin_dir=$(composer global config bin-dir --absolute 2>/dev/null)
  50. _store_cache composer __composer_bin_dir
  51. fi
  52. # Add Composer's global binaries to PATH
  53. export PATH="$PATH:$__composer_bin_dir"
  54. unset __composer_bin_dir
  55. else
  56. [ -d $HOME/.composer/vendor/bin ] && export PATH=$PATH:$HOME/.composer/vendor/bin
  57. [ -d $HOME/.config/composer/vendor/bin ] && export PATH=$PATH:$HOME/.config/composer/vendor/bin
  58. fi