Skip to main content
  1. Posts/

How to get fzf working in PowerShell

··462 words·3 mins·
DevOps Tips & How-To's Fzf Powershell Opensource
Table of Contents

What’s fzf?
#

Have you ever been in a situation where you’re trying to recall some program or command that you entered in your terminal a while back and can’t recall the exact command? Wouldn’t it be nice if you could do a search in your terminal history loosely based on what you’d typed previously? Enter fzf, for that’s what it does. fzf is a command-line fuzzy finder (hence ‘fzf’) that can look at your shell command history, processes, bookmarks and more.

fzf is a seriously awesome tool and every single of my *nix boxes have it installed. However, I use Windows a fair bit and wanted to see if there’s a way to get fzf running for PowerShell. Thanks to Michael Kelley and PSFzf this is possible!

PSFzf
#

PSFzf is a PowerShell module that wraps fzf. This means you can use all the goodness of fzf in a PowerShell session.

Installing
#

You can install PSFzf and fzf via a package manager like Chocolatey or Scoop. I used Scoop to install fzf. Before you proceed, install Scoop using the below command in a PowerShell session as mentioned in Scoop’s website.

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser # Optional: Needed to run a remote script the first time
irm get.scoop.sh | iex # irm == invoke web request, ie download this file. iex == invoke expression, ie, evaluate the command.

Install fzf using the below command.

scoop install fzf

Now install PSFzf using the below command

Install-Module -Name PSFzf

Using
#

Now that they are installed, you’ll need to update your PowerShell profile file so that the keybindings are installed and PSFzf is ready to use.

From your PowerShell terminal, open an editor with the location of your PowerShell profile file. This is easily done by the below command in a PowerShell session

notepad $PROFILE

Notepad should open a file called Microsoft.PowerShell_profile.ps1. Don’t be surprised if it’s empty. Paste the below command

Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r'

This will map Ctrl+t to invoke PSReadline. This also maps Ctrl+r to show the last few commands you used. Save it, close your editor and open a new PowerShell session.

So, if you want to search for a previous command, press Ctrl+r and you’ll get a prompt and fzf will show the last few commands you had used. Here, you can type what you want to search for, and fzf will search and show the matching commands. In the example below see how fzf shows the commands related to docker run passing an environment variable, even though my command is only searching for fraction of it.

“Example of docker run command passing an environment variable”

You can save a lot of time by this approach I’m sure. Hope this helps. Note: If PowerShell is not your thing, you can install this on Linux/Mac as well.

Sathyajith Bhat
Author
Sathyajith Bhat
Author, AWS Container Hero and DevOps Specialist.

Related

Self-hosting FreshRSS (for free) on Fly.io in under 10 minutes
··621 words·3 mins
DevOps Self-Hosting Fly.io
Here’s how you can self-host FreshRSS on Fly.io in under 10 minutes
Migrating Route 53 records from Latency Based Routing to Geolocation routing with zero downtime
··1265 words·6 mins
DevOps Route 53 DNS Aws
I had some fun playing with Route 53’s routing policies.
Notes on moving Amazon Linux AMI to Amazon Linux 2
··435 words·3 mins
DevOps Packer Aws AMI
I picked up a task to migrate our base image from Amazon Linux to Amazon Linux 2. Here’s what I needed to get it to work.