lf/etc/lfrc.example

99 lines
2.7 KiB
Plaintext
Raw Normal View History

# interpreter for shell commands (needs to be POSIX compatible)
set shell sh
2018-06-26 19:24:41 +00:00
# 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.
2018-06-26 19:24:41 +00:00
# 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
2017-09-08 20:46:31 +00:00
# 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"
2016-08-27 14:17:20 +00:00
2016-08-13 12:49:04 +00:00
# leave some space at the top and the bottom of the screen
set scrolloff 10
# use enter for shell commands
map <enter> shell
2016-08-13 12:49:04 +00:00
# execute current file (must be executable)
map x $$f
map X !$f
2016-08-13 12:49:04 +00:00
# dedicated keys for file opener actions
map o &mimeopen $f
map O $mimeopen --ask $f
2016-08-13 12:49:04 +00:00
2017-09-08 20:46:31 +00:00
# show documentation (overrides 'search-back' command)
2016-09-13 21:49:02 +00:00
map ? $lf -doc | less
2018-06-28 18:20:43 +00:00
# define a custom 'open' command
# This command is called when current file is not a directory. You may want to
# use either file extensions and/or mime types here. Below uses an editor for
# text files and a file opener for the rest.
cmd open ${{
case $(file --mime-type $f -b) in
2017-09-08 20:46:31 +00:00
text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
esac
}}
2016-08-13 12:49:04 +00:00
# rename current file without overwrite
2018-04-06 19:49:50 +00:00
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
map r push :rename<space>
2016-08-13 12:49:04 +00:00
# make sure trash folder exists
2018-04-06 19:49:50 +00:00
%mkdir -p ~/.trash
2016-08-13 12:49:04 +00:00
# move current file or selected files to trash folder
# (also see 'man mv' for backup/overwrite options)
2018-06-26 19:24:41 +00:00
cmd trash %set -f; mv $fx ~/.trash
2016-08-13 12:49:04 +00:00
2017-02-11 13:28:45 +00:00
# remove current file or selected files (prompting)
2017-09-08 20:46:31 +00:00
cmd remove ${{
2018-06-26 19:24:41 +00:00
set -f
2017-09-08 20:46:31 +00:00
printf "$fx\n"
printf "remove?[y/n]"
read ans
[ $ans = "y" ] && rm -rf $fx
}}
2017-02-11 13:28:45 +00:00
2016-08-13 12:49:04 +00:00
# extract the current file with the right command
2016-09-06 22:47:08 +00:00
# (xkcd link: https://xkcd.com/1168/)
2018-06-26 19:24:41 +00:00
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;;
2016-08-13 12:49:04 +00:00
esac
}}
2018-04-06 19:49:50 +00:00
# compress current file or selected files with tar and gunzip
2018-06-26 19:24:41 +00:00
cmd tar ${{
set -f
mkdir $1
2018-04-06 19:49:50 +00:00
cp -r $fx $1
tar czf $1.tar.gz $1
rm -rf $1
2016-08-13 12:49:04 +00:00
}}
2018-06-26 19:24:41 +00:00
# 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
}}