blob: 4d9c306bef79584c7393e43c21b0ae2003717dcc (
plain) (
blame)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# Basic Settings
set shell sh
set shellopts '-eu'
set ifs "\n"
set errorfmt "\033[1;31m%s\033[0m"
set promptfmt "\033[34;1m%d\033[0m\033[1m%f\033[0m"
set scrolloff 5
set wrapscroll
set sortby time
set info size:time
set reverse
set incsearch
set period 1
set hidden
set preview
#set previewer lfview
set ratios 2:4
%[ $LF_LEVEL -eq 1 ] || echo "Warning: You're in a nested lf instance!"
# Custom Functions
cmd open ${{
case $(file --mime-type "$(readlink -f $f)" -b) in
text/*|application/json) vix "$f";;
image/svg+xml) display -- $f ;;
image/*) nsxiv-rifle $f 2>/dev/null & ;;
audio/*) mpv $f ;;
video/*) mpv $f -quiet >/dev/null 2>&1 & ;;
*) xdg-open "$f" &>/dev/null &;;
esac
}}
cmd bulkrename ${{
old=$(mktemp)
new=$(mktemp)
[ -n $fs ] && fs=$(ls)
printf "$fs\n" > $old
printf "$fs\n" > $new
$EDITOR $new
[ $(cat $new | wc -l) -ne $(cat $old | wc -l) ] && exit
paste $old $new | while read names; do
src=$(printf $names | cut -f1)
dst=$(printf $names | cut -f2)
[ $src = $dst ] && continue
[ -e $dst ] && continue
mv $src $dst
done
rm $old $new
lf -remote "send $id unselect"
}}
# insert
cmd rename-insert &{{
if [ "$(echo "$fx" | wc -l)" -gt 1 ]; then
lf -remote "send $id echo You can't change more than one file name"
lf -remote "send $id unselect"
else
len="$(basename "$f" | wc -m)" # length of selected file/directory
for i in $(seq "$len"); do
pos="${pos}<left>" # how many times do I have to press <left> in order to get first char
done
lf -remote "send $id rename"
lf -remote "send $id push $pos"
fi
}}
# append before ext
cmd rename-before-ext &{{
if [ "$(echo "$fx" | wc -l)" -gt 1 ]; then
lf -remote "send $id echo You can't change more than one file name"
lf -remote "send $id unselect"
else
if [ -d "$f" ]; then
lf -remote "send $id rename"
else
ext_len="$(echo ${f##*.} | wc -m)" # extention length
for i in $(seq "$ext_len"); do
pos="${pos}<left>"
done
lf -remote "send $id rename"
lf -remote "send $id push "$pos""
fi
fi
}}
# change its name entirely
cmd rename-new &{{
if [ "$(echo "$fx" | wc -l)" -gt 1 ]; then
lf -remote "send $id echo You can't change more than one file name"
lf -remote "send $id unselect"
else
lf -remote "send $id rename"
lf -remote "send $id push <c-u>"
fi
}}
cmd paste-rsync &{{
set -- $(cat ~/.local/share/lf/files)
mode="$1"
shift
case "$mode" in
copy)
rsync -av --ignore-existing --progress -- "$@" . |
stdbuf -i0 -o0 -e0 tr '\r' '\n' |
while IFS= read -r line; do
lf -remote "send $id echo $line"
done
;;
move) mv -n -- "$@" .;;
esac
rm ~/.local/share/lf/files
lf -remote "send clear"
}}
cmd paste-overwrite %{{
mode=$(head -1 ~/.local/share/lf/files)
list=$(sed 1d ~/.local/share/lf/files)
if [ $mode = 'copy' ]; then
cp -R $list .
elif [ $mode = 'move' ]; then
mv $list .
fi
lf -remote 'send clear'
}}
cmd fzf_jump ${{
res="$(find . -maxdepth 2 | sed "s|^\./||" | fzf --reverse --header='Jump to location' | sed 's/\\/\\\\/g;s/"/\\"/g')"
if [ -d "$res" ]; then
cmd="cd"
else
cmd="select"
fi
lf -remote "send $id $cmd \"$res\""
}}
cmd Link %{{
lf -remote 'load' | while read file; do
if [ ! -n "${mode+1}" ]; then
mode="$file"
continue
fi
files+=("$file")
done
if [ "${#files[@]}" -le 1 ]; then
lf -remote "send $id echo no files to link"
exit 0
fi
# symbolicly copy mode is indicating a soft link
if [[ "$mode" == copy ]]; then
ln -sr $files -t .
# while a move mode is indicating a hard link
elif [[ "$mode" == move ]]; then
ln $files -t .
fi
}}
cmd git_branch ${{
git branch | iomenu | xargs git checkout
pwd_shell=$(pwd)
lf -remote "send $id updir"
lf -remote "send $id cd \"$pwd_shell\""
}}
# toggle single column view
cmd no_preview :{{
set nopreview
set ratios 1
set info size:time
map ~ yes_preview
}}
cmd yes_preview :{{
set ratios 2:2
set preview
set info size:time
map ~ no_preview
}}
cmd yank-dirname $dirname -- "$f" | head -c-1 | xclip -i -selection clipboard
cmd yank-path $printf '%s' "$fx" | xclip -i -selection clipboard
cmd yank-basename $basename -a -- $fx | head -c-1 | xclip -i -selection clipboard
cmd yank-basename-without-extension ${{
echo "$fx" |
xargs -r -d '\n' basename -a |
awk -e '{
for (i=length($0); i > 0; i--) {
if (substr($0, i, 1) == ".") {
if (i == 1) print $0
else print substr($0, 0, i-1)
break
}
}
if (i == 0)
print $0
}' |
if [ -n "$fs" ]; then cat; else tr -d '\n'; fi |
xclip -i -selection clipboard
}}
# Bindings
# Remove some defaults
map "'"
map '"'
map m
map n
map d
map p
map w
map y
map c
map /
map r
map G
cmap <esc> cmd-escape
map <f-2> push A<c-u> # new rename
map <f-3> cut
map <f-4> copy
map <f-5> reload
map <f-6> push $touch<space>
map <f-7> push :mkdir<space>
map <f-8> delete
map <f-9> paste
map <enter> open
map <backspace2> delete
map . set hidden!
map ~ no_preview
map | top
map ¿ bottom
map x clear
map dd cut
map yy copy
map yn yank-dirname
map yp yank-path
map yn yank-basename
map yw yank-basename-without-extension
map pp paste
map po paste-overwrite
map pr paste-rsync
map o &mimeopen $f
map O $mimeopen --ask $f
map cx $chmod +x "$f"
map bg $setbg $f
map du %du -sh $f
map Y %cp -ri $fs .
map D %mv -i $fs .
map zf $file-roller "$f"
map zx $zx "$f"
map I push A<c-a> # at the very beginning
map A rename # at the very end
map i push A<a-b><c-b> # at the very beginning
map a push A<a-b> # after extention
map B bulkrename
map L :Link
map f fzf_jump
map Gb :git_branch
map Gp ${{clear; git pull --rebase || true; echo "press ENTER"; read ENTER}}
map Gs ${{clear; git status; echo "press ENTER"; read ENTER}}
map Gl ${{clear; git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit}}
map da $git add $fx
# Movement
map gR cd /
map gE cd /etc
map gl cd ~/.local/share
map gb cd ~/bin
map g. cd ~/.config
map gn cd ~/.config/nvim
map gk cd ~/.config/ksh
map gd cd ~/doc
map ga cd ~/src
map ge cd ~/etc
map gi cd ~/img
map gu cd ~/usb
|