2021-12-27 01:58:22 +08:00
|
|
|
## Basic Composer command completion
|
|
|
|
# Since Zsh 5.7, an improved composer command completion is provided
|
|
|
|
if ! is-at-least 5.7; then
|
|
|
|
_composer () {
|
2020-02-29 02:28:55 +08:00
|
|
|
local curcontext="$curcontext" state line
|
|
|
|
typeset -A opt_args
|
2021-12-27 01:58:22 +08:00
|
|
|
_arguments '*:: :->subcmds'
|
2020-02-29 02:28:55 +08:00
|
|
|
|
2021-12-27 01:58:22 +08:00
|
|
|
if (( CURRENT == 1 )) || ( (( CURRENT == 2 )) && [[ "$words[1]" = "global" ]] ); then
|
|
|
|
# Command list
|
|
|
|
local -a subcmds
|
|
|
|
subcmds=("${(@f)"$($_comp_command1 --no-ansi 2>/dev/null | awk '
|
|
|
|
/Available commands/{ r=1 }
|
|
|
|
r == 1 && /^[ \t]*[a-z]+/{
|
|
|
|
gsub(/^[ \t]+/, "")
|
|
|
|
gsub(/ +/, ":")
|
|
|
|
print $0
|
|
|
|
}
|
|
|
|
')"}")
|
|
|
|
_describe -t commands 'composer command' subcmds
|
2020-02-29 02:28:55 +08:00
|
|
|
else
|
2021-12-27 01:58:22 +08:00
|
|
|
# Required list
|
|
|
|
compadd $($_comp_command1 show -s --no-ansi 2>/dev/null \
|
|
|
|
| sed '1,/requires/d' \
|
|
|
|
| awk 'NF > 0 && !/^requires \(dev\)/{ print $1 }')
|
2020-02-29 02:28:55 +08:00
|
|
|
fi
|
2021-12-27 01:58:22 +08:00
|
|
|
}
|
2012-10-06 04:13:10 +08:00
|
|
|
|
2021-12-27 01:58:22 +08:00
|
|
|
compdef _composer composer
|
|
|
|
compdef _composer composer.phar
|
|
|
|
fi
|
2012-10-06 04:13:10 +08:00
|
|
|
|
2021-12-27 01:58:12 +08:00
|
|
|
|
|
|
|
## Aliases
|
2012-10-06 04:13:10 +08:00
|
|
|
alias c='composer'
|
|
|
|
alias ccp='composer create-project'
|
2020-04-13 23:23:52 +08:00
|
|
|
alias cdo='composer dump-autoload -o'
|
2021-12-27 01:58:12 +08:00
|
|
|
alias cdu='composer dump-autoload'
|
|
|
|
alias cget='curl -s https://getcomposer.org/installer | php'
|
2013-08-17 23:11:21 +08:00
|
|
|
alias cgr='composer global require'
|
2017-02-21 02:21:36 +08:00
|
|
|
alias cgrm='composer global remove'
|
2021-12-27 01:58:12 +08:00
|
|
|
alias cgu='composer global update'
|
|
|
|
alias ci='composer install'
|
2016-05-30 16:03:40 +08:00
|
|
|
alias co='composer outdated'
|
|
|
|
alias cod='composer outdated --direct'
|
2021-12-27 01:58:12 +08:00
|
|
|
alias cr='composer require'
|
|
|
|
alias crm='composer remove'
|
2021-07-09 16:12:56 +08:00
|
|
|
alias cs='composer show'
|
2021-12-27 01:58:12 +08:00
|
|
|
alias csu='composer self-update'
|
|
|
|
alias cu='composer update'
|
2012-10-06 04:13:10 +08:00
|
|
|
|
2014-06-02 07:28:42 +08:00
|
|
|
|
2021-12-27 01:58:12 +08:00
|
|
|
## If Composer not found, try to add known directories to $PATH
|
|
|
|
if (( ! $+commands[composer] )); then
|
|
|
|
[[ -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"
|
2020-09-29 18:06:21 +08:00
|
|
|
|
2021-12-27 01:58:12 +08:00
|
|
|
# If still not found, don't do the rest of the script
|
|
|
|
(( $+commands[composer] )) || return 0
|
|
|
|
fi
|
2018-03-07 05:10:34 +08:00
|
|
|
|
|
|
|
|
2021-12-27 01:58:12 +08:00
|
|
|
## Add Composer's global binaries to PATH
|
|
|
|
autoload -Uz _store_cache _retrieve_cache _cache_invalid
|
|
|
|
_retrieve_cache composer
|
2018-03-07 05:10:34 +08:00
|
|
|
|
2021-12-27 01:58:12 +08:00
|
|
|
if [[ -z $__composer_bin_dir ]]; then
|
|
|
|
__composer_bin_dir=$(composer global config bin-dir --absolute 2>/dev/null)
|
|
|
|
_store_cache composer __composer_bin_dir
|
2018-08-20 03:46:22 +08:00
|
|
|
fi
|
2021-12-27 01:58:12 +08:00
|
|
|
|
|
|
|
# Add Composer's global binaries to PATH
|
|
|
|
export PATH="$PATH:$__composer_bin_dir"
|
|
|
|
|
|
|
|
unset __composer_bin_dir
|