Skip to content

Integrations

gokcehan edited this page Jul 15, 2019 · 8 revisions

Below are some shell tools that can be integrated into lf using regular or remote commands. Feel free to add more tools to this list as you like.

trash-cli

trash-cli can be used as command line interface for FreeDesktop.org Trash specification. trash-cli already provides separate commands for trash operations (i.e. trash-put, trash-empty, trash-list, trash-restore, trash-rm) so you can simply map these commands to a key:

cmd trash %trash-put $fx

Note that trash-cli uses the same trashcan used by KDE, GNOME, and XFCE.

autojump

autojump can be used to jump to a directory in lf that contains a given string:

cmd aj %lf -remote "send $id cd '$(autojump $1)'"
map a push :aj<space>

Note that autojump relies on shell prompts to build and update its database, so it will only be updated when you run commands outside of lf or exit from lfcd function.

fzf

You can bind keys in lf to your usual fzf commands:

map f $vi $(fzf)

It is also possible to define commands with arguments to use with fzf:

cmd fzf $vi $(find . -name "$1" | fzf)
map f push :fzf<space>

If you want to jump to a file or directory in lf using fuzzy matching, you can utilize fzf for this purpose:

map f $lf -remote "send $id select '$(fzf)'"

vim / neovim

Vim script in etc/lf.vim only works in terminal vim and provides only a basic :LF command. There is a separate vim plugin Lf.vim that provides more features and can be used in gvim and neovim as well.

archivemount

archivemount can be used to browse archives like directories. To integrate it with lf, the "open" command can be changed as follows:

cmd open ${{
    case "$f" in
        *.tar.bz|*.tar.bz2|*.tbz|*.tbz2|*.tar.gz|*.tgz|*.tar.xz|*.txz|*.zip|*.rar|*.iso)
            mntdir="$f-archivemount"
            [ ! -d "$mntdir" ] && {
                mkdir "$mntdir"
                archivemount "$f" "$mntdir"
                echo "$mntdir" >> "/tmp/__lf_archivemount_$id"
            }
            lf -remote "send $id cd \"$mntdir\""
            lf -remote "send $id reload"
            ;;
        *)
            for f in $fx; do
                $OPENER $f > /dev/null 2> /dev/null &
            done;;
    esac
}}

To unmount archives after exiting, a wrapper over lf can be done like this (integrating with lfcd):

lfcd () {
    tmp="$(mktemp)"
    fid="$(mktemp)"
    lf -command '$printf $id > '"$fid"'' -last-dir-path="$tmp" "$@"
    id="$(cat "$fid")"
    archivemount_dir="/tmp/__lf_archivemount_$id"
    if [ -f "$archivemount_dir" ]; then
        cat "$archivemount_dir" | \
            while read -r line; do
                sudo umount "$line"
                rmdir "$line"
            done
        rm -f "$archivemount_dir"
    fi
    if [ -f "$tmp" ]; then
        dir="$(cat "$tmp")"
        rm -f "$tmp"
        if [ -d "$dir" ]; then
            if [ "$dir" != "$(pwd)" ]; then
                cd "$dir"
            fi
        fi
    fi
}
Clone this wiki locally
You can’t perform that action at this time.