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

bash-complete

v0.0.11

Published

Shell script for auto-complete of bash commands that are context/directory specific, ex: yarn workspace <tab> to list workspaces

Downloads

682

Readme

Bash Complete

Bash Complete is a customizable command autocompletion system for Bash, designed to enhance the user experience by providing autocompletion suggestions for specific commands (by default, yarn). This project consists of a set of scripts that work together to support directory-specific and nested command autocompletion for complex workflows.


Install Instructions

Quick Install

You can install Bash Complete directly using npx:

npx bash-complete

Manual Install

Alternatively, you can clone the repository and run the install.sh script:

./install.sh

The installation script performs the following actions:

  1. Copies .bash-complete.sh and .bash-complete-update.cjs to the user’s home directory.
  2. Creates .bash-complete.json in the home directory with default content ({}) if it doesn't already exist.
  3. Updates .bashrc to source .bash-complete.sh for loading autocompletion on new shell sessions.

Once installed, open a new terminal session to start using Bash Complete.


How to Use

After installation, you can use Bash Complete for autocompletion with yarn (or any command specified in the SUPPORTED_COMMANDS array).

  • Autocompletion: The system records and suggests commands that you have previously run in this directory. Start typing a known command, followed by a partial command or subcommand, and press Tab to see autocomplete suggestions. For example:

    yarn build
    yarn b <Tab>
  • 💡 Automatic Command Logging: Run yarn --auto to automatically populate the autocompletion data for the current directory’s package.json scripts, as well as workspaces and their scripts.

    yarn --auto

    This will auto-discover available commands and subcommands and store them in .bash-complete.json for the current project directory and any workspaces it contains.


Customization: Adding More Commands

By default, the script only supports yarn as a command. To enable autocompletion for additional commands:

  1. Open .bash-complete.sh in your home directory:

    nano ~/.bash-complete.sh
  2. Locate the SUPPORTED_COMMANDS array near the top of the file:

    SUPPORTED_COMMANDS=("yarn")
  3. Add any additional commands to the array, separated by spaces. For example:

    SUPPORTED_COMMANDS=("yarn" "npm" "my_custom_command")
  4. Save the file, and new commands will be supported automatically in new terminal sessions.


What This Project Does

  1. Custom Command Autocompletion: Supports autocompletion for a specified list of commands in Bash, using data stored in .bash-complete.json.
  2. Directory-Specific Suggestions: The autocompletion suggestions are context-aware, providing different options based on the current directory.
  3. Nested Command Support: Handles nested commands with complex structures (e.g., yarn workspace @local/package build) and supports autocompletion for each part of the command.

File Details

.bash-complete.sh

This is the main script responsible for setting up command overrides and defining the autocompletion function:

  • Overrides Commands in SUPPORTED_COMMANDS, allowing autocompletion and logging.
  • Autocompletion Logic: Looks up suggestions in .bash-complete.json based on the current directory and command structure.

.bash-complete-update.cjs

This Node.js script updates .bash-complete.json with the current command structure:

  • Logging Commands: Every time a supported command runs, .bash-complete-update.cjs updates the command tree in .bash-complete.json.
  • Directory-Specific Data: Each directory gets its own set of command suggestions in the JSON file.

.bash-complete.json

This JSON file stores the command structure used by the autocompletion function:

  • Format: Directory paths are top-level keys, with command structures nested within each path.
  • Example Structure:
    {
      "/home/user/project": {
        "yarn": {
          "build": {
            "dev": {},
            "prod": {}
          },
          "test": {
            "unit": {},
            "integration": {}
          }
        }
      }
    }

install.sh

Automates the setup process:

  • Copies Required Files to the home directory.
  • Adds Source Entry to .bashrc: Ensures .bash-complete.sh is loaded for each new terminal session.
  • Dependency Check: Verifies jq is installed.

package.json

Defines project metadata and dependencies. If the project expands to include additional Node modules, you can manage them here.


Uninstallation

To remove Bash Complete:

  1. Delete the installed files:

    rm ~/.bash-complete.json ~/.bash-complete.sh ~/.bash-complete-update.cjs
  2. Remove the source line from .bashrc:

    nano ~/.bashrc

    Delete the following lines:

    # bash-complete setup
    source ~/.bash-complete.sh
  3. Open a new terminal session to apply changes.


License

This project is open-source under the MIT License.