PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 10, 2022

[FIXED] How can I enable composer to have command line argument auto complete?

 November 10, 2022     bash, composer-php     No comments   

Issue

I would like to be able to use tab auto completion with composer in my bash shell, the same way I can for example auto complete filenames or git commands.


Solution

To enable auto complete for composer in bash you need to write a function that returns an array of possible values for the last typed parameter (_composer() in this case) and register it using complete -F function command.

As a complete, working example add the following to your .bashrc (or any other configuration script you might be using)

_composer()
{
    local cur=${COMP_WORDS[COMP_CWORD]}
    local cmd=${COMP_WORDS[0]}
    if ($cmd > /dev/null 2>&1)
    then
        COMPREPLY=( $(compgen -W "$($cmd list --raw | cut -f 1 -d " " | tr "\n" " ")" -- $cur) )
    fi
}
complete -F _composer composer
complete -F _composer composer.phar


Answered By - Nils Werner
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing