set shell sh
set shellopts '-eu'
set ifs "\n"
set cursorpreviewfmt "\033[7;2m"
map ` !true


cmd open &{{
    case $(file --mime-type -Lb $f) in
        text/*) lf -remote "send $id \$nvim \$fx";;
        *) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
    esac
}}

# define a custom 'delete' command
cmd delete ${{
    set -f
    printf "$fx\n"
    printf "delete?[y/n]"
    read ans
    [ "$ans" = "y" ] && rm -rf $fx
}}

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
}}

# compress current file or selected files with tar and gunzip
cmd tar ${{
    set -f
    mkdir $1
    cp -r $fx $1
    tar czf $1.tar.gz $1
    rm -rf $1
}}

# compress current file or selected files with zip
cmd zip ${{
    set -f
    mkdir $1
    cp -r $fx $1
    zip -r $1.zip $1
    rm -rf $1
}}

# My Config

set icons true
set ignorecase true
set previewer ~/.config/lf/lf_kitty_preview
set cleaner ~/.config/lf/lf_kitty_clean

map d
map space

map i up
map k down
map j updir
map l open

map x cut
map dd delete
map v select


# Integrations
cmd on-cd &{{
    export STARSHIP_SHELL=
    fmt="$(starship prompt)"
    lf -remote "send $id set promptfmt \"$fmt\""
}}


