composer.plugin.zsh 1.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
# ------------------------------------------------------------------------------
#          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 () {
	composer --no-ansi | sed "1,/Available commands/d" | awk '/^  [a-z]+/ { print $1 }'
}

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

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
38
39
40
41
42
43
44
  fi
}

compdef _composer composer

# Aliases
alias c='composer'
alias csu='composer self-update'
alias cu='composer update'
alias ci='composer install'
alias ccp='composer create-project'
45
alias cdu='composer dump-autoload'
46

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