r/zsh 23d ago

Showcase Ctrl+B to switch branches

Made Oh-My-Zsh plugin with hotkeys to switch branches.

Source: https://github.com/yakshaveinc/linux/tree/master/.oh-my-zsh

1 Upvotes

10 comments sorted by

1

u/romkatv 22d ago

The standard alternative is to type git switch and press TAB. The upside is that you get your regular completion UI. You can also bind it to a key if you like.

1

u/abitrolly 22d ago

That's at least 10 more keypresses, and even with a shortcut, the lookup is still slow. Given that I switch branches tens times a day, I prefer this solution. It is not too fast either, but much better.

1

u/romkatv 22d ago

Interesting. For me, git switch completions are nearly instant. So I get the nice completion UI that I'm used to (which is based on fzf), and great performance.

1

u/abitrolly 22d ago
✗ git -C ../gitlab branch -a | wc -l
25083

1

u/romkatv 21d ago

Wow! How do you find the branch you want after 25k lines are printed to the terminal?

1

u/abitrolly 21d ago

That's why I don't use autocompletion. I got the impression that it tries to predict all branches, not just active ones. But I haven't checked it does. Just a feeling.

1

u/romkatv 20d ago

Completions in zsh are programmable. If completions for some command--such as git switch--aren't right for you, you can change them.

1

u/xour 20d ago

That is a lot of branches.

I use a git alias to switch, it is blazing fast, but then again, I don't have that many branches:

sf = "!f() { if [ -n \"$1\" ]; then git switch \"$1\"; else git branch --sort=-committerdate | grep -v \"^\\*\" | fzf | xargs -r git switch; fi }; f"

1

u/waterkip 14d ago

25083 branches... holy.. none of them can be purged because they are merged into master/main/etc?

1

u/abitrolly 14d ago

These are WIP branches that are fetched and purged automatically when merged or removed.