I think pretty much all software developers have faced the situation where they get introduced to a new
codebase — or some directory they don’t know that much — and they don’t really know their place around.
The idea is that one would like to move to a specific folder, but does not remember exactly the path to it.
Another situation is when someone wants to apply a command to a bunch of files, and a glob cannot really be
used, like *.txt
, because one would want only specific files — like {foo,bar}.txt
for instance.
Most of the time, if you are a CLI/TUI enjoyer, you will likely have a similar workflow to this:
ls
to show the directories. You will locate the first directory you want to go to.cd <that-dir>
.ls
again to show what’s there.cd <another-dir>
.- Repeat until you are at the place you want.
I don’t think I need to debate on the fact that this is a very time-wasting workflow, and honestly not very
pleasant. Most shells today allow you to do something like cd <tab>
and have a way to virtually visit the
directories, until you find the one you want. Press <return>
and your command is completed. You can use the
same method for tar-ing files, removing files, running arbitrary commands, etc.
Another interesting way of doing that is to use a fuzzy finder, like fzf or skim. I would usually just do
cd ^t
. That works when you know exactly what you are looking for, which is not exactly the situations we are talking about here.
The cd
example is what motivated me to make a small tool that I named flirt, but along the way, I realized
it could do much more interesting things, without expanding its scope and not violating the UNIX philosophy.
FiLe InteRacT, the file interaction tool for your CLI
I never liked file browsers, like nnn, lf or yazi. They look cool, but there is something too much about them. I like the Kakoune’s way. I think the UI from file browsers is interesting, but I think we could use it in a much more barebone/simple (and UNIX) way. The idea is to use it as a read-only UI, and let other tools compose around it.
For instance, let’s take the cd
example from before, where we go to a directory by interleaving cd
and ls
commands. What do we want to actually do?
- Locate a directory.
cd
into it.
flirt
allows to implement the first part. You can do something like cd $(flirt)
— or cd ^s
for a shell
shortcut integration, which I highly recommend — and move around directories until you have found the one
you are interested in. Quit flirt
, and you have your CLI set to cd <path>
. Just press <return>
to jump
to that directory.
This is a simple workflow, because it allows you to think of flirt
just as a read-only view into your
filesystem. But it can do much more.
Arbitrary files selection and reordering
flirt
can select multiple files. Why would you want to select many files? Well, imagine that you want
to select a bunch of files and put them in a directory. It’s a pretty cumbersome operation to do manually
on the CLI, because you have to type a lot of text to just pick the files you want to feed your mv
command.
With flirt
, you can do something like mv ^s
and pick the files you want.
Because flirt
is ordered — you can see the order on the right-side view and switch between the left and right
views with the <tab>
key by default — you can ensure the destination directory is the last argument — interactively.
Unlocking the full potential with other UNIX tools
Have you heard about moreutils? It’s a collection of UNIX tools that go a bit further in terms of composability. One
of those tools, vipe
, is a pipe editor: it reads from stdin and pipes its content to your $EDITOR
. Once you have
finished editing your buffer and quit your editor, it will pipe the modified data back into its stdout:
cmd1 | vipe | cmd2
Composing with flirt
is super easy and you can implement interesting workflows, such as with:
flirt | vipe | sh
Which allows you to select a bunch of files on which operate commands — that you add in your editor, via vipe
— and
execute the output script!
If you are interested, you can find flirt here, along with some additional links:
- Discussion mailing list
- Development mailing list (send your patches here!)
- Feature requests / bug reports
If you have cargo
installed, you can install flirt
easily:
cargo install flirt
I might add a
PKGBUILD
for Archlinux at some point.
Do not hesitate to send your feedback on the discussion mailing list! Keep the vibes!