Skip to content

Instantly share code, notes, and snippets.

@unique1984
Last active November 16, 2023 01:09
Show Gist options
  • Save unique1984/3d8ebc8c7b9b33162bb6dd7801be6128 to your computer and use it in GitHub Desktop.
Save unique1984/3d8ebc8c7b9b33162bb6dd7801be6128 to your computer and use it in GitHub Desktop.
Symfony Cli bash-completion
_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
@unique1984
Copy link
Author

Found the problems!

  1. grep -v 'Available\|Global\|Usage:' --> grep -v 'Available\|Global\|Usage:\|Runs\|Environment'
  2. 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