1
0
Fork 0

lfrc refactor

This commit is contained in:
Luca Bilke 2024-03-20 11:53:22 +01:00
parent 945f3d118f
commit d99af87acd
1 changed files with 40 additions and 47 deletions

View File

@ -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 <esc> quit
map <space> :toggle; down
map <enter> shell
map <a-enter> shell-wait
map <tab> find_shortcut
map -a find_file
map -t find_tag
map -m find_mark
map <tab> 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 <c-b> page-up
map b dupe