I have been a Vim user for 12 years and one important thing that you learn the first days using it is that you can be super efficient typing commands to complete what you are trying to do. I spend almost all my day coding in front of a console and at some point you realize that not only you can DRY your code, but your daily console commands also. From time to time, I really like to stop for a while and think about all the commands I have typed and see if I can execute them faster. Few months ago, a friend of mine was trying to polish his daily pain points too and he created this awesome plugin for tmux called but I decided to take another path. At the same time I discovered and I thought it would be an interesting to play with. tmux-fingers FZF tool This command-line fuzzy finder does one thing and does it well, just like the most ancient commands in . It takes an input and you can filter it to choose what you want in a interactive shell. So you can do things like this example: UNIX asciinema.org find + fzf I recommend to you to play with it a bit and start thinking about all the possibilities you can do with it. Review all the available FZF options and you will discover gems like multiselection (-m). So, how do you shuffle FZF and Git to get this posts’ topic answered? Think about common git use cases that you do every day and you are going to think of things like this: Switch between branches Review some specific commit Do interactive rebases Edit changed files in a commit We are going to get our hands dirty with one example: git log --pretty=oneline | fzf After executing the command below, you realize that you can search for a commit in you repository in an interactive way. If you press , the FZF’s output will be the selected line you chose. Now, try to execute this: ENTER git show $(git log --pretty=oneline | fzf | cut -d=' ' -f1) And you will get you first interactive git show. Hooray! :p Use cases Now take a breath and go through those use cases I detected in my daily workflows that apply to you. All my fuzzy git commands start with . pam Switch between branches This is a classic use case. You want to switch to some branch where you have been recently. I execute this: git pam Internally what this command is doing is: git checkout $(git recent | fzf) _git branch + fzf_asciinema.org git pam Edit uncommitted files This is another classic use case. You want to edit some non committed file you are working on. I execute this: git pamvim Internally what this command is doing is: vim $(git status -s | fzf -m) This command supports multiselection! _fzf + git + vim_asciinema.org git pamvim Interactive rebase This is getting interesting… You want to start a interactive rebase from some specific commit and you want to select it. I execute this: git pamrebase Internally what this command is doing is: git rebase -i $(git log --pretty=oneline | fzf)^ _git rebase + fzf_asciinema.org git pamrebase Edit files in a commit Another useful command. You want to edit some files that were changed in some specific commit and you want to select it. I execute this: git pamvimlog Note: check my out to know how it works. dotfiles This command supports multiselection! _vim + git + fzf_asciinema.org git pamvimlog Interactive fixup And my last example. You want to do a fixup in some specific commit and you want to select it. I stage some changes and then I execute this: git pamfix _fixup + fzf_asciinema.org git pamfix Conclusion If you are interested in more useful commands like those, check my out. dotfiles Happy hacking! Thanks for reading, Ferran Basora http://github.com/fcsonline/ Like this? Please give it some ♥ and share it! is how hackers start their afternoons. We’re a part of the family. We are now and happy to opportunities. Hacker Noon @AMI accepting submissions discuss advertising &sponsorship To learn more, , , or simply, read our about page like/message us on Facebook tweet/DM @HackerNoon. If you enjoyed this story, we recommend reading our and . Until next time, don’t take the realities of the world for granted! latest tech stories trending tech stories
Share Your Thoughts