File tree 4 files changed +43
-28
lines changed
4 files changed +43
-28
lines changed Original file line number Diff line number Diff line change @@ -6,21 +6,24 @@ This is an experimental hack to add [Symfony BASH auto complete](https://github.
6
6
7
7
## Installation
8
8
9
- 1 . Run ` composer global require stecman/composer-bash-completion-plugin dev-master `
10
- 2 . Add a completion hook to your shell's user config file:
11
- - If you're using BASH, put the following in your ` ~/.bash_profile ` file:
12
-
13
- ``` bash
14
- # Add shell auto-completion for composer
15
- source " ${COMPOSER_HOME-$HOME / .composer} /vendor/stecman/composer-bash-completion-plugin/hooks/bash-completion"
16
- ```
17
- - If you' re using ZSH, put the following in your `~/.zshrc` file:
18
-
19
- ```bash
20
- # Add shell auto-completion for composer
21
- source "${COMPOSER_HOME-$HOME/.composer}/vendor/stecman/composer-bash-completion-plugin/hooks/zsh-completion"
22
- ```
23
- 3. Reload the modified shell config (or open a new shell), and enjoy tab completion on Composer
9
+ 1 . Install the plugin:
10
+
11
+ ```
12
+ composer global require stecman/composer-bash-completion-plugin dev-master
13
+ ```
14
+
15
+ 2 . Generate code to register a completion hook for your shell and Composer configuration:
16
+
17
+ ```
18
+ source $(composer config home --global)/vendor/stecman/composer-bash-completion-plugin/generate-hook
19
+ ```
20
+
21
+ 3 . Add the registration code to your shell profile:
22
+
23
+ - If you're using BASH, copy the output to your ` ~/.bash_profile `
24
+ - If you're using ZSH, copy the output to your ` ~/.zshrc `
25
+
26
+ 4 . Reload your modified shell config (or open a new shell), and enjoy tab completion on Composer
24
27
25
28
## Explanation
26
29
Original file line number Diff line number Diff line change
1
+ # Generate registration code to go in a shell profile
2
+
3
+ _composercomplete_hook_dir="$(composer config home --global)/vendor/stecman/composer-bash-completion-plugin/hooks"
4
+
5
+ echo "# Add tab auto-completion for composer"
6
+
7
+ if [ ! -z $BASH_VERSION ]; then
8
+ echo "source $_composercomplete_hook_dir/bash-completion"
9
+ fi
10
+
11
+ if [ ! -z $ZSH_VERSION ]; then
12
+ echo "source $_composercomplete_hook_dir/zsh-completion"
13
+ fi
14
+
15
+ unset _composercomplete_hook_dir
Original file line number Diff line number Diff line change @@ -8,15 +8,13 @@ function _composercomplete {
8
8
9
9
export CMDLINE_CONTENTS CMDLINE_CURSOR_INDEX CMDLINE_WORDBREAKS
10
10
11
- # Honour the COMPOSER_HOME variable if set
12
- local composer_dir=$COMPOSER_HOME
13
- if [ -z "$composer_dir" ]; then
14
- composer_dir=$HOME/.composer
11
+ # Query and cache where the global composer.json lives
12
+ if [ -z "$_composer_config_dir" ]; then
13
+ _composer_config_dir="$(composer config home --global)"
15
14
fi
16
15
17
16
local RESULT STATUS;
18
-
19
- RESULT=$(cd $composer_dir && composer depends _completion);
17
+ RESULT=$(cd "$_composer_config_dir" && composer depends _completion);
20
18
STATUS=$?;
21
19
22
20
local cur;
@@ -32,4 +30,4 @@ function _composercomplete {
32
30
__ltrim_colon_completions "$cur";
33
31
};
34
32
35
- complete -F _composercomplete composer;
33
+ complete -F _composercomplete composer;
Original file line number Diff line number Diff line change @@ -6,14 +6,13 @@ function _composer {
6
6
local -x CMDLINE_CURSOR_INDEX
7
7
(( CMDLINE_CURSOR_INDEX = ${#${(j. .)words[1,CURRENT]}} ))
8
8
9
- # Honour the COMPOSER_HOME variable if set
10
- local composer_dir=$COMPOSER_HOME
11
- if [ -z "$composer_dir" ]; then
12
- composer_dir=$HOME/.composer
9
+ # Query and cache where the global composer.json lives
10
+ if [ -z "$_composer_config_dir" ]; then
11
+ _composer_config_dir="$(composer config home --global)"
13
12
fi
14
13
15
14
local RESULT STATUS
16
- RESULT=("${(@f)$( cd $composer_dir && composer depends _completion )}")
15
+ RESULT=("${(@f)$( cd $_composer_config_dir && composer depends _completion )}")
17
16
STATUS=$?;
18
17
19
18
if [ $STATUS -ne 0 ]; then
@@ -24,4 +23,4 @@ function _composer {
24
23
compadd -- $RESULT
25
24
};
26
25
27
- compdef _composer composer;
26
+ compdef _composer composer;
You can’t perform that action at this time.
0 commit comments