Last active
January 7, 2022 19:40
-
-
Save richstokes/bcdfac677e3881e9e88e9ab47fbbdd65 to your computer and use it in GitHub Desktop.
zsh git branch switcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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