Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

bower install <TAB_COMPLETION> ? #93

Closed
hemanth opened this Issue · 25 comments

6 participants

hemanth.hm Sindre Sorhus F A T André Cruz Mickael Daniel Martin Miklós
hemanth.hm

It would be kool to have bash like tab completion here?

Was thinking if we can use this with compgen -W or this or something similar?

F A T
Owner

this sounds pretty awesome, interested in giving it a shot implementing it?

hemanth.hm

@fat Yes, tried a first cut couple of days back. Will give a gist soon!

hemanth.hm

@fat @sindresorhus Here is the first cut, for simplicity have avoided CLI args.

var auto = require('autocomplete');
var request = require('request');
request('https://bower.herokuapp.com/packages',function(err,resp,body){
  var data = JSON.parse(body);
  var pkgs = [];
  data.forEach(function(pkg){
    pkgs.push(pkg.name);
  });
  var ac = auto.connectAutocomplete();

  ac.initialize(function(onReady){
      onReady(pkgs);
  });  

  var matches = ac.search('back');
  console.log(matches); 

});

That would output :

[ 'backbone',
  'backbone.wreqr',
  'backbone.utils',
  'backbone.rpc',
  'backbone.paginator',
  'backbone.mutators',
  'backbone.marionette.handlebars',
  'backbone.localStorage',
  'backbone.include',
  'backbone.eventbinder',
  'backbone.collectionview',
  'backbone.collectionsubset',
  'backbone.chosen',
  'backbone.app',
  'backbone-validation',
  'backbone-relational',
  'backbone-paginator',
  'backbone-jqmobile',
  'backbone-dombuilder',
  'backbone-deep-model',
  'backbone-amd' ]
Sindre Sorhus

@hemanth Any progress?

hemanth.hm

@sindresorhus Yet to proceed on the first cut, was on a vacation. :man:

Sindre Sorhus

@hemanth Ok, no worries, just wanted to ping in :)

hemanth.hm

Tried the same with bower commands :

var auto = require('autocomplete');
var request = require('request');
var cmds = require('./index.js');
var cmds =  Object.keys(cmds);

var ac = auto.connectAutocomplete();
ac.initialize(function(onReady){
    onReady(cmds);
});  

var matches = ac.search('i');
console.log(matches);

That would output something like :

[ 'install', 'info' ]

But now having issues with tab-completion here!

Until the return key is pressed we can't process the argv, is there a way out? Would be better to play with readline or something similar? Is there a way to trap key? Or should be done with bash/other auto-complete module?

Also, came across https://npmjs.org/package/complete but seems like it's not working as in the example.

@sindresorhus @fat @satazor Need some suggestions please :six_pointed_star:

Sindre Sorhus

I have no experience with Bash autocompletion, but I know @mklabs did a prototype for Yeoman, maybe he can give some insight.

André Cruz
Owner

@hemanth This needs to be integrated with a postinstall script.

Basically you need to create a new bower command (e.g.: _autocomplete) and print to the stdout the autocompletion results (separated by a newline).

Then, we need to detect the type of shell in the postinstall script and react accordingly.

  • For bash, it would create a /etc/profile.d/bower.sh with the following:

    _bower()
    {
    COMPREPLY=( $(bower _autocomplete "$*") )
    return 0
    }
    complete -F _bower bower

The postinstall script should also warn the user that he needs to reload its shell to have the autocomplete.
I can make some quick example that works.

Completing this solution, a postuninstall script should also be done to remove any added files to the system.

IMPORTANT: all of this should only be done if bower was installed with -g

hemanth.hm

@satazor There seems to be some complexity invloved in handling diffrenent $SHELL, anyway it would have been more kool if node had some similar facility is in't ? /me awaits for the example.

André Cruz
Owner

@hemanth yes, I know that this is possible for bash but I don't know how to do it in zshell or iterm. But we could support bash initially and investigate how it's done for others later on.

I will make the example as soon as I get some free time.

André Cruz
Owner

@hemanth Still need the example? I think that if you follow yeomen's you are going to make it.

Mickael Daniel

@hemanth I'm willing to help if you want to.

hemanth.hm

@satazor Was down with fever :crying_cat_face: @mklabs I would neva say no to helping hand! :+1:

Mickael Daniel

@hemanth I'll send you something soon to review :)

hemanth.hm

@mklabs wow! ok :wolf:

Mickael Daniel mklabs referenced this issue
Merged

Completion #191

Martin Miklós

Hey guys!

I've just noticed you're working on completition, and I must say a few things about this.

It's definitely cool to have completition on frequently used cli tools.
However, I think it's the job of your shell, not the tool you're using.

I created an oh-my-zsh plugin for bower a few months ago, you might want to check it out.
Here is the description of the plugin:
https://github.com/miklos-martin/oh-my-zsh-plugins#bower
And here is the code:
https://github.com/miklos-martin/oh-my-zsh-plugins/tree/master/bower
It's probably can be easily ported to bash or other shells.

Mickael Daniel

Hey @miklos-martin

While I understand your point, I tend to not agree.

See https://npmjs.org/doc/completion.html for the reasoning behind this. Each and every command can have a different semantic, and to really be comprehensive, you can't only rely on parsing just the help output. In the end, it's still your shells job, the scripts just acts in a "plumbing mode".

Martin Miklós

@mklabs: Thanks for the info, I didn't know that.

Then take my previous comment as a tip. I hope it helps others, as it eases my life too.

Mickael Daniel

Don't get me wrong, I definitely think your zsh script is cool. I've learned a few things in there :)

Sindre Sorhus

This was fixed #191

Nils Winkler nwinkler referenced this issue in revans/bash-it
Closed

Added Bower completion #368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.