1
0
Fork 0

experimental lf binding

This commit is contained in:
Luca Bilke 2024-03-19 22:39:41 +01:00
parent 402abede44
commit 983c3b522b
3 changed files with 63 additions and 52 deletions

View File

@ -131,42 +131,54 @@ cmd dupe &{{
# cmd share $curl -F"file=@$fx" https://0x0.snaile.de | xclip -r -selection c
# TODO: Move this to zsh config
cmd fzfsearch ${{
file="$(find -L $PWD | fzf --header='Searching Filenames' --preview='head -$LINES {} 2>/dev/null || ls -lhpAN --color=always --group-directories-first {}' || true)"
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 fzftags ${{
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 fzfmarks ${{
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 fzfshortcut ${{
file="$(cat $XDG_DATA_HOME/lf/dirs | fzf --header='Searching Shortcuts' --preview='echo '{}' | cut -f2 | xargs ls' | cut -f2 )"
[ -z "$file" ] && return
[ -d "$file" ] && lf -remote "send $id cd $file" && return 0
[ -f "$file" ] && lf -remote "send $id select $file"
cmd find_shortcut ${{
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 <<< {})
if [ -f "$file" ] && [ -r "$file" ]; then
head -$LINES "$file"
elif [ -d "$file" ] && [ -r "$file" ]; then
ls -lhpANX --color=always --group-directories-first "$file"
fi
' <"$XDG_DATA_HOME/lf/dirs" |
cut -f2 |
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
}}
# cmd fzfworkon ${{
# workon -n $(workon | fzf)
# }}
cmd fzfgrep ${{
cmd find_word ${{
set +ue
RG_PREFIX="rg --hidden --column --line-number --no-heading --color=always --smart-case --follow --no-ignore "
res="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX ''" \
fzf --bind "change:reload:$RG_PREFIX {q} || true" \
--ansi --layout=reverse --header 'Searching file contents' |\
grep -iv -e 'Trash/files' -e 'Trash/info'
fzf --bind "change:reload:$RG_PREFIX {q} || true" \
--ansi --layout=reverse --header 'Searching file contents' |\
grep -iv -e 'Trash/files' -e 'Trash/info'
)"
file="$(realpath "$(echo "$res" | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g')" 2>/dev/null)"
row="$(echo "$res" | cut -d':' -f2)"
@ -193,16 +205,16 @@ cmd extract ${{
done
}}
cmd set_previewer %{{
cmd set_previewer &{{
if [ "${1}" = "sixel" ]; then
lf -remote "send $id :set sixel; set previewer ~/.config/lf/preview/sixel"
echo 'Previewer set to sixel'
# echo 'Previewer set to sixel'
elif [ "${1}" = "ueberzug" ]; then
lf -remote "send $id :set cleaner ~/.config/lf/preview/clean; set previewer ~/.config/lf/preview/ueberzug"
echo 'Previewer set to ueberzug'
# echo 'Previewer set to ueberzug'
else
lf -remote "send $id :set previewer ~/.config/lf/preview/chafa"
echo 'Previewer set to chafa'
# echo 'Previewer set to chafa'
fi
}}
@ -215,9 +227,9 @@ cmd new_lf_term &{{
&{{
set +u
previewer=sixel
previewer=ueberzug
# [ -n "$SCRATCHPAD" ] && previewer=sixel
[ -n "$TMUX" ] && previewer=ueberzug
# [ -n "$TMUX" ] && previewer=ueberzug
[ -n "$VIM" ] && previewer=chafa
lf -remote "send $id set_previewer $previewer"
@ -238,11 +250,11 @@ map <esc> quit
map <space> :toggle; down
map <enter> shell
map <a-enter> shell-wait
map <tab>a fzfsearch
map <tab>t fzftags
map <tab>m fzfmarks
map <tab>f fzfshortcut
map <tab>g fzfgrep
map <tab> find_shortcut
map -a find_file
map -t find_tag
map -m find_mark
map -g find_word
map "'" mark-load
map '"' mark-save
map "$" shell
@ -267,8 +279,6 @@ map F find-back
map <c-g> lazygit
map <a-g> $gdu
map gg top
map g/ cd "/"
# WARN: do not chain any more maps to g (check shortcutrc)
map G bottom
map h updir
map i :rename; cmd-end # rename from end
@ -287,7 +297,7 @@ map q quit
map <c-r> reload
map r :rename # before extension
map R $lf -remote "send $id :select \"$(readlink $f)\""
map <c-s> set hidden!
map sh :set hidden!
map sn :set sortby natural; set info
map ss :set sortby size; set info size
map st :set sortby time; set info time
@ -312,6 +322,3 @@ map zn set info
map zs set info size
map zt set info time
map za set info size:time
# Load bookmark shortcuts
source "~/.config/lf/shortcutrc"

View File

@ -1,18 +0,0 @@
map gh cd "/home/luca"
map gch cd "/home/luca/.cache"
map gcf cd "/home/luca/.config"
map gdt cd "/home/luca/.local/share"
map gst cd "/home/luca/.local/state"
map gsc cd "/home/luca/.local/bin"
map gse cd "/home/luca/.local/libexec"
map gmn cd "/mnt"
map gco cd "/home/luca/Documents/dev"
map gdl cd "/home/luca/Downloads"
map gdm cd "/home/luca/Documents"
map gdk cd "/home/luca/Desktop"
map gms cd "/home/luca/Music"
map gpc cd "/home/luca/Pictures"
map gvd cd "/home/luca/Videos"
map gdot cd "/home/luca/.local/share/stow/dots"
map glg cd "/home/luca/.local/log"
map gsv cd "/home/luca/.local/sv"

22
.config/lf/test.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/sh
clear
file="$(\
fzf --expect=' ' --select-1 --cycle --bind one:accept -q '^' -e -n1 --scheme=history --history="$XDG_DATA_HOME/lf/shortcut_history" --header='Searching Shortcuts' --preview='
file=$(cut -f2 <<< "{}")
if [ -f "$file" ] && [ -r "$file" ]; then
head -$LINES "$file"
elif [ -d "$file" ] && [ -r "$file" ]; then
ls -lhpANX --color=always --group-directories-first "$file"
fi
' <"$XDG_DATA_HOME/lf/dirs" |
cut -f2 |
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