npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

completarr

v0.2.2

Published

Zero config autocompletions for yargs apps (bash, zsh, fish)

Downloads

5

Readme

Completarr

JavaScript Style Guide npm

Completarr is a zero config way to add shell auto completion for your yargs-based CLI applications.

You may want to use this over yargs' built-in solution if you need to support a wider range of shells (including zsh and fish).

Installation

npm install --save completarr

Usage

To use Completarr, perform the following rather simple steps:

  1. Integrate it into your CLI app:

    require('completarr')()
    
    // Your yargs-related code
  2. Add install/uninstall hooks to your package.json to automatically attach the completion script the user's shell init file:

    {
      "scripts": {
        "postinstall": "install-yargs-completion",
        "uninstall": "uninstall-yargs-completion"
      }
    }

Caveats

There are some things to consider:

  • Completarr is based on omelette and therefore does not support Windows. 😕
  • Completarr only works with globally installed commands.
  • Your yargs app needs to expose its help via .help() to make Completarr work.

Configuration

Completarr should work without any config 99% of the time, but there might be some edge cases in your app you want to handle:

Command Name (Shell Script)

By default, Completarr adds completion for all commands it finds in your package.json's bin field. If you got more commands there than you want completion for, you need to pass them to the install/uninstall hook explicitely:

// Your CLI app's package.json
{
  // We got three binaries:
  "bin": {
    "a": "./src/a",
    "b": "./src/b"
    "c": "./src/c"
  },
  "scripts": {
    // But we only want to install completions for "b" and "c":
    "postinstall": "install-yargs-completion b c",
    "uninstall": "uninstall-yargs-completion b c"
  }
}

Command Name (Node)

Completarr needs to know the name of your yargs root command to provide completions. By default it derives that from the binary where Completarr is included:

// file: src/hello
require('completarr')()

// Completarr assumes the command name is "hello"

However if for some reason your command name does not equal your file's name, you may pass Completarr the command name manually:

// file: src/foo.js
require('completarr')({
  name: 'hello'
})

Help Option

By default, yargs' option for showing the help output is --help. However, should you decide to publish the help under a different option (which yargs allows you to do) you'll have to tell Completarr about it:

// We use --info instead of --help
require('completarr')({
  helpOption: 'info'
})

// yargs-related code
require('yargs')
  .help('info')
  // ...