composer.plugin.zsh 1.58 KB
Newer Older
1
2
3
4
5
6
7
8
9
# ------------------------------------------------------------------------------
#          FILE:  composer.plugin.zsh
#   DESCRIPTION:  oh-my-zsh composer plugin file.
#        AUTHOR:  Daniel Gomes (me@danielcsgomes.com)
#       VERSION:  1.0.0
# ------------------------------------------------------------------------------

# Composer basic command completion
_composer_get_command_list () {
10
    $_comp_command1 --no-ansi 2>/dev/null | sed "1,/Available commands/d" | awk '/^[ \t]*[a-z]+/ { print $1 }'
11
12
}

13
_composer_get_required_list () {
14
    $_comp_command1 show -s --no-ansi 2>/dev/null | sed '1,/requires/d' | awk 'NF > 0 && !/^requires \(dev\)/{ print $1 }'
15
16
}

17
_composer () {
18
19
20
21
22
  local curcontext="$curcontext" state line
  typeset -A opt_args
  _arguments \
    '1: :->command'\
    '*: :->args'
23
24
25
26
27
28
29
30
31

  case $state in
    command)
      compadd $(_composer_get_command_list)
      ;;
    *)
      compadd $(_composer_get_required_list)
      ;;
  esac
32
33
34
}

compdef _composer composer
35
compdef _composer composer.phar
36
37
38
39
40

# Aliases
alias c='composer'
alias csu='composer self-update'
alias cu='composer update'
Maxime Fabre's avatar
Maxime Fabre committed
41
alias cr='composer require'
42
alias crm='composer remove'
43
44
alias ci='composer install'
alias ccp='composer create-project'
45
alias cdu='composer dump-autoload'
46
alias cdo='composer dump-autoload --optimize-autoloader'
Maxime Fabre's avatar
Maxime Fabre committed
47
48
alias cgu='composer global update'
alias cgr='composer global require'
49
alias cgrm='composer global remove'
50

51
# install composer in the current directory
52
alias cget='curl -s https://getcomposer.org/installer | php'
53

54
55
# Add Composer's global binaries to PATH
export PATH=$PATH:~/.composer/vendor/bin