]> Freerunner's - dotfiles.git/commitdiff
lf: update config/keybinds
authorAndre Ramnitz <tux.rising@gmail.com>
Fri, 26 Jan 2024 15:35:13 +0000 (16:35 +0100)
committerAndre Ramnitz <tux.rising@gmail.com>
Sun, 18 Aug 2024 16:18:53 +0000 (18:18 +0200)
config/lf/lfrc

index a376cd80c810793dc6424a88af22cb5dbffc8da9..dbb0ef4a82d77166b4e58b84b76a3e58be3882c1 100644 (file)
@@ -1,4 +1,11 @@
 #vim: noai:ft=conf:ts=4:sw=4
+# warn on nested instances
+&[ $LF_LEVEL -eq 1 ] || lf -remote "send $id echoerr \"Warning: You're in a nested lf instance!\""
+
+# toggles
+set ignorecase
+set icons
+set info size
 
 set previewer ~/.config/lf/previewer.sh
 set cleaner ~/.config/lf/clear_img.sh
@@ -23,7 +30,7 @@ set shellopts '-eu'
 set ifs "\n"
 
 # leave some space at the top and the bottom of the screen
-set scrolloff 10
+set scrolloff 3
 
 # use enter for shell commands
 # map <enter> shell
@@ -46,6 +53,18 @@ set scrolloff 10
 # map <delete> trash
 # map <delete> delete
 
+cmd touchdir ${{
+       printf "Directory name:"
+       read ans
+       mkdir $ans
+}}
+
+cmd touchfile ${{
+       printf "File name:"
+       read ans
+       touch $ans
+}}
+
 # extract the current file with the right command
 # (xkcd link: https://xkcd.com/1168/)
 cmd extract ${{
@@ -149,21 +168,133 @@ cmd toggle_preview %{{
     fi
 }}
 
-# go commands
+# Trash cli bindings
+cmd trash ${{
+  files=$(printf "$fx" | tr '\n' ';')
+  while [ "$files" ]; do
+    # extract the substring from start of string up to delimiter.
+    # this is the first "element" of the string.
+    file=${files%%;*}
+
+    trash-put "$(basename "$file")"
+    # if there's only one element left, set `files` to an empty string.
+    # this causes us to exit this `while` loop.
+    # else, we delete the first "element" of the string from files, and move onto the next.
+    if [ "$files" = "$file" ]; then
+      files=''
+    else
+      files="${files#*;}"
+    fi
+  done
+  notify-send " ðŸš® Trashing." "$file Moved to Trash"
+}}
+
+cmd clear_trash %trash-empty
+
+cmd trash-restore ${{
+  trash-restore
+}}
+
+cmd move-parent &{{
+    dironly="setlocal '$(dirname "$PWD")' dironly"
+    lf -remote "send $id :updir; $dironly true; $1; $dironly false; open"
+}}
+
+cmd select-files &{{
+    get_files() {
+        if [ "$lf_hidden" = 'false' ]; then
+            find "$PWD" -mindepth 1 -maxdepth 1 -type f -not -name '.*' -print0
+        else
+            find "$PWD" -mindepth 1 -maxdepth 1 -type f -print0
+        fi |
+        xargs -0 printf ' %q'
+    }
+
+    lf -remote "send $id :unselect; toggle $(get_files)"
+}}
+
+cmd select-dirs &{{
+    get_dirs() {
+        if [ "$lf_hidden" = 'false' ]; then
+            find "$PWD" -mindepth 1 -maxdepth 1 -type d -not -name '.*' -print0
+        else
+            find "$PWD" -mindepth 1 -maxdepth 1 -type d -print0
+        fi |
+        xargs -0 printf ' %q'
+    }
+
+    lf -remote "send $id :unselect; toggle $(get_dirs)"
+}}
+
+cmd select-all &{{
+    get_dirs() {
+        if [ "$lf_hidden" = 'false' ]; then
+            find "$PWD" -mindepth 1 -maxdepth 1 -type d -not -name '.*' -print0
+        else
+            find "$PWD" -mindepth 1 -maxdepth 1 -type d -print0
+        fi |
+        xargs -0 printf ' %q'
+    }
+    get_files() {
+        if [ "$lf_hidden" = 'false' ]; then
+            find "$PWD" -mindepth 1 -maxdepth 1 -type f -not -name '.*' -print0
+        else
+            find "$PWD" -mindepth 1 -maxdepth 1 -type f -print0
+        fi |
+        xargs -0 printf ' %q'
+    }
+
+    lf -remote "send $id :unselect; toggle $(get_files) $(get_dirs)"
+}}
+# unmap keys
+map d
+map m
+map t
+
+# one-shot commands
+map x cut
+map R bulk-rename
+map J move-parent down
+map K move-parent up
+map \= select-dirs
+map \+ select-files
+map \% select-all
+map \| shell-pipe
+
+# m = mark
+map mm mark-save
+map mr mark-remove
+# mark-load is gm
+
+# t = touch
+map td touchdir
+map tt touchfile
+
+# d = delete
+map dd trash
+map dD delete
+map dr trash-restore
+
+# o = order
+map oc : set sortby ctime; set reverse false; set info ctime
+map oe : set sortby ext; set reverse false; set info size
+map on : set sortby name; set reverse false; set info size
+map os : set sortby size; set reverse false; set info size
+map om : set sortby time; set reverse false; set info time
+map oC : set sortby ctime; set reverse true; set info ctime
+map oE : set sortby ext; set reverse true; set info size
+map oN : set sortby name; set reverse true; set info size
+map oS : set sortby size; set reverse true; set info size
+map oM : set sortby time; set reverse true; set info time
+
+# g = goto
 map gc cd ~/.config
-map gm cd /mnt
-map gM cd /media
+map gm mark-load
+map gM cd /mnt
 map ge bottom
 map go :fzf_jump
 map gs :fzf_search
 
-# sort commands}
-map sa
-map st :{{set sortby time; reverse; set info time;}}
-map sT :{{set sortby time; set info time;}}
-map ss :{{set sortby size; reverse; set info size;}}
-map sS :{{set sortby size; set info size;}}
-
 # various commands
 map zp toggle_preview
 map C edit-config