1# interpreter for shell commands 2set shell sh 3 4# set '-eu' options for shell commands 5# These options are used to have safer shell commands. Option '-e' is used to 6# exit on error and option '-u' is used to give error for unset variables. 7# Option '-f' disables pathname expansion which can be useful when $f, $fs, and 8# $fx variables contain names with '*' or '?' characters. However, this option 9# is used selectively within individual commands as it can be limiting at 10# times. 11set shellopts '-eu' 12 13# set internal field separator (IFS) to "\n" for shell commands 14# This is useful to automatically split file names in $fs and $fx properly 15# since default file separator used in these variables (i.e. 'filesep' option) 16# is newline. You need to consider the values of these options and create your 17# commands accordingly. 18set ifs "\n" 19 20# leave some space at the top and the bottom of the screen 21set scrolloff 10 22 23# == previewer == 24set previewer ~/.config/lf/previewer.sh 25 26# use enter for shell commands 27map <enter> shell 28 29# execute current file (must be executable) 30map x $$f 31map X !$f 32 33# dedicated keys for file opener actions 34map o &mimeopen $f 35map O $mimeopen --ask $f 36 37# define a custom 'open' command 38# This command is called when current file is not a directory. You may want to 39# use either file extensions and/or mime types here. Below uses an editor for 40# text files and a file opener for the rest. 41cmd open ${{ 42 test -L $f && f=$(readlink -f $f) 43 case $(file --mime-type $f -b) in 44 text/*) $EDITOR $fx;; 45 *) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;; 46 esac 47}} 48 49# define a custom 'rename' command without prompt for overwrite 50# cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1 51# map r push :rename<space> 52 53# make sure trash folder exists 54# %mkdir -p ~/.trash 55 56# move current file or selected files to trash folder 57# (also see 'man mv' for backup/overwrite options) 58cmd trash %set -f; mv $fx ~/.trash 59 60# define a custom 'delete' command 61# cmd delete ${{ 62# set -f 63# printf "$fx\n" 64# printf "delete?[y/n]" 65# read ans 66# [ "$ans" = "y" ] && rm -rf $fx 67# }} 68 69# use '<delete>' key for either 'trash' or 'delete' command 70# map <delete> trash 71# map <delete> delete 72 73# extract the current file with the right command 74# (xkcd link: https://xkcd.com/1168/) 75cmd extract ${{ 76 set -f 77 case $f in 78 *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;; 79 *.tar.gz|*.tgz) tar xzvf $f;; 80 *.tar.xz|*.txz) tar xJvf $f;; 81 *.zip) unzip $f;; 82 *.rar) unrar x $f;; 83 *.7z) 7z x $f;; 84 esac 85}} 86 87# compress current file or selected files with tar and gunzip 88cmd tar ${{ 89 set -f 90 mkdir $1 91 cp -r $fx $1 92 tar czf $1.tar.gz $1 93 rm -rf $1 94}} 95 96# compress current file or selected files with zip 97cmd zip ${{ 98 set -f 99 mkdir $1 100 cp -r $fx $1 101 zip -r $1.zip $1 102 rm -rf $1 103}}