lf
lf enables very efficient file
management workflows when combined with other tools. In this article, I will
explain how I use it alongside sxhkd
, fzf
and
dragcli
.
sxhkd
First of all, I use sxhkd
for my
keybinds. Here is the relevant excerpt:
control + alt + r $TERMINAL -e lfNot only is it fast to start, it is also fast to quit: since I run
lf
in a shell like bash
, the window disappears as soon
as I hit q
. Note that this keybinding only makes sense because I
swap the Control and Caps Lock keys.
I do also invoke lf
from my shell when I need to peek at/manage
files in the context of a long running session and I know that I will go back to
my shell shortly after. I also use it to change directory when I need to go far
from the current directory (otherwise, typing the path is often faster). To
enable that, I have the following snippet in my .bashrc
:
lf() { tmp="$(mktemp)" command lf -last-dir-path="$tmp" "$@" cd "$(cat "$tmp")" rm -f "$tmp" }This way, my shell's directory is changed for the one in which I left
lf
.
lf
can be navigated using hjlk
or the arrow keys.
Files can be selected with the Space key. Hitting l
or the right
arrow key will open the currently selected file(s). They can then be copied
(yanked) with y
or cut with d
and then pasted
elsewhere with p
. It is not necessary to select with Space to
operate on a single file. A copy/cut can be cleared with c
. A file
can be renamed with r
. v
will invert the current
selection, which is useful to select all/most of the files in a directory. It is
possible to start a search by hitting /
, to stop it by hitting
Enter or to cancel it by hitting Escape.
Because lf
has a client/server architecture, it is possible to copy
files from one instance of it and paste them in another one.
It is possible to enter commands by hitting :
. Available commands
include doc
, delete
and many others. These commands
support Tab completion with a nice popup menu.
lf
is configured via ~/.config/lf/lfrc
. Here are some
general options:
set shell sh set shellopts '-eu' set ifs "\n" set drawbox set scrolloff 10 set incsearch set ignoredia set period 2 set ratios 1:2:2You can type
:doc
in lf
to find a description of what
those do as I will only go over the most interesting ones:
drawbox
draws nice lines that make lf
nicer to
look atscrolloff
starts scrolling the pane 10 lines before reaching
the top or bottomincsearch
starts jumping to the first matching file while the
user types, before hitting Enterignoredia
ignores diacritics such as accents while searching.
Therefore, /épo
will match the file dépotoire
fzf
I integrate fzf
with the following snippet:
map f ${{ selected="$(fzf)" [ -d "$selected" ] && cmd=cd || cmd=select lf -remote "send $id $cmd '$selected'" }}This allows me to just hit the
f
key, start typing and end up
exactly where I want to be when I hit Enter. It either selects the result if it
is a normal file or enters it if it is a directory.
I use the following commands to deal with compressed files:
map x extract cmd extract ${{ set -f case $f in *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;; *.tar.gz|*.tgz) tar xzvf $f;; *.tar.xz|*.txz) tar xJvf $f;; *.zip) unzip $f;; *.rar) unrar x $f;; *.7z) 7z x $f;; esac }} cmd tar ${{ set -f mkdir $1 cp -r $fx $1 tar czf $1.tar.gz $1 rm -rf $1 }} cmd zip ${{ set -f mkdir $1 cp -r $fx $1 zip -r $1.zip $1 rm -rf $1 }}This enables me to just hit
x
on any compressed file to decompress,
without having to think about command line options. I can also use :zip
myarchive
or :tar myarchive
to package the selected files
into a compressed archive (respectively myarchive.zip
or
myarchive.tar.gz
).
Drag and drop is often a pain point when working from a terminal. I have already
explain how I tackle it in another article. Together
with the fzf
integration and the archiving bindings, this makes
uploading files to website a breeze.
I use a few other minor bindings to make my life a little easier:
map D delete
to delete files.map u $urxvtcd
to spawn a new terminal in the current
directory (change urxvtcd
for your terminal of choice).map * push :glob-select
to prompt for a glob search.
This way, I can type **wav
to select all WAV files or
*hello*
to select all files that start with "hello".