Skip to content

Instantly share code, notes, and snippets.

@richstokes
Last active January 7, 2022 19:40
Show Gist options
  • Save richstokes/bcdfac677e3881e9e88e9ab47fbbdd65 to your computer and use it in GitHub Desktop.
Save richstokes/bcdfac677e3881e9e88e9ab47fbbdd65 to your computer and use it in GitHub Desktop.
zsh git branch switcher
## Add this to your `~/.zshrc` file to have CTRL+G let you select your recent branches
## Open a new terminal, or run `source ~/.zshrc` after adding
## Requires: fzf (`brew install fzf`)
# Function to select recent branches
function gsl() {
git switch -q $(git for-each-ref refs/heads --format='%(refname)' --sort='committerdate' | cut -d'/' -f3- | fzf +s --tac --preview='git log --oneline {} | head -20')
zle reset-prompt
}
# Create a ZSH "Widget" and bind to key (CTRL+G here)
zle -N gsl-widget gsl
bindkey '^g' gsl-widget
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment