Last active
November 16, 2023 01:09
-
-
Save unique1984/3d8ebc8c7b9b33162bb6dd7801be6128 to your computer and use it in GitHub Desktop.
Symfony Cli bash-completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_symfony() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local cmd="${COMP_WORDS[0]}" | |
if ($cmd > /dev/null 2>&1) | |
then | |
COMPREPLY=($(compgen -W "$($cmd --help --no-ansi | grep -v 'Available\|Global\|Usage:\|Runs\|Environment' | grep ':' | awk '{print $1}' | grep -Poi '^\K[\w:-]+') new serve server:stop security:check composer console login link projects envs env:create tunnel:open ssh deploy domains vars user:add help" -- $cur)) | |
fi | |
} | |
complete -F _symfony symfony |
Found the problems!
grep -v 'Available\|Global\|Usage:'
-->grep -v 'Available\|Global\|Usage:\|Runs\|Environment'
grep -Poi '^\K[\w-:]+'
-->grep -Poi '^\K[\w:-]+'
for 2nd part -> stackoverflow grep -
This kind a work on Mac OSX with lots of error before compliting command. Probably due to following 2 things:
1. `grep -v 'Available\|Global\|Usage:'` 2. `grep -Poi '^\K[\w-:]+'`
Is there way to make autocomplete with static list of all commands I quickly extracted?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know MacOs is using "bash" but yes you can use compgen using static list.
compgen is a GNU tool to create programmable completion of a string GNU Compgen
symfony --help --no-ansi | grep -v 'Available\|Global\|Usage:' | grep ':' | awk '{print $1}' | grep -Poi '^\K[\w-:]+'
In this command i am getting the command output of "symfony --help" and parsing it using GNU grep.
As i am using an output of a command (a list of argument, string) it means that i can use an output of a string saved in a document.
for example save your string as a file named symfony_commands.txt and use compgen with it.
symfony --help --no-ansi ... = cat symfony_commands.txt
It is the same. Actually, you should look what type of terminal you are using and revise this code after that. This one works best under bash.
...