summaryrefslogtreecommitdiff
path: root/.config/lf/lfrc
blob: b8bf8004f2ed6176cb25b3f027969becbb1ed811 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# interpreter for shell commands
set shell sh

# 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 5

# Basic Settings
set hidden true
#set drawbox true
set icons true
set ignorecase true
set smartcase true
set mouse
set previewer preview
set preview

cmd open $$OPENER $f

cmd on-cd &{{
	sed -i "\|^$PWD$|d" ${XDG_DATA_HOME:-$HOME/.local/share}/cdhist
	echo "$PWD" >> ${XDG_DATA_HOME:-$HOME/.local/share}/cdhist
}}

cmd delete ${{
	clear; tput cup $(($(tput lines)/3)); tput bold
	set -f
	printf "%s\n\t" "$fx"
	printf "delete?[y/N] "
	read ans
	[ $ans = "y" ] && rm -rf -- $fx
}}

cmd extract ${{
	# extract the current file with the right command
	# (xkcd link: https://xkcd.com/1168/)
	set -f
	for f in $fx; do case "$f" in
				*.tar) tar xvf "$f" ;;
				*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf "$f" ;;
				*.tar.gz|*.tgz) tar xzvf "$f" ;;
				*.tar.xz|*.txz) tar xJvf "$f" ;;
				*.gz) gunzip "$f" ;;
				*.zip) unzip "$f" ;;
				*.rar) unrar x "$f" ;;
				*.7z) 7z x "$f" ;;
				*.zst) unzstd "$f" ;;
				*) echo "Unsupported format" >&2; exit 1 ;;
		esac done
}}

cmd link_index %{{
	case "$f" in
		*.html) index="index.html" ;;
		*) echo "Unsupported file"; exit 1 ;;
	esac
	[ -e "$index" ] && [ ! -L "$index" ] && {
		echo "Failed: $index already exists and is not a symbolic link"
		exit
	}
	ln -sf "$f" "$index"
}}

cmd select_eval ${{
	res="$(eval "$@")"
	[ -d "$res" ] &&
		lf -remote "send $id cd \"$res\"" ||
		lf -remote "send $id select \"$res\""
}}

cmd link %{{
    set -- $(cat ~/.local/share/lf/files)
    mode="$1"
    shift
    [ "$#" -lt 1 ] &&
	{ lf -remote "send $id echo no files to link"; exit 0; }
    case "$mode" in
        copy) ln -sr -t . -- "$@";;
        move) ln -t . -- "$@";;
    esac
    rm ~/.local/share/lf/files
    lf -remote "send clear"
}}

# Basic Functions
cmap <tab> cmd-menu-complete
cmap <backtab> cmd-menu-complete-back
map <enter> shell
map <delete> trash
map <c-space> set preview!
map <c-n> push $mkdir<space>""<c-b>
map <a-s> :source ~/.config/lf/lfrc
map <tab> :toggle; down
map <backtab> :toggle; up
map Z :toggle; up
map <c-j> select_eval "fzf --reverse --query '!/$ ' --header-first --header='Jump to location'"
map <backspace> ${{ lf -remote "send $id select \"$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/openhist |
	fzf --tac --reverse --header-first --header='File History')\"" }}
map <c-k> ${{ lf -remote "send $id cd \"$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/cdhist |
	fzf --tac --reverse --header-first --header='Path History')\"" }}
map <c-c> ${{ lf -remote "send $id cd \"$(find -mindepth 1 -type d |
	fzf --reverse --header-first --header='Jump to directory')\"" }}

map c
map d
map I :rename; cmd-home
map i :rename
map a :rename; cmd-right
map A :rename; cmd-end
map S push A<c-u>
map o $LESSOPEN="|preview %s" less $f
map O $mimeopen --ask $f
map . set hidden!
map x cut
map M $lf -remote "send $id select \"$(fmd)\""
map D delete
map W $setsid -f $TERMINAL >/dev/null 2>&1
map X !$f
map T !dev test $f
map b $vidir
map V push :!nvim<space>""<c-b>
map P :link

map ge extract $f
map gl clear
map gx ${{ chmod u+x $fx; lf -remote "send $id reload"; }}
map gX ${{ chmod -x $fx; lf -remote "send $id reload"; }}
map gm push $chmod<space>--<space>$fx<c-a><a-f><space>
map gL %lf -remote "send ${id} select '$(readlink $f)'"
map gd !du -hd1
map gf !file $f
map gy %{{ printf "%s" "$f" | xsel -b }}
map gY %{{ printf "%s" "$fs" | xsel -b }}
map gi link_index
map gsh $setbg $f
map gsl $setbg -l $f
map zpp set previewer preview
map zpc set previewer cat
map zpb set previewer preview-bat
map zph set previewer preview-highlight

# Trash Mappings
map dd  ${{ echo "$fx" | xargs -I{} trash-put "{}" }}
map dtc $trash-empty
map dtr $trash-restore
# Dragon Mapping
map dr %dragon-drop -a -x $fx
map ds %dragon-drop -a $fx
map di %dragon-drop $fx
map dm %cpdragon
map dc %mvdragon
map dl %dlfile

source ~/.config/lf/shortcutrc