Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Saving time with fzf

One of my favourite terminal utilities is a little utility called fzf (fuzzy finder). It’s how I save a bunch of time by not writing out commands, or even remembering them.The thing I use fzf for the most is Command history. To access the history, I use Ctrl+R and I get a list of my most recent commands:(The numbers represent the position of that command in my .zsh_history file.)If I then write the word “serve”, fzf will only show me commands with that word in it:I usually use this for running some different Rails apps on certain ports. So I would hit Ctrl+R, and then type a particular port number such as 3004 to get:Instead of typing out the full command, I can type Ctrl+R and 4 keystrokes later arrive at the right command.Another thing I use fzf for is its relative file searching. Most of the time, I’m using this to run RSpec tests. I type:(Which is my alias for “bundle exec rspec”), and then I hit Ctrl+T and I get a list of files in my terminal:Then I can type a few words, or even parts of words, to get what I’m after. In this example, I’d like to find the file at spec/requests/graphql/queries/repo_categories_spec.rb. What a mouthful! With fzf, I can type repocat and arrive at that spec in only seven keystrokes:When I hit enter here, my ber command becomes:Then I can run this test.(If I’ve run this command before, I might use Ctrl+R to find the “full version” of ber + the file path!)Finally, the last way I use fzf is to filter output. You can pipe a list of inputs to fzf and it will provide its fuzzy finding features on that list.The way I use this the most is this very complicated looking function:I didn’t come up with this myself, but I borrowed it from elsewhere.This command finds the 30 most recent Git branches (surely more than adequate!) and provides a way of filtering through them. Here’s what I see when I run fbr in a gem I have checked out:If I type the word locale and hit enter, the git checkout command will switch me into that branch.I find this one really useful when I can only half-remember a branch name, or if I’ve got a branch with an issue number in it, then I can jump straight to that branch if I know the number.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Saving time with fzf

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×