Skip to content

Commit 060d328

Browse files
committedDec 7, 2021
bug symfony#44475 [Console] Handle alias in completion script (GromNaN)
This PR was merged into the 5.4 branch. Discussion ---------- [Console] Handle alias in completion script | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#44461 | License | MIT | Doc PR | - Detect when completion is triggered by an alias and get the underlying command. Tip extracted from [bamarni/symfony-console-autocomplete](https://github.com/bamarni/symfony-console-autocomplete/blob/v1.4.2/resources/bash/default.php#L7-L10). Works well with such alias: ```console alias console=bin/console ``` Doesn't work with these aliases (command name is not the 1st part of the alias): ```console alias console='APP_ENV=test bin/console' ``` When alias has a different name, the name in the completion script must be updated. Commits ------- f3c196a Handle alias in completion script
2 parents cbebf57 + f3c196a commit 060d328

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed
 

‎src/Symfony/Component/Console/Resources/completion.bash

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ _sf_{{ COMMAND_NAME }}() {
99
# Use newline as only separator to allow space in completion values
1010
IFS=$'\n'
1111
local sf_cmd="${COMP_WORDS[0]}"
12+
13+
# for an alias, get the real script behind it
14+
if [[ $(type -t $sf_cmd) == "alias" ]]; then
15+
sf_cmd=$(alias $sf_cmd | sed -E "s/alias $sf_cmd='(.*)'/\1/")
16+
fi
17+
1218
if [ ! -f "$sf_cmd" ]; then
1319
return 1
1420
fi

0 commit comments

Comments
 (0)