Skip to content
Gokcehan edited this page Apr 3, 2022 · 11 revisions

This page lists some ranger goodies to be used with lf.

Scope

Ranger has a scope.sh file to preview files. You can also use this file in lf to some extent. First, create a wrapper script ~/.config/lf/scope-lf-wrapper.sh as follows:

#!/bin/sh
"$HOME/.config/ranger/scope.sh" "${1}" "${2}" "${3}" "" "" || true

Then set previewer option and pager mapping in lfrc to use this script as follows:

set previewer ~/.config/lf/scope-lf-wrapper.sh
map i $LESSOPEN='| ~/.config/lf/scope-lf-wrapper.sh %s' less -R $f

Note, ranger uses return codes for different semantics so we append || true to enable caching in lf. Also, arguments ${4} and ${5} are used for image previews in ranger which does not work directly in lf so they are left empty. See also Previews wiki page for image previews in lf.

Rifle

Ranger has a rifle.py file executor/opener. You can use it as the file opener in lf as follows:

cmd open $set -f; rifle -p 0 $fx

You can also list all possible ways to open a file with a command/mapping as follows:

cmd open-with ${{
    set -f
    rifle -l $fx
    read -p "Open with: " method
    rifle -p $method $fx
}}
map r open-with

Note that these examples assume you are using a posix compatible shell (e.g. set shell sh) and you have the appropriate settings to handle filenames without quoting in your configuration file (e.g. set ifs "\n"). Also note that the example mapping overwrites the default r binding for rename command in lf.

Clone this wiki locally