-
Notifications
You must be signed in to change notification settings - Fork 3
Gallery
Table of Contents generated with DocToc
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.
-
capture.zsh
executable in your$PATH
[
{
"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).
-
capture.zsh
executable in your$PATH
[
{
"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": "[]"
},
]
{
"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": "[]"
}
{
"regexpLeft": "git (cp|cherry-pick) *$",
"cmdGroups": [
{
"tag": "🍒:commit",
"stmt": "git log --oneline --branches --tags",
"after": "awk '{print $1}'"
}
],
"bufferLeft": "[]",
"bufferRight": "[]"
}
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.
{
"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": "[]"
}
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