composer.plugin.zsh 1.43 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 | sed "1,/Available commands/d" | awk '/^\s*[a-z]+/ { print $1 }'
11
12
}

13
_composer_get_required_list () {
14
    $_comp_command1 show -s --no-ansi | 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
43
alias ci='composer install'
alias ccp='composer create-project'
44
alias cdu='composer dump-autoload'
Maxime Fabre's avatar
Maxime Fabre committed
45
46
alias cgu='composer global update'
alias cgr='composer global require'
47

48
# install composer in the current directory
49
alias cget='curl -s https://getcomposer.org/installer | php'
50

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