Skip to content

Instantly share code, notes, and snippets.

@shibayu36
Created June 27, 2014 13:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibayu36/6e88877cf82f7cf75b08 to your computer and use it in GitHub Desktop.
Save shibayu36/6e88877cf82f7cf75b08 to your computer and use it in GitHub Desktop.
function peco-git-recent-branches () {
local selected_branch=$(git for-each-ref --format='%(refname)' --sort=-committerdate refs/heads | \
perl -pne 's{^refs/heads/}{}' | \
peco)
if [ -n "$selected_branch" ]; then
BUFFER="git checkout ${selected_branch}"
zle accept-line
fi
zle clear-screen
}
zle -N peco-git-recent-branches
function peco-git-recent-all-branches () {
local selected_branch=$(git for-each-ref --format='%(refname)' --sort=-committerdate refs/heads refs/remotes | \
perl -pne 's{^refs/(heads|remotes)/}{}' | \
peco)
if [ -n "$selected_branch" ]; then
BUFFER="git checkout -t ${selected_branch}"
zle accept-line
fi
zle clear-screen
}
zle -N peco-git-recent-all-branches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment