From 5f6b0ac7fbfbb0e25d0d691efa1bf676ac9f6962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 26 Dec 2021 18:58:12 +0100 Subject: [PATCH] style(composer): fix code and README style --- plugins/composer/README.md | 36 +++++++------- plugins/composer/composer.plugin.zsh | 74 ++++++++++++---------------- 2 files changed, 50 insertions(+), 60 deletions(-) diff --git a/plugins/composer/README.md b/plugins/composer/README.md index 7a5f7256e..00ada1e13 100644 --- a/plugins/composer/README.md +++ b/plugins/composer/README.md @@ -10,22 +10,24 @@ To use it add `composer` to the plugins array in your zshrc file. plugins=(... composer) ``` +Original author: Daniel Gomes + ## Aliases -| Alias | Command | Description | -| ------ | ------------------------------------------- | --------------------------------------------------------------------------------------- | -| `c` | `composer` | Starts composer | -| `csu` | `composer self-update` | Updates composer to the latest version | -| `cu` | `composer update` | Updates composer dependencies and `composer.lock` file | -| `cr` | `composer require` | Adds new packages to `composer.json` | -| `crm` | `composer remove` | Removes packages from `composer.json` | -| `ci` | `composer install` | Resolves and installs dependencies from `composer.json` | -| `ccp` | `composer create-project` | Create new project from an existing package | -| `cdu` | `composer dump-autoload` | Updates the autoloader | -| `cdo` | `composer dump-autoload -o` | Converts PSR-0/4 autoloading to classmap for a faster autoloader (good for production) | -| `cgu` | `composer global update` | Allows update command to run on COMPOSER_HOME directory | -| `cgr` | `composer global require` | Allows require command to run on COMPOSER_HOME directory | -| `cgrm` | `composer global remove` | Allows remove command to run on COMPOSER_HOME directory | -| `cget` | `curl -s https://getcomposer.org/installer` | Installs composer in the current directory | -| `co` | `composer outdated` | Shows a list of installed packages with available updates | -| `cod` | `composer outdated --direct` | Shows a list of installed packages with available updates which are direct dependencies | +| Alias | Command | Description | +| ------ | ---------------------------- | --------------------------------------------------------------------------------------- | +| `c` | `composer` | Starts composer | +| `ccp` | `composer create-project` | Create new project from an existing package | +| `cdo` | `composer dump-autoload -o` | Converts PSR-0/4 autoloading to classmap for a faster autoloader (good for production) | +| `cdu` | `composer dump-autoload` | Updates the autoloader | +| `cget` | `curl -s \| php` | Installs composer in the current directory | +| `cgr` | `composer global require` | Allows require command to run on COMPOSER_HOME directory | +| `cgrm` | `composer global remove` | Allows remove command to run on COMPOSER_HOME directory | +| `cgu` | `composer global update` | Allows update command to run on COMPOSER_HOME directory | +| `ci` | `composer install` | Resolves and installs dependencies from `composer.json` | +| `co` | `composer outdated` | Shows a list of installed packages with available updates | +| `cod` | `composer outdated --direct` | Shows a list of installed packages with available updates which are direct dependencies | +| `cr` | `composer require` | Adds new packages to `composer.json` | +| `crm` | `composer remove` | Removes packages from `composer.json` | +| `csu` | `composer self-update` | Updates composer to the latest version | +| `cu` | `composer update` | Updates composer dependencies and `composer.lock` file | diff --git a/plugins/composer/composer.plugin.zsh b/plugins/composer/composer.plugin.zsh index 218a13e5f..ba29503e4 100644 --- a/plugins/composer/composer.plugin.zsh +++ b/plugins/composer/composer.plugin.zsh @@ -1,19 +1,3 @@ -# ------------------------------------------------------------------------------ -# 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 () { - $_comp_command1 --no-ansi 2>/dev/null | sed "1,/Available commands/d" | awk '/^[ \t]*[a-z]+/ { print $1 }' -} - -_composer_get_required_list () { - $_comp_command1 show -s --no-ansi 2>/dev/null | sed '1,/requires/d' | awk 'NF > 0 && !/^requires \(dev\)/{ print $1 }' -} - _composer () { local curcontext="$curcontext" state line typeset -A opt_args @@ -30,41 +14,45 @@ _composer () { compdef _composer composer compdef _composer composer.phar -# Aliases + +## Aliases alias c='composer' -alias csu='composer self-update' -alias cu='composer update' -alias cr='composer require' -alias crm='composer remove' -alias ci='composer install' alias ccp='composer create-project' -alias cdu='composer dump-autoload' alias cdo='composer dump-autoload -o' -alias cgu='composer global update' +alias cdu='composer dump-autoload' +alias cget='curl -s https://getcomposer.org/installer | php' alias cgr='composer global require' alias cgrm='composer global remove' +alias cgu='composer global update' +alias ci='composer install' alias co='composer outdated' alias cod='composer outdated --direct' +alias cr='composer require' +alias crm='composer remove' +alias csu='composer self-update' +alias cu='composer update' -# install composer in the current directory -alias cget='curl -s https://getcomposer.org/installer | php' -# Add Composer's global binaries to PATH, using Composer if available. -if (( $+commands[composer] )); then - autoload -Uz _store_cache _retrieve_cache _cache_invalid +## 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" - _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 -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 + # If still not found, don't do the rest of the script + (( $+commands[composer] )) || return 0 fi + + +## Add Composer's global binaries to PATH +autoload -Uz _store_cache _retrieve_cache _cache_invalid +_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