blob: f88c56266777095df1b6a33f6cf725ffde9c3b98 (
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
|
set icons
set scrolloff 3
set ratios 1:4:3
set period 1
set ifs "\n"
set info size
set previewer ~/.local/bin/scope
set mouse true
set drawbox true
# Custom commands
cmd on-cd &{{
# '&' commands run silently in background (which is what we want here),
# but are not connected to stdout.
# To make sure our escape sequence still reaches stdout we pipe it to /dev/tty
printf "\033]0; lf - $PWD\007" > /dev/tty
}}
on-cd
cmd mkdir $mkdir -p "$(echo $* | tr ' ' '\ ')"
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
}}
# compress current file or selected files with tar and gunzip
cmd tar ${{
set -f
mkdir $1
cp -r $fx $1
tar -czf $1.tar.gz $1
rm -rf $1
}}
# extract the current file with the right command
cmd extract ${{
set -f
case $f in
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.xz|*.txz) tar xJvf $f;;
*.zip) unzip $f;;
*.rar) unrar x $f;;
*.7z) 7z x $f;;
esac
}}
# change dir with fzf
cmd fzf_jump ${{
res="$(find . -type d | fzf --header='Jump to location')"
if [ -d "$res" ]; then
cmd="cd"
else
cmd="select"
fi
lf -remote "send $id $cmd \"$res\""
}}
# open file with fzf
cmd fzf_open ${{
res="$(find . -type d -path "*/\.*" -prune -o -not -name ".*" -type f | fzf)"
if [ -e "$res" ]; then
setsid mimeo "$res" &
fi
}}
# drag and drop prompt
cmd dragon $dragon-drop -a $fx
cmd dragon_drop $cp $(dragon-drop --target | sed 's/file:\/\///g') .
# copy path to clipboard
cmd yank-path &printf '%s' "$fx" | wl-copy
cmd open &mimeo $fx
cmd hard_link %{{
load=$(cat ~/.local/share/lf/files)
list=$(echo "$load" | sed '1d')
ln $list .
}}
cmd soft_link %{{
load=$(cat ~/.local/share/lf/files)
list=$(echo "$load" | sed '1d')
ln -s $list .
}}
cmd paste &{{
set -- $(cat ~/.local/share/lf/files)
mode="$1"
shift
case "$mode" in
copy)
rsync -rlDvh --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 -- "$@" .
lf -remote "send $id clear"
;;
esac
lf -remote "send $id reload"
}}
cmd archive &{{
set -- $(cat ~/.local/share/lf/files)
mode="$1"
shift
case "$mode" in
copy)
rsync -avhH --delete --progress -- "$@" . |
stdbuf -i0 -o0 -e0 tr '\r' '\n' |
while IFS= read -r line; do
lf -remote "send $id echo $line"
done
;;
move)
rsync -avhH --delete --remove-source-files --progress -- "$@" . |
stdbuf -i0 -o0 -e0 tr '\r' '\n' |
while IFS= read -r line; do
lf -remote "send $id echo $line"
done
lf -remote "send $id clear"
;;
esac
lf -remote "send $id reload"
}}
# Bindings
map A rename
map c
map cc clear
map cd push :cd<space>
map cw push A<c-u> # rename from zero
map I push A<c-a> # rename from the beginning
map i push A<a-b><a-b><a-f> # rename before extention
map a push A<a-b> # rename after extention
map <c-n> push :mkdir<space>
map <c-t> push :$touch<space>
map <c-r> reload
map <enter> shell
map D delete
map <enter> shell
map f :fzf_jump
map o :fzf_open
map t :dragon
map T :dragon_drop
map W $setsid $TERMINAL > /dev/null 2>&1 & # open new terminal window
map Y :yank-path
map L $LESSOPEN='| ~/.local/bin/scope %s' less -r $f # open file preview in pager
map P hard_link
map <a-p> soft_link
map r archive
# Mouse bindings
map <m-3> :dragon
|