19

Gallery · relastle/pmy Wiki · GitHub

 4 years ago
source link: https://github.com/relastle/pmy/wiki/Gallery
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Table of Contents generated with DocToc

Gallery of pmy's application

Template is here.


Git completion (using zsh-capture-completion )

If you want to use zsh's completion candidates as fzf source directly, using https://github.com/Valodim/zsh-capture-completion is very reasonable.

GIF (demonstration)

git global

Requirements

  • capture.zsh executable in your $PATH

JSON rule

[
  {
    "regexpLeft": "(?P<body>^git.*) -{1,2}(?P<query>[^\\s]*)$",
    "cmdGroups": [
      {
        "tag": "",
        "stmt": "capture.zsh '<body> -' | sed 's/\r//g'",
        "after": "awk '{print $1}'"
      }
    ],
    "fuzzyFinderCmd": "fzf -0 -1 --ansi -n 1 -q '<query>'",
    "bufferLeft": "<body> ",
    "bufferRight": "[]"
  },
  {
    "regexpLeft": "(?P<body>^git.*) (?P<query>[^\\s]*)$",
    "cmdGroups": [
      {
        "tag": "",
        "stmt": "capture.zsh '<body> ' | sed 's/\r//g' | grep --color=always '<query>'",
        "after": "awk '{print $1}'"
      }
    ],
    "fuzzyFinderCmd": "fzf -0 -1 --ansi -n 1 -q '<query>'",
    "bufferLeft": "<body> ",
    "bufferRight": "[]"
  }
]

Most command completion using zsh-capture-completion

Like git example above, by using zsh-capture-completion, you can complete using fzf using zsh completion candidates in almost all situations

NOTE: Using such widely matched regular expression rule might break other settings. So it is recommended to write it to bottom of rules(low priority) or use command-specific rules described above (git example).

GIF (demonstration)

all

Requirements

  • capture.zsh executable in your $PATH

JSON rule

[
  {
    "regexpLeft": "(?P<body>.*) -{1,2}(?P<query>[^\\s]*)$",
    "cmdGroups": [
      {
        "tag": "",
        "stmt": "capture.zsh '<body> -' | sed 's/\r//g'",
        "after": "awk '{print $1}'"
      }
    ],
    "fuzzyFinderCmd": "fzf -0 -1 --ansi -n 1 -q '<query>'",
    "bufferLeft": "<body> ",
    "bufferRight": "[]"
  },
  {
    "regexpLeft": "(?P<body>.*) (?P<query>[^\\s]*)$",
    "cmdGroups": [
      {
        "tag": "",
        "stmt": "capture.zsh '<body> ' | sed 's/\r//g' | grep --color=always '<query>'",
        "after": "awk '{print $1}'"
      }
    ],
    "fuzzyFinderCmd": "fzf -0 -1 --ansi -n 1 -q '<query>'",
    "bufferLeft": "<body> ",
    "bufferRight": "[]"
  },
]

git checkout/co

GIF (demonstration)

git co

Requirements

JSON rule

{
"regexpLeft": "(?P<body>git (co|checkout)) *(?P<query>.*)$",
"cmdGroups": [
  {
    "tag": "🌱:branch",
    "stmt": "git branch --format=\"%(refname:short)\" 2>/dev/null",
    "after": "awk '{print $0}'"
  },
  {
    "tag": "🔖:tag",
    "stmt": "git tag 2>/dev/null",
    "after": "awk '{print $0}'"
  },
  {
    "tag": "🍺:commit",
    "stmt": "git log --oneline -30 --color 2>/dev/null",
    "after": "awk '{print $1}'"
  }
],
"fuzzyFinderCmd": "fzf -0 -1 --ansi -q \"<query>\"",
"bufferLeft": "<body> ",
"bufferRight": "[]"
}

git cherry-pick/cp

GIF (demonstration)

git cp

Requirements

JSON rule

{
  "regexpLeft": "git (cp|cherry-pick) *$",
  "cmdGroups": [
    {
      "tag": "🍒:commit",
      "stmt": "git log --oneline --branches --tags",
      "after": "awk '{print $1}'"
    }
  ],
  "bufferLeft": "[]",
  "bufferRight": "[]"
}

git subcommand completion

completion of git subcommand (with its description shown).

NOTE: In almost all cases, your need is accomplished by capture.zsh. However, you sometimes need to prepare arbitrary snippet for completion. In this example, git subcommand and its description is provided by a snippet.

GIF (demonstration)

git sub

JSON rule

{
"regexpLeft": "^git (?P<query>[a-z]*)$",
"cmdGroups": [
  {
    "tag": "",
    "stmt": "%git_sub%",
    "after": "awk '{print $1}'"
  }
],
"fuzzyFinderCmd": "fzf -0 -1 -n 1 -q \"<query>\"",
"bufferLeft": "git ",
"bufferRight": "[]"
}

Snippet file (if necessary)

save below as git_sub_pmy_snippet.txt under your $PMY_SNIPPET_PATH.

clone      Clone a repository into a new directory
init       Create an empty Git repository or reinitialize an existing one
add        Add file contents to the index
mv         Move or rename a file, a directory, or a symlink
reset      Reset current HEAD to the specified state
rm         Remove files from the working tree and from the index
bisect     Use binary search to find the commit that introduced a bug
grep       Print lines matching a pattern
log        Show commit logs
show       Show various types of objects
status     Show the working tree status
branch     List, create, or delete branches
checkout    Switch branches or restore working tree files
commit     Record changes to the repository
diff       Show changes between commits, commit and working tree, etc
merge      Join two or more development histories together
rebase     Reapply commits on top of another base tip
tag        Create, list, delete or verify a tag object signed with GPG
fetch      Download objects and refs from another repository
pull       Fetch from and integrate with another repository or a local branch
push       Update remote refs along with associated objects

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK