fzf is an awesome tool for filtering and selecting lists of things on the command line.
In addition to the autocomplete for
kill, we can use
to pick from other lists as well. We can roughly reconstruct
the behavior with a chain of other commands.
Let's do something a bit more fun. We can boot up a kube cluster using GKE, then interactively select a pod to exec into. First let's create a cluster and start a sample pod.
We can check to make sure the pod is running by getting the pods.
fzf, we can construct a command which will let
us interactively pick a pod to exec into.
Pick the pod (of which there's only one for us right now).
This will get you a shell in a pod something like this, which you can then use and exit.
xargs arguments are pretty crucial here.
-I % allows
us to use
% in our command at any arbitrary point.
will get replaced with the pod name.
If we didn't use
kubectl would error out complaining
about not having a tty.