FZF: interactivity as a service or how to make ssh interactive
CLIs are very powerful, but they often lack in interactivity. When interactivity is added, it’s often as a feature for a specific CLI, and not something that can be plugged on any one of them.
Yet, that’s exactly what Fzf proposes!
Let’s see how this works by making ssh interactive.
1. Fzf value proposition
Fzf takes a list of lines as input, and lets the user search, filter and select one (or many) of them, and passes it to its output.
Here is a very simple example:
echo -e 'option1\noption2\noption3' | fzf
2. Interactive SSH
Let’s say you often connect to many known ssh hosts.
Instead of having to search through your shell history each time you want to ssh into a specific host, or simply making typo, you can make that process interactive.
First, save the list of hosts in a file:
host1.com hosta.net host_78.org
Then, you can use the following script to interactively select, and ssh into one of those hosts:
set -e server="$(cat hosts.txt | fzf)" ssh "my_username@$server"
You can use fzf in many more ways, give it a try! Some use cases are so common that they come pre-installed by default:
Ctrl-Rlets you search and filter your shell history;
Alt-Clets you filter and
cdinto one of the sub directories.
Many more examples (archive) are there to give you ideas.