From 9fd484d4ac214b210e457aa74554935a341fad02 Mon Sep 17 00:00:00 2001 From: Andre Ramnitz Date: Fri, 26 Jan 2024 16:35:13 +0100 Subject: [PATCH] lf: update config/keybinds --- config/lf/lfrc | 153 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 142 insertions(+), 11 deletions(-) diff --git a/config/lf/lfrc b/config/lf/lfrc index a376cd80..dbb0ef4a 100644 --- a/config/lf/lfrc +++ b/config/lf/lfrc @@ -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 shell @@ -46,6 +53,18 @@ set scrolloff 10 # map trash # map 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 -- 2.51.2