-
Notifications
You must be signed in to change notification settings - Fork 1
/
lfrc
419 lines (384 loc) · 12.4 KB
/
lfrc
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# lf file manager config
## docs: lf -doc L
## example: https://raw.githubusercontent.com/BrodieRobertson/dotfiles/master/config/lf/lfrc
# from https://github.com/thimc/lfimg
set previewer ~/.config/lf/preview
set cleaner ~/.config/lf/cleaner
# set previewer ~/scripts/lf-preview
set nodirfirst
set relativenumber
set ratios 5:4
# ignore
set hiddenfiles ".*:*.aux:*.log:*.synctex.gz:*.bcf:*.run.xml:*.bbl:*.blg:*.toc:*.nav:*.out:*.snm:package-lock.json:node_modules"
set cursorpreviewfmt "\033[48;5;240m"
set statfmt "\033[36m%p\033[0m| (%s)| %t| -> %l" # size in GB (not GiB)
# for working with $fs/$fx
set shell zsh
set shellopts '-euy'
set ifs "\n"
set filesep "\n"
# Different commands:
# $ -> shell
# % -> shell-pipe: input from the ui and output to the ui
# ! -> shell-wait: wait for input after running
# & -> shell-async: run in the background
cmd source-config %lf -remote "send $id source ~/.config/lf/lfrc"
cmd open $~/scripts/mime/mime -e lf open "$f"
cmd edit $~/scripts/mime/mime -e lf edit "$f"
cmd remove $rm -rf $fx
cmd diropen $~/.config/lf/scripts/handle-dir "$f"
cmd diropenShuffle $~/.config/lf/scripts/handle-dir "$f" -s
cmd massmove $~/.config/lf/scripts/rename "$fx"
cmd combine $~/.config/lf/scripts/combine $fx
cmd paste_and_forget &lf -remote "send $id :paste; clear; refresh"
cmd clear-unselect &lf -remote "send $id :clear; unselect"
cmd move-to-inbox %{{
local filename="${f##*/}"
if [ -e "$ORG_INBOX/$filename" ]; then
mv "$f" "$ORG_INBOX/$(date +%s)-$filename"
else
mv "$f" $ORG_INBOX/
fi
printf "Moved '${f##*/}' to inbox"
}}
cmd move-to-other-inbox ${{
local filename="${f##*/}"
org=$(gum filter dava jobdirecto)
if [ -n "$org" ]; then
inbox=$ORG_INBOX
case "$org" in
dava) inbox=$DAVA_ORG/0_inbox;;
jobdirecto) inbox=$JD_ORG/0_inbox;;
esac
if [ -e "$inbox/$filename" ]; then
mv "$f" "$inbox/$(date +%s)-$filename"
else
mv "$f" $inbox/
fi
printf "Moved '${f##*/}' to inbox"
fi
}}
cmd move-to-archive %{{
local filename="${f##*/}"
if [ -e "$ORG_ARCHIVE/$filename" ]; then
mv "$f" "$ORG_ARCHIVE/$(date +%s)-$filename"
else
mv "$f" $ORG_ARCHIVE/
fi
printf "Moved '${f##*/}' to archive"
}}
cmd move-to-local-archive %{{
local filename="${f##*/}"
if echo $filename | grep -e$ORG_PROJECT_STATUS_ACTIVE -e$ORG_PROJECT_STATUS_INACTIVE -e$ORG_PROJECT_STATUS_BLOCKED >/dev/null; then
lf -remote "send $id set-status-active '$f'"
printf "Project has a status. Status was changed to active. To archive instead, remove status."
return
fi
mkdir -p .archive
if [ -e ".archive/$filename" ]; then
mv "$f" ".archive/$(date +%s)-$filename"
else
mv "$f" .archive/
fi
printf "Moved '${f##*/}' to archive"
}}
cmd move-to-paperless %{{
local filename="${f##*/}"
mv "$f" $ORG/.paperless_import/
printf "Moved '${f##*/}' to paperless"
}}
cmd move-to-blog-post-ideas %{{
local filename="${f##*/}"
mv "$f" "$ORG_AREAS/blog/posts/0 ideas/"
printf "Moved '${f##*/}' to blog post ideas"
}}
cmd move-to-designs %{{
local filename="${f##*/}"
mv "$f" "$ORG_DESIGN/0 inbox/"
printf "Moved '${f##*/}' to design inbox"
}}
cmd move-to-project ${{
local filename="${f##*/}"
project="$(select-project)"
dir="$ORG_PROJECTS/$project"
if [ -n "$project" ] && [ -d "$dir" ]; then
if [ -e "$dir/$filename" ]; then
mv "$f" "$dir/$(date +%s)-$filename"
else
mv "$f" $dir/
fi
printf "Moved '${f##*/}' to project: $project"
fi
}}
cmd move-to-area ${{
local filename="${f##*/}"
area="$(select-area)"
dir="$ORG_AREAS/$area"
if [ -n "$area" ] && [ -d "$dir" ]; then
if [ -e "$dir/$filename" ]; then
mv "$f" "$dir/$(date +%s)-$filename"
else
mv "$f" $dir/
fi
printf "Moved '${f##*/}' to area: $area"
fi
}}
cmd move-to-resource ${{
local filename="${f##*/}"
resource="$(select-resource)"
dir="$ORG_RESOURCES/$resource"
if [ -n "$resource" ] && [ -d "$dir" ]; then
if [ -e "$dir/$filename" ]; then
mv "$f" "$dir/$(date +%s)-$filename"
else
mv "$f" $dir/
fi
printf "Moved '${f##*/}' to resource: $resource"
fi
}}
cmd gimp &gimp "$f" >/dev/null 2>&1
cmd fzf_dir $~/.config/lf/scripts/fzf-open dir
cmd fzf_file $~/.config/lf/scripts/fzf-open file
## create files
cmd gen-note $~/scripts/gen-note
cmd touch %{{
printf "File Name: "
read ans
if echo $ans | grep -Fv . >/dev/null; then
title="$ans"
ans="$ans.org"
generate-orgmode-metadata "$title" >"$ans"
else
touch "$ans"
fi
lf -remote "send $id select '$ans'"
lf -remote "send $id edit"
}}
cmd touchTex %{{
printf "Tex Name: "
read ans
vtex "$ans"
}}
cmd create-index ${{
generate-orgmode-metadata >index.org
open-orgmode-file-at-title-insert index.org
}}
cmd mkdir %{{
printf "Directory name: "
read ans
mkdir -p "$ans"
lf -remote "send $id cd '$ans'" # curiously only works if no spaces in name
}}
cmd create-project ${{
printf "Project dir name: "
read ans
local project="$ORG_PROJECTS/$ORG_PROJECT_STATUS_ACTIVE $ans"
mkdir -p "$project"
lf -remote "send $id :cd '$project'; reload" &
plan "$project/index.norg"
}}
cmd create-design ${{
printf "Design dir name: "
read ans
local design="$ORG_DESIGN/$ans"
mkdir -p "$design"
lf -remote "send $id :cd '$design'; reload" &
plan "$project/index.norg"
}}
cmd create-area ${{
printf "Area dir name: "
read ans
local area="$ORG_AREAS/$ans"
mkdir -p "$area"
touch "$area/index.norg"
lf -remote "send $id :cd '$area'; reload" &
}}
cmd create-resource ${{
printf "Resource name: "
read ans
local resource="$ORG_RESOURCES/$ans"
mkdir -p "$resource"
lf -remote "send $id cd '$resource'" &
}}
cmd ldr %{{
printf "LDR title: "
read ans
if [ -n "$ans" ]; then
file="$(ldr "$ans" -print)"
lf -remote "send $id select '$file'"
lf -remote "send $id edit"
fi
}}
cmd create-plan ${{
plan "./index.norg"
}}
cmd on-cd &{{
case "$PWD" in
$ORG_DESIGN|"$ORG_AREAS/mental models"|$ORG_AREAS/geld|$ORG_AREAS/blog/posts|$ORG_AREAS/challenges|"$ORG_RESOURCES/power dynamics/"*|"$ORG_AREAS/börse/Hierarchie")
# sort: alphabetical (needs to come before the more general matches)
lf -remote "send $id :set sortby natural; set noreverse";;
$ORG_RESOURCES/LDR|$ORG_AREAS/steuern/past)
# sort: alphabetical, reverse (needs to come before the more general matches)
lf -remote "send $id :set sortby natural; set reverse";;
$ORG_RESOURCES/* | $ORG_INBOX)
# sort: most recent at the top
lf -remote "send $id :set sortby time; set reverse";;
$ORG_PROJECTS/* | $ORG_AREAS/*)
# sort: most recent at the top
lf -remote "send $id :set sortby time; set reverse"
manage-task-view-pane "$PWD" &
;;
$HOME/code/web/_/newsletter)
lf -remote "send $id :set sortby ctime; set reverse";;
*)
# sort: alphabetical
lf -remote "send $id :set sortby natural; set noreverse";;
esac
# can be paritally recreated with setlocal: https://github.com/gokcehan/lf/pull/1381
}}
on-cd # run on startup
cmd show-tasks %tmux split-window -v -l 30%; tmux select-pane -T 'task-view'; tmux send-keys "clear && t" "Enter"
# project status
cmd set-status-active %{{
local filename="${f##*/}"
local filenameWithoutEmojiPrefix="$(echo $filename | cut -c5-)"
if echo $filename | grep -v -e$ORG_PROJECT_STATUS_ACTIVE -e$ORG_PROJECT_STATUS_INACTIVE -e$ORG_PROJECT_STATUS_BLOCKED >/dev/null; then
filenameWithoutEmojiPrefix=" $filename"
fi
mv "$filename" "${ORG_PROJECT_STATUS_ACTIVE}${filenameWithoutEmojiPrefix}" 2>/dev/null
lf -remote "send $id select '${ORG_PROJECT_STATUS_ACTIVE}${filenameWithoutEmojiPrefix}'"
}}
cmd set-status-inactive %{{
local filename="${f##*/}"
local filenameWithoutEmojiPrefix="$(echo $filename | cut -c5-)"
if echo $filename | grep -v -e$ORG_PROJECT_STATUS_ACTIVE -e$ORG_PROJECT_STATUS_INACTIVE -e$ORG_PROJECT_STATUS_BLOCKED >/dev/null; then
filenameWithoutEmojiPrefix=" $filename"
fi
mv "$filename" "${ORG_PROJECT_STATUS_INACTIVE}${filenameWithoutEmojiPrefix}" 2>/dev/null
lf -remote "send $id select '${ORG_PROJECT_STATUS_INACTIVE}${filenameWithoutEmojiPrefix}'"
}}
cmd set-status-blocked %{{
local filename="${f##*/}"
local filenameWithoutEmojiPrefix="$(echo $filename | cut -c5-)"
if echo $filename | grep -v -e$ORG_PROJECT_STATUS_ACTIVE -e$ORG_PROJECT_STATUS_INACTIVE -e$ORG_PROJECT_STATUS_BLOCKED >/dev/null; then
filenameWithoutEmojiPrefix=" $filename"
fi
mv "$filename" "${ORG_PROJECT_STATUS_BLOCKED}${filenameWithoutEmojiPrefix}" 2>/dev/null
lf -remote "send $id select '${ORG_PROJECT_STATUS_BLOCKED}${filenameWithoutEmojiPrefix}'"
}}
cmd set-status-none %{{
local filename="${f##*/}"
local filenameWithoutEmojiPrefix="$(echo $filename | cut -d\ -f2-)"
if echo $filename | grep -v -e$ORG_PROJECT_STATUS_ACTIVE -e$ORG_PROJECT_STATUS_INACTIVE -e$ORG_PROJECT_STATUS_BLOCKED >/dev/null; then
filenameWithoutEmojiPrefix="$filename"
fi
mv "$filename" "$filenameWithoutEmojiPrefix" 2>/dev/null
lf -remote "send $id select '$filenameWithoutEmojiPrefix'"
}}
cmd set-status-important %{{
local filename="${f##*/}"
if echo $filename | grep -v -e$ORG_PROJECT_STATUS_ACTIVE -e$ORG_PROJECT_STATUS_INACTIVE -e$ORG_PROJECT_STATUS_BLOCKED >/dev/null; then
printf "Only use with project that already have a status"
exit 0
fi
local statusEmoji="$(echo $filename | cut -c1-4)" # the circles are 4 chars long, adjust if other emojis are introduced
local filenameWithoutEmojiPrefix="$(echo $filename | cut -d\ -f2-)"
if echo $filename | grep -e$ORG_PROJECT_STATUS_IMPORTANT >/dev/null; then
mv "$filename" "$statusEmoji $filenameWithoutEmojiPrefix"
lf -remote "send $id select '$statusEmoji $filenameWithoutEmojiPrefix'"
else
mv "$filename" "${statusEmoji}${ORG_PROJECT_STATUS_IMPORTANT} $filenameWithoutEmojiPrefix"
lf -remote "send $id select '${statusEmoji}${ORG_PROJECT_STATUS_IMPORTANT} $filenameWithoutEmojiPrefix'"
fi
}}
## bindings
### remove defaults
map m
map d
map e
map r
map p
map c
map u
map N # jump to prev result
### create files
map t touch
map T touchTex
map NN gen-note
map ci create-index
map cp create-project
map cd create-design
map ca create-area
map cr create-resource
map cP create-plan
### own bindings
map cb combine
map e edit
map u clear-unselect
map rm remove $f
map rp rm_pi
map x cut
map p paste_and_forget
map <esc> clear
map d mkdir
map D diropen
map Y diropenShuffle
map S source-config
map . set hidden!
map R reload
map I gimp # [I]mage
map L show-tasks
map sr set reverse!
map rd ldr
### fzf open
### move into dir
map <a-d> fzf_dir
map <a-f> fzf_file
map <a-a> $lf -remote "send $id cd '$ORG_AREAS/$(select-area)'"
map <a-p> $lf -remote "send $id cd '$ORG_PROJECTS/$(select-project)'"
map <a-r> $lf -remote "send $id cd '$ORG_RESOURCES/$(select-resource)'"
### move files
map mm massmove
map mi move-to-inbox
map mI move-to-other-inbox
map mA move-to-archive
map ml move-to-local-archive
map mP move-to-paperless
map mb move-to-blog-post-ideas
map md move-to-designs
map ma move-to-area
map mp move-to-project
map mr move-to-resource
### jump - cd to dirs
map go %lf -remote "send $id cd $ORG"
map gi %lf -remote "send $id cd $ORG_INBOX"
map gd %lf -remote "send $id cd $ORG_DESIGN"
map gp %lf -remote "send $id cd $ORG_PROJECTS"
map ga %lf -remote "send $id cd $ORG_AREAS"
map gf %lf -remote "send $id cd $ORG_AREAS/Freunde"
map ge %lf -remote "send $id cd $ORG_AREAS/geld"
map gR %lf -remote "send $id cd $ORG_AREAS/routine"
map gI %lf -remote "send $id cd $ORG_AREAS/assets/Aktien/Investieren"
map gt %lf -remote "send $id cd $ORG_AREAS/assets/Aktien/Trading"
map gG %lf -remote "send $id cd $ORG_AREAS/geld"
map gP %lf -remote "send $id cd $ORG_AREAS/blog/posts"
map gt %lf -remote "send $id cd $ORG_AREAS/blog/posts"
map gb %lf -remote "send $id cd $ORG_AREAS/blog"
map gr %lf -remote "send $id cd $ORG_RESOURCES"
# map gb %lf -remote "send $id cd $ORG_RESOURCES/media/books"
map gn %lf -remote "send $id cd $ORG_RESOURCES/Neurostreams/Neurostreams"
map gmm %lf -remote "send $id cd $ORG_MEDIA"
map gM %lf -remote "send $id cd $ORG_MEDIA/music"
map gA %lf -remote "send $id cd $ORG_ARCHIVE"
map gs %lf -remote "send $id cd $ORG_INBOX/screenshots"
map gD cd ~/Downloads
map gc cd ~/code
map gl cd .archive # local archive
map öa set-status-active
map öi set-status-inactive
map öu set-status-inactive
map öb set-status-blocked
map ön set-status-none
map ö! set-status-important
map o jump-prev
map i jump-next