zsh (or PowerShell) + fzf + git
After loading git-pick (see Installation) these keybinds are set:
- Ctrl-gCtrl-s Add status files to the command line.
- Ctrl-f Includes excluded items (
GP_STATUS_EXCLUDE) in fzf's list. - Ctrl-a Toggles selecting all items from fzf's list.
- Tab Toggle current item selection.
- Ctrl-f Includes excluded items (
- Ctrl-gCtrl-w Add worktree path to the command line.
- Ctrl-a Toggles selecting all items from fzf's list.
- Tab Toggle current item selection.
- Ctrl-gCtrl-h Add the HEAD to the command line.
Usage examples:
git add <Ctrl-g><Ctrl-s>
git push -u origin <Ctrl-g><Ctrl-h>
cd <Ctrl-g><Ctrl-w>
Warning
Ctrl-gCtrl-s does not work if flow control is enabled, stty -ixon disables flow control.
Excluding files from gp-status (Ctrl-gCtrl-s)
Set GP_STATUS_EXCLUDE=1 before loading git-pick so
Ctrl-gCtrl-s leaves specific files out of fzf's list:
GP_STATUS_EXCLUDE=1
eval "$(git-pick init zsh)"
# Use case:
# Exclude from `git add` files modified for app startup purposes.
# $ git add <Ctrl-g><Ctrl-s>
# File: ~/.zshrcIn PowerShell, set $GP_STATUS_EXCLUDE = 1 before loading git-pick.
The exclusions are defined per directory, in a .gitpickignore file. On each
Ctrl-gCtrl-s the closest such file is looked up: the lookup starts
at the cwd and walks up the parent dirs, stopping at ${HOME} or /. The first file
found wins; files higher up are not merged in. When no file is found nothing is excluded.
The file is in gitignore syntax, so its comment,
escaping and pattern rules are the ones from .gitignore. Example contents of a
.gitpickignore file placed at the root of a repository:
# Files modified for app startup purposes.
Makefile
compose.yaml
src/main/resources/application-*.yml
!src/main/resources/application-prod.yml
src/main/resources/db/migration/
# File: ./.gitpickignoreOnly the patterns which excluded at least one file are listed in fzf's header, each
followed by how many files it excluded, as in src/main/resources/application-*.yml (2).
Press Ctrl-f to list the full status.
The matching runs in an empty repository cached at ${XDG_CACHE_HOME:-~/.cache}/git-pick,
created on first use, so that .gitpickignore is the only exclude source Git
considers. Otherwise the repo's .gitignore would take precedence over it, leaving a
filepath which is tracked and gitignored impossible to exclude.
Add .gitpickignore to your global .gitignore.
Transforming HEAD with gp-head-map
Set GP_HEAD_MAP_REGEX and use gp-head-map to put only the HEAD's first match of the
regex in the zsh buffer (its group 1 when it has one, else the whole match). Nothing is put
when it does not match. The regex is Go's syntax
(RE2). Example:
# Jira ticket key, e.g., ABC-123.
GP_HEAD_MAP_REGEX='[A-Z]+-[0-9]+'
eval "$(git-pick init zsh)"
bindkey "^g^k" gp-head-map
# Use case:
# Prefix the ticket key to each commit message:
# $ git commit -m '<Ctrl-g><Ctrl-k>
# File: ~/.zshrcIn PowerShell, set the variable before loading git-pick and bind Invoke-GpHeadMap:
$GP_HEAD_MAP_REGEX = '[A-Z]+-[0-9]+'
Invoke-Expression (& git-pick init pwsh | Out-String)
Set-PSReadLineKeyHandler -Chord 'Ctrl+g,Ctrl+k' -ScriptBlock { Invoke-GpHeadMap }
# File: $PROFILEFirst, install fzf and the git-pick binary. With
mise:
mise use -g github:hernancerm/git-pickOR: Download it from releases and add
to $PATH.
Load git-pick from ~/.zshrc:
eval "$(git-pick init zsh)"
# File: ~/.zshrcOR: If you want to set custom keybinds then use:
GP_SET_KEYBINDS=0
eval "$(git-pick init zsh)"
bindkey "^g^s" gp-status
bindkey "^g^w" gp-worktrees
bindkey "^g^h" gp-head
# File: ~/.zshrcOR: If you use jeffreytse/zsh-vi-mode:
GP_SET_KEYBINDS=0
eval "$(git-pick init zsh)"
function zvm_after_init {
zvm_define_widget gp-menu
# ZVM does not handle chords well, prefer gp-menu.
zvm_bindkey viins "^g" gp-menu
}
# File: ~/.zshrcLoad git-pick from $PROFILE:
Invoke-Expression (& git-pick init pwsh | Out-String)
# File: $PROFILEOR: If you want to set custom keybinds then use:
$GP_SET_KEYBINDS = 0
Invoke-Expression (& git-pick init pwsh | Out-String)
Set-PSReadLineKeyHandler -Chord 'Ctrl+g,Ctrl+s' -ScriptBlock { Invoke-GpStatus }
Set-PSReadLineKeyHandler -Chord 'Ctrl+g,Ctrl+w' -ScriptBlock { Invoke-GpWorktrees }
Set-PSReadLineKeyHandler -Chord 'Ctrl+g,Ctrl+h' -ScriptBlock { Invoke-GpHead }
# File: $PROFILERun the tests with go test ./.... To try a change, build the binary onto $PATH, ahead
of any installed release:
go build -o ~/.local/bin/git-pick .If you installed git-pick globally with mise, register your build as a mise version
named dev, once:
mise link github:hernancerm/git-pick@dev "$PWD"Select it in ~/.config/mise/config.local.toml, which overrides the global config:
[tools]
"github:hernancerm/git-pick" = "dev"Then build into the repo's bin/, which mise runs from:
mise run build