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

unique1984 commented Dec 5, 2021

  • Create a file /etc/bash_completion.d/symfony
  • copy the code above in that file
  • source /etc/bash_completion.d/symfony

That is it;

This is not a healthy working code, when you use it, try tab completion after char " the command symfony " without " completion starts the line start.

image

image

@gecbla
Copy link

gecbla commented Apr 26, 2023

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?

book
book:check
book:check-requirements
book:checkout
check:req
check:requirements
check:security
cloud
cloud:act
cloud:activities
cloud:activity
cloud:activity:cancel
cloud:activity:get
cloud:activity:list
cloud:activity:log
cloud:app
cloud:app:config-get
cloud:app:list
cloud:apps
cloud:auth
cloud:auth:api-token-login
cloud:auth:browser-login
cloud:auth:info
cloud:auth:logout
cloud:auth:verify-phone-number
cloud:backup
cloud:backup:create
cloud:backup:delete
cloud:backup:get
cloud:backup:list
cloud:backup:restore
cloud:backups
cloud:branch
cloud:cc
cloud:certificate
cloud:certificate:add
cloud:certificate:delete
cloud:certificate:get
cloud:certificate:list
cloud:certificates
cloud:certs
cloud:checkout
cloud:clear-cache
cloud:clearcache
cloud:commit
cloud:commit:get
cloud:commit:list
cloud:commits
cloud:create
cloud:db
cloud:db:dump
cloud:db:size
cloud:db:sql
cloud:deploy
cloud:disk
cloud:docs
cloud:domain
cloud:domain:add
cloud:domain:delete
cloud:domain:get
cloud:domain:list
cloud:domain:update
cloud:domains
cloud:env
cloud:environment
cloud:environment:activate
cloud:environment:backup
cloud:environment:branch
cloud:environment:checkout
cloud:environment:deactivate
cloud:environment:debug
cloud:environment:delete
cloud:environment:http-access
cloud:environment:info
cloud:environment:init
cloud:environment:list
cloud:environment:logs
cloud:environment:merge
cloud:environment:metadata
cloud:environment:push
cloud:environment:redeploy
cloud:environment:relationships
cloud:environment:restore
cloud:environment:routes
cloud:environment:scp
cloud:environment:sql
cloud:environment:sql-dump
cloud:environment:ssh
cloud:environment:synchronize
cloud:environment:url
cloud:environment:xdebug
cloud:environments
cloud:get
cloud:httpaccess
cloud:i:act
cloud:integration
cloud:integration:activities
cloud:integration:activity:get
cloud:integration:activity:list
cloud:integration:activity:log
cloud:integration:add
cloud:integration:delete
cloud:integration:get
cloud:integration:list
cloud:integration:update
cloud:integration:validate
cloud:integrations
cloud:log
cloud:login
cloud:logout
cloud:logs
cloud:merge
cloud:metrics
cloud:metrics:disk-usage
cloud:mongo
cloud:mongodump
cloud:mongoexport
cloud:mongorestore
cloud:mount
cloud:mount:download
cloud:mount:list
cloud:mount:size
cloud:mount:upload
cloud:mounts
cloud:multi
cloud:organization
cloud:organization:billing:address
cloud:organization:billing:profile
cloud:organization:create
cloud:organization:delete
cloud:organization:info
cloud:organization:list
cloud:organization:subscription:list
cloud:organization:subscriptions
cloud:organization:user:add
cloud:organization:user:delete
cloud:organization:user:get
cloud:organization:user:list
cloud:organization:user:projects
cloud:organization:user:update
cloud:organization:users
cloud:organizations
cloud:orgs
cloud:oups
cloud:pro
cloud:project
cloud:project:clear-build-cache
cloud:project:create
cloud:project:delete
cloud:project:get
cloud:project:info
cloud:project:list
cloud:project:metadata
cloud:project:set-remote
cloud:projects
cloud:push
cloud:read
cloud:redeploy
cloud:redis
cloud:relationships
cloud:repo
cloud:repo:cat
cloud:repo:ls
cloud:repo:read
cloud:route
cloud:route:get
cloud:route:list
cloud:routes
cloud:scp
cloud:service
cloud:service:list
cloud:service:mongo:dump
cloud:service:mongo:export
cloud:service:mongo:restore
cloud:service:mongo:shell
cloud:service:redis-cli
cloud:services
cloud:snapshot:create
cloud:snapshot:list
cloud:snapshot:restore
cloud:snapshots
cloud:source-operation
cloud:source-operation:list
cloud:source-operation:run
cloud:source-ops
cloud:sql
cloud:sql-dump
cloud:ssh
cloud:ssh-cert
cloud:ssh-cert:load
cloud:ssh-key
cloud:ssh-key:add
cloud:ssh-key:delete
cloud:ssh-key:list
cloud:ssh-keys
cloud:subscription
cloud:subscription:info
cloud:sync
cloud:tunnel
cloud:tunnel:close
cloud:tunnel:info
cloud:tunnel:list
cloud:tunnel:open
cloud:tunnel:single
cloud:tunnels
cloud:url
cloud:user
cloud:user:add
cloud:user:delete
cloud:user:get
cloud:user:list
cloud:user:role
cloud:user:update
cloud:users
cloud:var
cloud:variable
cloud:variable:create
cloud:variable:delete
cloud:variable:get
cloud:variable:list
cloud:variable:update
cloud:variables
cloud:vget
cloud:web
cloud:worker
cloud:worker:list
cloud:workers
cloud:xdebug
deploy
environment:debug
help
init
list
local
local:check:requirements
local:check:security
local:new
local:php:list
local:php:refresh
local:proxy:domain:attach
local:proxy:domain:detach
local:proxy:start
local:proxy:status
local:proxy:stop
local:proxy:url
local:run
local:security:check
local:server:ca:install
local:server:ca:uninstall
local:server:list
local:server:log
local:server:prod
local:server:start
local:server:status
local:server:stop
local:var:expose-from-tunnel
new
open
open:local
open:local:rabbitmq
open:local:service
open:local:webmail
project
project:init
proxy:domain:attach
proxy:domain:detach
proxy:start
proxy:status
proxy:stop
proxy:url
run
security:check
self
self:help
self:version
serve
server:ca:install
server:ca:uninstall
server:list
server:log
server:prod
server:start
server:status
server:stop
var
var:export
var:expose-from-tunnel
version

@unique1984
Copy link
Author

unique1984 commented Jun 5, 2023

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.

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?

book

...

@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