From d99af87acd8b9545b09b21755584c6b8db222375 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Wed, 20 Mar 2024 11:53:22 +0100 Subject: [PATCH] lfrc refactor --- .config/lf/lfrc | 87 +++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/.config/lf/lfrc b/.config/lf/lfrc index 0b625fbc8..7f34dd738 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -131,46 +131,39 @@ cmd dupe &{{ # cmd share $curl -F"file=@$fx" https://0x0.snaile.de | xclip -r -selection c -cmd find_file ${{ - file="$(find -L $PWD | fzf --header='Searching Filenames' --preview='head -$LINES \"$(echo {} | cut -f2)\" 2>/dev/null || ls -lhpAN --color=always --group-directories-first {}' || true)" - [ -z "$file" ] && return - [ -d "$file" ] && lf -remote "send $id cd $file" && return 0 - [ -f "$file" ] && lf -remote "send $id select $file" -}} -cmd find_tag ${{ - file="$(cat $XDG_DATA_HOME/lf/tags | fzf --header='Searching Tags' | sed 's/:.$//' || true)" - [ -z "$file" ] && return - [ -d "$file" ] && lf -remote "send $id cd $file" && return 0 - [ -f "$file" ] && lf -remote "send $id select $file" -}} -cmd find_mark ${{ - file="$(cat $XDG_DATA_HOME/lf/marks | fzf --header='Searching Marks' | cut -b 3- || true)" - [ -z "$file" ] && return - [ -d "$file" ] && lf -remote "send $id cd $file" && return 0 - [ -f "$file" ] && lf -remote "send $id select $file" -}} -cmd find_shortcut ${{ +cmd fzf ${{ + name="$1" input="$2" delimiter="$3" field="$4" width="$5" query="${6:-}" + histfile="$XDG_DATA_HOME/$(echo $name | tr '[:upper:]' '[:lower:]')_history" + clear - file="$(\ - fzf --expect=' ' --preview-window right,90% --select-1 --cycle --bind one:accept -q '^' -d "\t" -e -n 1 --with-nth=1 --scheme=history --history="$XDG_DATA_HOME/lf/shortcut_history" --header='Searching Shortcuts' --preview=' - file=$(cut -f2 <<< {}) + file="$(eval "$input" | fzf \ + --query "$query" \ + --delimiter "$delimiter" \ + --exact \ + --select-1 \ + --cycle \ + --nth=1 \ + --with-nth=1 \ + --preview-window="right,$width" \ + --bind="one:accept,focus:transform-preview-label(echo {} | cut -d '$delimiter' -f '$field')" \ + --scheme='history' \ + --history="$histfile" \ + --header="$name" \ + --preview=' + file=$(echo {} | cut -d '$delimiter' -f '$field') if [ -f "$file" ] && [ -r "$file" ]; then head -$LINES "$file" elif [ -d "$file" ] && [ -r "$file" ]; then - ls -lhpANX --color=always --group-directories-first "$file" + ls -pLHAN1 --color=always --group-directories-first "$file" fi - ' <"$XDG_DATA_HOME/lf/dirs" | - cut -f2 | + ' | + cut -d "$delimiter" -f "$field" | tr -d '\n' )" - - if [ -d "$file" ]; then - lf -remote "send $id cd $file" - return - elif [ -f "$file" ]; then - lf -remote "send $id select $file" - fi + [ -d "$file" ] && lf -remote "send $id cd $file" && return 0 + [ -f "$file" ] && lf -remote "send $id select $file" }} + cmd find_word ${{ set +ue RG_PREFIX="rg --hidden --column --line-number --no-heading --color=always --smart-case --follow --no-ignore " @@ -228,18 +221,18 @@ cmd new_lf_term &{{ &{{ set +u previewer=ueberzug - # [ -n "$SCRATCHPAD" ] && previewer=sixel # [ -n "$TMUX" ] && previewer=ueberzug - [ -n "$VIM" ] && previewer=chafa + # [ -n "$VIM" ] && previewer=chafa lf -remote "send $id set_previewer $previewer" # Clean up tags that don't exist anymore - echo "$( - while read -r l; do - file=$(echo "$l" | cut -d ':' -f 1) - [ -e "$file" ] && echo "$l" - done <"${XDG_DATA_HOME}/lf/tags" - )" >"${XDG_DATA_HOME}/lf/tags" + # BUG: causes an obscure lf crash when tags are empty + # echo "$( + # while read -r l; do + # file=$(echo "$l" | cut -d ':' -f 1) + # [ -e "$file" ] && echo "$l" + # done <"${XDG_DATA_HOME}/lf/tags" + # )\n" >"${XDG_DATA_HOME}/lf/tags" }} on-cd @@ -250,19 +243,19 @@ map quit map :toggle; down map shell map shell-wait -map find_shortcut -map -a find_file -map -t find_tag -map -m find_mark +map fzf 'Shortcuts' 'cat $XDG_DATA_HOME/lf/shortcuts 2>/dev/null' ':' '2' '85%' '^' +map -t fzf 'Tags' 'cat $XDG_DATA_HOME/lf/tags 2>/dev/null' ':' '1' '50%' '^' +map -m fzf 'Marks' 'cat $XDG_DATA_HOME/lf/marks 2>/dev/null' ':' '2' '85%' '^' +map -f fzf 'Files' 'find -L $PWD' ':' '1' '50%' map -g find_word map "'" mark-load map '"' mark-save map "$" shell map "!" shell-wait map "&" shell-async -map ; find-next -map , find-prev -map / search +map ";" find-next +map "," find-prev +map "/" search map a :rename; cmd-home # rename from beginning map page-up map b dupe