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

[git] add Wildcard Suggestions #358

Merged
merged 6 commits into from
Jul 13, 2021
Merged

Conversation

ankithm28
Copy link
Contributor

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Add Wildcard Generator for staging files in git

What is the current behavior? (You can also link to an open issue here)
Issue #73
Revision of PR #349

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

Checks for matching paths of committed files and adds a suggestion for a wildcard.

@withfig-bot
Copy link
Collaborator

withfig-bot commented Jul 12, 2021

Overview

dev/git.ts:

Info:

Script:
git log --oneline
postProcess(function):

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

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

      return output.split("\n").map((line) => {
        return {
          name: line.substring(0, 7),
          icon: "fig://icon?type=node",
          description: line.substring(7),
        };
      });
    }

Script:
git config --get-regexp '^alias' |cut -d. -f2
postProcess(function):

 function (out) {
      return out.split("\n").map((aliasLine) => {
        const splitted = aliasLine.match(/^(\S+)\s(.*)/);
        return { name: splitted[1], description: splitted[2] };
      });
    }

Script:
git stash list
postProcess(function):

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

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

      return output.split("\n").map((file) => {
        return {
          name: file.split(":")[2],
          insertValue: file.split(":")[0],
          icon: `fig://icon?type=node`,
        };
      });
    }

Script:
git diff --cached --name-only
postProcess(function):

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

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

      return output.split("\n").map((file) => {
        return {
          name: file,
          insertValue: "-- " + file,
          icon: `fig://icon?type=file`,
          description: "staged file",
        };
      });
    }

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",
        };
      });
    }

Script:
git remote -v
postProcess(function):

 function (out) {
      const remoteURLs = out.split("\n").reduce((dict, line) => {
        const pair = line.split("\t");
        const remote = pair[0];
        console.log(remote, pair);
        const url = pair[1].split(" ")[0];

        dict[remote] = url;
        return dict;
      }, {});

      return Object.keys(remoteURLs).map((remote) => {
        const url = remoteURLs[remote];
        let icon = "box";
        if (url.includes("github.com")) {
          icon = "github";
        }

        if (url.includes("gitlab.com")) {
          icon = "gitlab";
        }

        if (url.includes("heroku.com")) {
          icon = "heroku";
        }
        return {
          name: remote,
          icon: `fig://icon?type=${icon}`,
          description: "remote",
        };
      });
    }

Single Scripts:

  • git tag --list
  • git status --short
  • git diff --name-only --cached
  • git diff --name-only

URLs:

  • http://developercertificate.org
  • http://developercertificate.org

@withfig-bot
Copy link
Collaborator

Hello @monkeyank,
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.

Copy link
Contributor

@QuiiBz QuiiBz left a comment

Choose a reason for hiding this comment

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

LGTM!

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

Successfully merging this pull request may close these issues.

None yet

3 participants