lfrc (3785B)
1 # interpreter for shell commands (needs to be POSIX compatible)
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 # enable ANSI 256 color escape code support
24 set color256 on
25
26 # panel ratios
27 cmd recol &{{
28 w=$(tput cols)
29 if [ $w -le 80 ]; then
30 lf -remote "send $id set ratios 1:2"
31 elif [ $w -le 160 ]; then
32 lf -remote "send $id set ratios 1:2:3"
33 else
34 lf -remote "send $id set ratios 1:2:3:5"
35 fi
36 }}
37 map <c-g> recol
38 recol
39
40 # use enter for shell commands
41 map <enter> shell
42
43 # execute current file (must be executable)
44 map x $$f
45 map X !$f
46
47 # dedicated keys for file opener actions
48 map o &mimeopen $f
49 map O $mimeopen --ask $f
50
51 # Emacs style copy-paste
52 map <c-w> cut
53 map <a-w> copy
54 map <c-y> paste
55
56 # Fuzzy search for current directory and below.
57 # Only search non-hidden directories.
58 map <c-s> $lf -remote "send $id select '$(fd --no-ignore-vcs -t d | fzf)'"
59 # Include hidden ones.
60 map <a-s> $lf -remote "send $id select '$(fd --no-ignore-vcs -H -t d | fzf)'"
61
62 # define a custom 'open' command
63 # This command is called when current file is not a directory. You may want to
64 # use either file extensions and/or mime types here. Below uses an editor for
65 # text files and a file opener for the rest.
66 cmd open ${{
67 case $(xdg-mime query filetype $f) in
68 application/epub*|application/pdf|application/postscript|application/vnd.comicbook*|image/vnd.djvu*) nohup zathura $fx > /dev/null 2> /dev/null &;;
69 image/*) nohup imv $fx $(fd --no-ignore-vcs -t f -d 1 . ./) > /dev/null 2> /dev/null &;;
70 text/*) nohup emacsclient -c -a emacs $fx > /dev/null 2> /dev/null &;;
71 *) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
72 esac
73 }}
74
75 # rename current file without overwrite
76 cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
77 map r push :rename<space>
78
79 # make sure trash folder exists
80 %mkdir -p ~/.trash
81
82 # move current file or selected files to trash folder
83 # (also see 'man mv' for backup/overwrite options)
84 cmd trash %set -f; mv $fx ~/.trash
85
86 # delete current file or selected files (prompting)
87 cmd delete ${{
88 set -f
89 printf "$fx\n"
90 printf "delete?[y/n]"
91 read ans
92 [ $ans = "y" ] && rm -rf $fx
93 }}
94
95 # extract the current file with the right command
96 # (xkcd link: https://xkcd.com/1168/)
97 cmd extract ${{
98 set -f
99 case $f in
100 *.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
101 *.tar.gz|*.tgz) tar xzvf $f;;
102 *.tar.xz|*.txz) tar xJvf $f;;
103 *.zip) unzip $f;;
104 *.rar) unrar x $f;;
105 *.7z) 7z x $f;;
106 esac
107 }}
108
109 # compress current file or selected files with tar and gunzip
110 cmd tar ${{
111 set -f
112 mkdir $1
113 cp -r $fx $1
114 tar czf $1.tar.gz $1
115 rm -rf $1
116 }}
117
118 # compress current file or selected files with zip
119 cmd zip ${{
120 set -f
121 mkdir $1
122 cp -r $fx $1
123 zip -r $1.zip $1
124 rm -rf $1
125 }}
126
127 # preview command
128 set previewer ~/.local/bin/lf/previewer
129 map i $~/.local/bin/lf/previewer $f | less -R