Files
dotfiles/.config/lf/lfrc

178 lines
4.2 KiB
Plaintext

## Basic Settings
### interpreter for shell commands (needs to be POSIX compatible)
set shell sh
### view hidden files
set hidden
set info size:time
set previewer lf-preview.sh
#set previewer /usr/bin/pistol
### Enable icons. Requires nerd fonts and LF_ICONS variable.
set icons
set ignorecase true
### set '-eu' options for shell commands
### These options are used to have safer shell commands. Option '-e' is used to
### exit on error and option '-u' is used to give error for unset variables.
### Option '-f' disables pathname expansion which can be useful when $f, $fs, and
### $fx variables contain names with '*' or '?' characters. However, this option
### is used selectively within individual commands as it can be limiting at
### times.
set shellopts '-eu'
### set internal field separator (IFS) to "\n" for shell commands
### This is useful to automatically split file names in $fs and $fx properly
### since default file separator used in these variables (i.e. 'filesep' option)
### is newline. You need to consider the values of these options and create your
### commands accordingly.
set ifs "\n"
### leave some space at the top and the bottom of the screen
set scrolloff 10
## Custom Functions
### define a custom 'open' command
cmd open ${{
case $(file --mime-type $f -b) in
application/x-gtar|application/gzip|application/x-bzip2|application/x-rar|application/zip|application/x-iso9660-image|application/x-xz)
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"
;;
text/*|*/json) $EDITOR "$f";;
*) for f in $fx; do $OPENER "$f" > /dev/null 2> /dev/null & done;;
esac
}}
### define a custom 'rename' command without prompt for overwrite
# cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
# map r push :rename<space>
cmd trash ${{
for file in $fs; do
trash-put "$file"
done
}}
cmd trash_clear %trash_empty
cmd trash_restore ${{
trash-restore
}}
cmd mkdir %mkdir -p "$(echo $* | tr ' ' '\ ')"
map a push :mkdir<space>
cmd mkfile ${{
$EDITOR $1
}}
cmd sudomkfile ${{
sudo $EDITOR $1
}}
cmd setwallpaper ${{
swaymsg output "*" background "$f" stretch
}}
cmd chmod ${{
for file in "$fx"; do chmod $1 $file; done
lf -remote 'send reload'
}}
### extract the current file with the right command
### (xkcd link: https://xkcd.com/1168/)
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;;
*) echo "Unsupported format";;
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
}}
cmd paste &{{
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
rsync -av --progress $list . \
| stdbuf -i0 -o0 -e0 tr '\r' '\n' \
| while read line; do
lf -remote "send $id echo $line"
done
elif [ $mode = 'move' ]; then
mv -n $list .
fi
lf -remote 'send load'
lf -remote 'send clear'
}}
cmd drag &{{
dragon-drag-and-drop -a -x $fx
}}
cmd broot_jump ${{
f=$(mktemp)
res="$(broot --outcmd $f && cat $f | sed 's/cd //')"
rm -f "$f"
if [ -f "$res" ]; then
cmd="select"
elif [ -d "$res" ]; then
cmd="cd"
fi
lf -remote "send $id $cmd \"$res\""
}}
#cmd bulkrename $vdir
#cmd bulkrename $qmv -f do -a
cmd bulkrename $edir -a
## Bindings
# map <delete> trash
map <delete> delete
map f broot_jump
### use enter for shell commands
map <enter> shell
### execute current file (must be executable)
#map x $$f
#map X !$f
### dedicated keys for file opener actions
#map o &mimeopen $f
#map O $mimeopen --ask $f
map R bulkrename