The Wayback Machine - https://web.archive.org/web/20230320171406/https://github.com/withfig/autocomplete/pull/703
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bun completion spec #703

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicholasoxford
Copy link
Contributor

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Additional info:

@withfig-bot
Copy link
Collaborator

Overview

src/bun.ts:

Info:

Script:
until [[ -f package.json ]] || [[ $PWD = '/' ]]; do cd ..; done; cat package.json
postProcess(function):

 function (out, [npmClient]) {
    if (out.trim() == "") {
      return [];
    }

    try {
      const packageContent = JSON.parse(out);
      const scripts = packageContent["scripts"];
      const figCompletions = packageContent["fig"] || {};

      if (scripts) {
        return Object.entries(scripts).map(([scriptName, scriptContents]) => {
          const icon =
            npmClient === "yarn"
              ? "fig://icon?type=yarn"
              : "fig://icon?type=npm";
          const customScripts: Fig.Suggestion = figCompletions[scriptName];
          return {
            name: scriptName,
            icon,
            description: scriptContents as string,
            /**
             * If there are custom definitions for the scripts
             * we want to overide the default values
             * */
            ...customScripts,
          };
        });
      }
    } catch (e) {
      console.error(e);
    }

    return [];
  }
@withfig-bot
Copy link
Collaborator

Hello @nicholasoxford,
thank you very much for creating a Pull Request!
Here is a small checklist to get this PR merged as quickly as possible:

  • Do all subcommands / options which take arguments have the arg property (arg: {})?
  • Are all options modular? E.g. a -u -x instead of -aux
  • Have all other checks passed?

Please add a 👍 as a reaction to this comment to show that you read this.


/** Generator that lists package.json scripts (with the respect to the `fig` field) */
export const bunScriptsGenerator: Fig.Generator = {
script:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to get this same information faster & more accurately via bun getcompletes s. I need to add support for returning the contents of the script rather than just the script name, but I'm happy to do that.

description: "Bundle dependencies of input files into a .bun",
},
{
name: "create",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bun c shorthand exists for bun create - should be ["c", "create"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants