| 1 |
# interpreter for shell commands |
| 2 |
set 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. |
| 11 |
set 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. |
| 18 |
set ifs "\n" |
| 19 |
|
| 20 |
# leave some space at the top and the bottom of the screen |
| 21 |
set scrolloff 10 |
| 22 |
|
| 23 |
# Use the `dim` attribute instead of underline for the cursor in the preview pane |
| 24 |
set cursorpreviewfmt "\033[7;2m" |
| 25 |
|
| 26 |
# use enter for shell commands |
| 27 |
map <enter> shell |
| 28 |
|
| 29 |
# show the result of execution of previous commands |
| 30 |
map ` !true |
| 31 |
|
| 32 |
# execute current file (must be executable) |
| 33 |
map x $$f |
| 34 |
map X !$f |
| 35 |
|
| 36 |
# dedicated keys for file opener actions |
| 37 |
map o &mimeopen "$f" |
| 38 |
map O $mimeopen --ask "$f" |
| 39 |
|
| 40 |
# define a custom 'open' command |
| 41 |
# This command is called when current file is not a directory. You may want to |
| 42 |
# use either file extensions and/or mime types here. Below uses an editor for |
| 43 |
# text files and a file opener for the rest. |
| 44 |
cmd open &{{ |
| 45 |
set -f |
| 46 |
case $(file --mime-type -Lb "$f") in |
| 47 |
text/*) lf -remote "send $id \$$EDITOR \$fx";; |
| 48 |
*) for f in $fx; do $OPENER "$f" > /dev/null 2> /dev/null & done;; |
| 49 |
esac |
| 50 |
}} |
| 51 |
|
| 52 |
# mkdir command. See wiki if you want it to select created dir |
| 53 |
map a :push %mkdir<space> |
| 54 |
|
| 55 |
# define a custom 'rename' command without prompt for overwrite |
| 56 |
# cmd rename %[ -e "$1" ] && printf "file exists" || mv "$f" "$1" |
| 57 |
# map r push :rename<space> |
| 58 |
|
| 59 |
# make sure trash folder exists |
| 60 |
# %mkdir -p ~/.trash |
| 61 |
|
| 62 |
# move current file or selected files to trash folder |
| 63 |
# (also see 'man mv' for backup/overwrite options) |
| 64 |
cmd trash %set -f; mv -t ~/.trash -- $fx |
| 65 |
|
| 66 |
# define a custom 'delete' command |
| 67 |
# cmd delete ${{ |
| 68 |
# set -f |
| 69 |
# printf "$fx\n" |
| 70 |
# printf "delete? [y/N] " |
| 71 |
# read ans |
| 72 |
# [ "$ans" = "y" ] && rm -rf $fx |
| 73 |
# }} |
| 74 |
|
| 75 |
# use '<delete>' key for either 'trash' or 'delete' command |
| 76 |
# map <delete> trash |
| 77 |
# map <delete> delete |
| 78 |
|
| 79 |
# extract the current file with the right command |
| 80 |
# (xkcd link: https://xkcd.com/1168/) |
| 81 |
cmd extract ${{ |
| 82 |
set -f |
| 83 |
case "$f" in |
| 84 |
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf "$f";; |
| 85 |
*.tar.gz|*.tgz) tar xzvf "$f";; |
| 86 |
*.tar.xz|*.txz) tar xJvf "$f";; |
| 87 |
*.zip) unzip "$f";; |
| 88 |
*.rar) unrar x "$f";; |
| 89 |
*.7z) 7z x "$f";; |
| 90 |
esac |
| 91 |
}} |
| 92 |
|
| 93 |
# compress current file or selected files with tar and gunzip |
| 94 |
cmd tar ${{ |
| 95 |
set -f |
| 96 |
mkdir "$1" |
| 97 |
cp -r $fx "$1" |
| 98 |
tar czf "$1.tar.gz" "$1" |
| 99 |
rm -rf "$1" |
| 100 |
}} |
| 101 |
|
| 102 |
# compress current file or selected files with zip |
| 103 |
cmd zip ${{ |
| 104 |
set -f |
| 105 |
mkdir "$1" |
| 106 |
cp -r $fx "$1" |
| 107 |
zip -r "$1.zip" "$1" |
| 108 |
rm -rf "$1" |
| 109 |
}} |