composer.plugin.zsh 2.24 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
23
24
25
26
27
    local curcontext="$curcontext" state line
    typeset -A opt_args
    _arguments \
        '*:: :->subcmds'

    if (( CURRENT == 1 )) || ( ((CURRENT == 2)) && [ "$words[1]" = "global" ] ) ; then
        compadd $(_composer_get_command_list)
    else
        compadd $(_composer_get_required_list)
    fi
28
29
30
}

compdef _composer composer
31
compdef _composer composer.phar
32
33
34
35
36

# Aliases
alias c='composer'
alias csu='composer self-update'
alias cu='composer update'
Maxime Fabre's avatar
Maxime Fabre committed
37
alias cr='composer require'
38
alias crm='composer remove'
39
40
alias ci='composer install'
alias ccp='composer create-project'
41
alias cdu='composer dump-autoload'
42
alias cdo='composer dump-autoload -o'
Maxime Fabre's avatar
Maxime Fabre committed
43
44
alias cgu='composer global update'
alias cgr='composer global require'
45
alias cgrm='composer global remove'
46
47
alias co='composer outdated'
alias cod='composer outdated --direct'
48

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

52
53
# Add Composer's global binaries to PATH, using Composer if available.
if (( $+commands[composer] )); then
54
55
    autoload -Uz _store_cache _retrieve_cache

56
57
58
59
60
61
62
63
64
65
66
    _retrieve_cache composer

    if [[ -z $__composer_bin_dir ]]; then
        __composer_bin_dir=$(composer global config bin-dir --absolute 2>/dev/null)
        _store_cache composer __composer_bin_dir
    fi

    # Add Composer's global binaries to PATH
    export PATH="$PATH:$__composer_bin_dir"

    unset __composer_bin_dir
67
68
69
70
else
  [ -d $HOME/.composer/vendor/bin ] && export PATH=$PATH:$HOME/.composer/vendor/bin
  [ -d $HOME/.config/composer/vendor/bin ] && export PATH=$PATH:$HOME/.config/composer/vendor/bin
fi