vorpal icon indicating copy to clipboard operation
vorpal copied to clipboard

Vorpal version 1 autocomplete problem

Open ORESoftware opened this issue 6 years ago • 4 comments

I created this video demonstrating the problem

https://www.useloom.com/share/40a9509bf03248d586d0357894f0edf4

I would like to use tab completion to access a directory

something like this:

node test/src/dev/node/foo.test.js

but using Vorpals autocomplete functionality does not make tab completing through a filesystem easy at all because Vorpal adds an extra character after the user hits tab. See the video.

My code to do the autocompletion looks like this:

  vorpal.command('run [file]')
  .description('run a single test script')
  .autocomplete({
    data: function (input: string, cb: Function) {

      const basename = path.basename(input);
      const dir = path.dirname(path.resolve(process.cwd() + `/${input}`));

      fs.readdir(dir, function (err, items) {
        if (err) {
          return cb(null);
        }
        const matches = items.filter(function (item) {
          return String(item).match(basename);
        });

        return cb(matches);

      });

    }
  })

ORESoftware avatar Oct 15 '17 22:10 ORESoftware

any word on this bird?

I think it might be this line https://github.com/dthree/vorpal/blob/8bb46ada64a3dac333b9f5b9e5ed72432aa26d0e/lib/autocomplete.js#L100

ORESoftware avatar Oct 23 '17 06:10 ORESoftware

this one is important to me, if someone can help me with it - @dthree @milesj

ORESoftware avatar Nov 06 '17 01:11 ORESoftware

Hi @ORESoftware. Thanks for the video. Yes, adding a space is intended functionality, and file system navigation is the one place I've observed this to come up as an issue.

Perhaps we can add a flag on the tabbed autocompletion command? In this way, you can make the space omission command-specific.

By the way, there's already a file-system autocompletion library:

https://github.com/vorpaljs/vorpal-autocomplete-fs

dthree avatar Nov 07 '17 18:11 dthree

oh nice, let me try that fs autocompletion lib, if it doesn't work I will report back very soon

ORESoftware avatar Nov 07 '17 18:11 ORESoftware