autocomplete icon indicating copy to clipboard operation
autocomplete copied to clipboard

feat(yarn): show more executable packages

Open fedeci opened this issue 3 years ago • 2 comments
trafficstars

Closes #1211

fedeci avatar May 08 '22 13:05 fedeci

Overview

src/ls.ts:

Info:

src/yarn.ts:

Info:

Script: yarn config list postProcess(function):

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

    try {
      const startIndex = out.indexOf("{");
      const endIndex = out.indexOf("}");
      let output = out.substring(startIndex, endIndex + 1);
      // TODO: fix hacky code
      // reason: JSON parse was not working without double quotes
      output = output
        .replace(/\'/gi, '"')
        .replace("lastUpdateCheck", '"lastUpdateCheck"')
        .replace("registry", '"lastUpdateCheck"');
      const configObject = JSON.parse(output);
      if (configObject) {
        return Object.keys(configObject).map((key) => ({ name: key }));
      }
    } catch (e) {}

    return [];
  }

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

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

    try {
      const packageContent = JSON.parse(out);
      const dependencies = packageContent["dependencies"] ?? {};
      const devDependencies = packageContent["devDependencies"];
      const optionalDependencies = packageContent["optionalDependencies"] ?? {};
      Object.assign(dependencies, devDependencies, optionalDependencies);

      return Object.keys(dependencies)
        .filter((pkgName) => {
          const isListed = context.some((current) => current === pkgName);
          return !isListed;
        })
        .map((pkgName) => ({
          name: pkgName,
          icon: "📦",
          description: dependencies[pkgName]
            ? "dependency"
            : optionalDependencies[pkgName]
            ? "optionalDependency"
            : "devDependency",
        }));
    } catch (e) {
      console.error(e);
      return [];
    }
  }

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

 function (context) {
    if (context[context.length - 1] === "") return "";
    const searchTerm = "create-" + context[context.length - 1];
    return `curl -s -H "Accept: application/json" "https://api.npms.io/v2/search?q=${searchTerm}&size=20"`;
  }

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

 function (out) {
    try {
      return JSON.parse(out).results.map(
        (item) =>
          ({
            name: item.package.name.substring(7),
            description: item.package.description,
          } as Fig.Suggestion)
      ) as Fig.Suggestion[];
    } catch (e) {
      return [];
    }
  }

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

 function (out: string) {
                    if (out.trim() == "") {
                      return [];
                    }
                    try {
                      const packageContent = JSON.parse(out);
                      const scripts = packageContent["scripts"];
                      if (scripts) {
                        return Object.keys(scripts).map((script) => ({
                          name: script,
                        }));
                      }
                    } catch (e) {}
                    return [];
                  }

URLs:

  • https://api.npms.io/v2/search?q=

src/pnpm.ts:

Info:

Script: git branch --no-color postProcess(function):

 function (out) {
    const output = filterMessages(out);

    if (output.startsWith("fatal:")) {
      return [];
    }

    return output.split("\n").map((elm) => {
      let name = elm.trim();
      const parts = elm.match(/\S+/g);
      if (parts.length > 1) {
        if (parts[0] == "*") {
          // Current branch.
          return {
            name: elm.replace("*", "").trim(),
            description: "Current branch",
            icon: "⭐️",
          };
        } else if (parts[0] == "+") {
          // Branch checked out in another worktree.
          name = elm.replace("+", "").trim();
        }
      }

      return {
        name,
        description: "Branch",
        icon: "fig://icon?type=git",
      };
    });
  }

withfig-bot avatar May 08 '22 13:05 withfig-bot

Hello @fedeci, 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 include the args property (args: {})?
  • [ ] 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.

withfig-bot avatar May 08 '22 13:05 withfig-bot

Status update on this? Directly related to this: https://github.com/withfig/autocomplete/issues/1211

brendanfalk avatar Nov 23 '22 18:11 brendanfalk