aboutsummaryrefslogtreecommitdiffstats
path: root/modules/tools/lf/lfrc
blob: 11a99593b66e23501680b62469fe33d6b86a7f85 (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
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
# ─── lf config — nvim-tree style keybindings ───────────────────────────────

# ─── Colors (optional — remove if you use a color scheme plugin) ──────────────
# set color256 true

# ─── Custom commands ──────────────────────────────────────────────────────────

# Create a new file (like nvim-tree 'a' with no trailing /)
cmd touch %{{
    printf "New file name: "
    read -r name
    touch "$name"
    lf -remote "send $id select '$name'"
}}

# Create a new directory (like nvim-tree 'a' with trailing /)
cmd mkdir %{{
    printf "New directory name: "
    read -r name
    mkdir -p "$name"
    lf -remote "send $id select '$name'"
}}

# Rename — full name (like nvim-tree 'r')
cmd rename ${{
    printf "Rename '%s' to: " "$f"
    read -r newname
    mv -- "$f" "$(dirname "$f")/$newname"
    lf -remote "send $id select '$newname'"
}}

# Rename — only basename without extension (like nvim-tree 'e' in some configs)
cmd rename_stem ${{
    stem="${f##*/}"
    stem="${stem%.*}"
    printf "Rename stem to: "
    read -r newname
    ext="${f##*.}"
    if [ "${f##*/}" = "$stem" ]; then
        mv -- "$f" "$(dirname "$f")/$newname"
    else
        mv -- "$f" "$(dirname "$f")/$newname.$ext"
    fi
}}

# Delete — trash (safe) using trash-cli if available, else rm
cmd trash %{{
    set -f
    files=$(printf '%s\n' $fx | wc -l)
    printf "Trash $files item(s)? [y/N] "
    read -r ans
    [ "$ans" = "y" ] || [ "$ans" = "Y" ] || exit 0
    if command -v trash-put >/dev/null 2>&1; then
        printf '%s\n' $fx | xargs trash-put --
    else
        printf '%s\n' $fx | xargs rm -rf --
    fi
}}

# Delete — permanent, no confirmation prompt (use carefully)
cmd delete ${{
    set -f
    printf "Permanently delete? [y/N] "
    read -r ans
    [ "$ans" = "y" ] || [ "$ans" = "Y" ] || exit 0
    rm -rf -- $fx
}}

# Paste (move or copy depending on operation)
cmd paste &{{
    set -f
    load=$(lf -remote 'load')
    mode=$(echo "$load" | sed -n '1p')
    list=$(echo "$load" | sed -n '2,$p')
    if [ "$mode" = "copy" ]; then
        cp -rn -- $list .
    elif [ "$mode" = "move" ]; then
        mv -n -- $list .
        lf -remote 'send clear'
    fi
    lf -remote 'send reload'
    lf -remote 'send clear'
}}

# Paste with overwrite
cmd paste_overwrite &{{
    set -f
    load=$(lf -remote 'load')
    mode=$(echo "$load" | sed -n '1p')
    list=$(echo "$load" | sed -n '2,$p')
    if [ "$mode" = "copy" ]; then
        cp -r -- $list .
    elif [ "$mode" = "move" ]; then
        mv -- $list .
        lf -remote 'send clear'
    fi
    lf -remote 'send reload'
    lf -remote 'send clear'
}}

# Open in nvim
cmd edit $nvim "$f"

# Open with xdg-open (GUI apps)
cmd open_gui &xdg-open "$f"

# Toggle hidden files (like nvim-tree 'H')
cmd toggle_hidden :{{
    set hidden!
    set info
}}

# Bulk rename with $EDITOR (like vimv / nvim-tree mass rename)
cmd bulk_rename ${{
    index=$(mktemp /tmp/lf-bulk-index.XXXXXX)
    names=$(mktemp /tmp/lf-bulk-names.XXXXXX)
    printf '%s\n' $fx > "$index"
    sed 's|.*/||' "$index" > "$names"
    $EDITOR "$names"
    paste "$index" "$names" | while IFS=$'\t' read -r old new; do
        if [ "$old" != "$(dirname "$old")/$new" ]; then
            mv -- "$old" "$(dirname "$old")/$new"
        fi
    done
    rm -- "$index" "$names"
    lf -remote 'send reload'
}}

# Create symlink (relative)
cmd symlink %{{
    printf "Symlink target name: "
    read -r name
    ln -s "$f" "$name"
}}

# Copy path to clipboard (needs xclip / xsel / wl-copy)
cmd copy_path &{{
    printf '%s' "$f" | xclip -selection clipboard 2>/dev/null \
      || printf '%s' "$f" | xsel --clipboard --input 2>/dev/null \
      || printf '%s' "$f" | wl-copy 2>/dev/null
}}

# Show file info (like nvim-tree 'i')
cmd info %{{
    stat -- "$f"
    printf '\nPress ENTER...'
    read -r _
}}

# Jump to bookmarks (requires fzf)
cmd bookmark_jump ${{
    bm="$HOME/.config/lf/bookmarks"
    [ -f "$bm" ] || touch "$bm"
    dest=$(cat "$bm" | fzf --prompt "Jump to: ")
    [ -n "$dest" ] && lf -remote "send $id cd '$dest'"
}}

# Add bookmark
cmd bookmark_add %{{
    bm="$HOME/.config/lf/bookmarks"
    printf '%s\n' "$PWD" >> "$bm"
    sort -u "$bm" -o "$bm"
    echo "Bookmarked: $PWD"
}}

# fzf-based fuzzy find & cd/select
cmd fzf_cd ${{
    dest=$(find . -type d 2>/dev/null | fzf --prompt "cd: ")
    [ -n "$dest" ] && lf -remote "send $id cd '$dest'"
}}

cmd fzf_file ${{
    file=$(find . -type f 2>/dev/null | fzf --prompt "open: ")
    [ -n "$dest" ] && lf -remote "send $id select '$file'"
}}

# ─── Keybindings — clear defaults and remap ───────────────────────────────────

# Unmap keys we'll remap
map d
map y
map p
map c
map r
map a
map e
map f
map g
map G
map i
map o
map H
map m

# ── Navigation ────────────────────────────────────────────────────────────────
map h   updir               # go up one dir
map l   open                # open file/dir (maps to $EDITOR for files)
map j   down
map k   up
map J   half-down
map K   half-up
map gg  top
map G   bottom
map gd  cd ~/Downloads
map gh  cd ~
map gc  cd ~/.config
map gp  cd ~/projects

# Page navigation (nvim-style)
map <c-d>  half-down
map <c-u>  half-up
map <c-f>  page-down
map <c-b>  page-up

# ── Opening / editing ─────────────────────────────────────────────────────────
map <enter>  open              # open with default
map o        open_gui          # open with GUI app
map e        edit              # open in nvim explicitly

# ── File / dir creation ───────────────────────────────────────────────────────
map af   touch               # a → file  (like nvim-tree 'a' without /)
map ad   mkdir               # a → dir   (like nvim-tree 'a' with /)

# ── Rename ────────────────────────────────────────────────────────────────────
map r    rename              # full rename (like nvim-tree 'r')
map R    bulk_rename         # bulk rename in $EDITOR
map cw   rename              # alias: cw like vim's 'change word'
map I    rename              # alias: go to start (lf positions cursor)
map A    rename              # alias: go to end

# ── Delete ────────────────────────────────────────────────────────────────────
map dd   trash               # move to trash (safe delete — like nvim-tree 'd')
map dD   delete              # permanent delete (no trash)

# ── Yank / Copy / Cut / Paste ─────────────────────────────────────────────────
map yy   copy                # yank/copy selection (like nvim-tree 'c')
map yn   copy_path           # yank path to clipboard
map dd   cut                 # cut selection (like nvim-tree 'x') — overrides trash above;
                             # uncomment the trash line below if you prefer separate keys
# map dt   trash             # use 'dt' for trash if 'dd' is used for cut
map pp   paste               # paste (like nvim-tree 'p')
map po   paste_overwrite     # paste with overwrite
map P    paste               # alias

# ── Marking / selection ───────────────────────────────────────────────────────
map <space>  toggle          # toggle mark on current item (like nvim-tree space)
map v        invert          # invert selection
map V        invert          # alias
map u        unselect        # clear all marks
map *        glob-select '*' # select all via glob

# ── Search ────────────────────────────────────────────────────────────────────
map /        search          # incremental search forward
map n        search-next
map N        search-prev
map f        fzf_file        # fuzzy find file (requires fzf)
map F        fzf_cd          # fuzzy cd into dir (requires fzf)

# ── View toggles ──────────────────────────────────────────────────────────────
map H    toggle_hidden       # toggle hidden files (like nvim-tree 'H')
map zi   set icons!
map zr   set reverse!
map zh   set hidden!
map zn   set sortby natural
map zs   set sortby size
map zm   set sortby modified
map ze   set sortby ext

# ── Info / misc ───────────────────────────────────────────────────────────────
map i        info            # show stat info (like nvim-tree 'i')
map <c-r>    reload          # reload directory
map <esc>    clear           # clear selection
map q        quit
map Q        quit
map m        bookmark_add    # add bookmark
map '        bookmark_jump   # jump to bookmark (requires fzf)

# Symlink
map S        symlink