composer.plugin.zsh 1.45 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
  if [ -f composer.json ]; then
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
  else
    compadd create-project init search selfupdate show
34
35
36
37
  fi
}

compdef _composer composer
38
compdef _composer composer.phar
39
40
41
42
43
44
45

# Aliases
alias c='composer'
alias csu='composer self-update'
alias cu='composer update'
alias ci='composer install'
alias ccp='composer create-project'
46
alias cdu='composer dump-autoload'
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