1
0
Fork 0
dotfiles/.config/lf/lfrc

237 lines
6.8 KiB
Plaintext
Raw Normal View History

2022-07-04 21:36:33 +02:00
# Basic vars
2024-01-30 01:36:46 +01:00
set ratios 1:2:5
2022-07-04 21:36:33 +02:00
set shellopts '-eu'
set ifs "\n"
2022-10-24 18:10:24 +02:00
set findlen 1
2022-07-04 21:36:33 +02:00
set scrolloff 10
set icons
2022-08-03 14:39:17 +02:00
set wrapscroll
2022-07-04 21:36:33 +02:00
set period 1
2023-06-16 10:20:47 +02:00
set cursorpreviewfmt "\033[7;90m"
2024-02-22 14:45:42 +01:00
set promptfmt # this is set in a function later
2022-07-04 21:36:33 +02:00
2024-02-05 16:51:16 +01:00
# HACK: This is needed to trigger the opening function of the taolf nvim plugin
cmd open ${{
set +u
2024-02-05 16:50:26 +01:00
[ "$lf_user_multiedit" = "true" ] && { $EDITOR $fx; return; }
$OPENER "$f"
2024-02-01 00:33:30 +01:00
}}
cmd pushedit %{{
echo "Open: " && read files
echo
echo $files | xargs touch
lf -remote "send $id \$$OPENER $files
send $id unselect"
2024-02-01 00:33:30 +01:00
}}
2023-05-31 11:26:50 +02:00
cmd open-with ${{
2024-02-01 00:33:30 +01:00
method=$(rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -l $fx | fzf --header="Choose an application:" | cut -d':' -f1)
2023-05-31 11:27:31 +02:00
rifle -c $XDG_CONFIG_HOME/lf/rifle.conf -p $method $fx
2022-07-04 21:36:33 +02:00
}}
2023-12-11 16:42:07 +01:00
cmd trash &{{
2023-11-17 11:12:50 +01:00
for f in $fx; do
trash-put $f &
done
2024-02-01 00:33:30 +01:00
lf -remote "send load"
2022-07-07 16:23:55 +02:00
}}
2024-02-05 15:37:19 +01:00
cmd lazygit %{{
2024-02-01 09:33:43 +01:00
dir=$(dirname "$(realpath "${f:-_}")"})
if ! git --noglob-pathspecs -C $dir status >/dev/null 2>&1; then
echo "Initialize git repo in '${dir}' [Y/n]:" && read yn &&
case $yn in
"" | [Yy]*) git -C ${dir} init >/dev/null 2>&1; break ;;
[Nn]*) ;;
esac
fi
lf -remote "send $id \$cd '$dir' && lazygit"
2023-11-22 20:42:33 +01:00
}}
2022-07-06 16:41:11 +02:00
# y (select for copy) and P to paste soft-link
# d (select for cut) and P to paste hard-link
2023-11-22 10:21:14 +01:00
cmd link &{{
2022-07-06 16:41:11 +02:00
set -- $(cat ~/.local/share/lf/files)
mode="$1"
shift
if [ "$#" -lt 1 ]; then
lf -remote "send $id echo no files to link"
exit 0
fi
case "$mode" in
# symbolically copy mode is indicating a soft link
copy) ln -sr -t . -- "$@";;
# while a move mode is indicating a hard link
move) ln -t . -- "$@";;
esac
rm ~/.local/share/lf/files
lf -remote "send clear"
}}
2022-07-04 21:36:33 +02:00
cmd bulkrename $vidir
cmd on-cd &{{
2024-02-22 14:45:42 +01:00
prompt="$(zsh -lc 'print -P $PS1')\033[33m%f\033[0m"
2024-02-22 14:45:53 +01:00
printf "%b" "\033]0;$(echo $prompt | sed 's/\[[0-9;]*m//g;s/» %f//g')\007" > /dev/tty
2024-02-22 14:45:42 +01:00
lf -remote "send $id set promptfmt \"$prompt\""
2022-07-07 16:23:55 +02:00
}}
2024-02-01 20:34:38 +01:00
cmd on-quit &printf "\033]0; $(echo $PWD | sed "s|$HOME|~|")\007" > /dev/tty
2022-07-07 16:23:55 +02:00
2022-09-15 20:27:44 +02:00
cmd paste &{{
set -- $(cat ~/.local/share/lf/files)
mode="$1"
shift
case "$mode" in
2023-11-17 11:12:50 +01:00
copy)
2024-02-15 01:08:58 +01:00
rsync -aP --del -- "$@" . |
2023-11-17 11:12:50 +01:00
stdbuf -i0 -o0 -e0 tr '\r' '\n' |
while IFS= read -r line; do
lf -remote "send $id echo $line"
done
;;
2022-09-15 20:27:44 +02:00
move) mv -n -- "$@" .;;
esac
rm ~/.local/share/lf/files
lf -remote "send clear"
}}
2023-11-22 10:21:14 +01:00
cmd dupe &{{
for file in $fx; do
find "$PWD" "$file" -maxdepth 0 | grep -oP '(?<=.\.~)\d+(?=~$)' | sort -n | tail -1 | (
ext=$(($(cat /dev/stdin)+1))
filedest="$(echo "$file" | sed 's/.~[[:digit:]]*~$//').~$ext~"
cp -r "$file" "$filedest"
)
done
}}
# cmd share $curl -F"file=@$fx" https://0x0.snaile.de | xclip -r -selection c
2022-07-07 16:23:55 +02:00
2023-03-21 19:21:46 +01:00
cmd fzfsearch ${{
2024-02-01 00:33:30 +01:00
file="$(find -L $PWD | fzf --header="Searching Filenames")"
2023-04-04 11:42:59 +02:00
[ -d $file ] && lf -remote "send $id cd $file" && return 0
2023-03-21 19:21:46 +01:00
[ -f $file ] && lf -remote "send $id select $file"
}}
cmd fzftags ${{
2024-02-01 00:33:30 +01:00
file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/tags | sed 's/:\*$//' | fzf --header="Searching Tags")"
2023-04-04 11:42:59 +02:00
[ -d $file ] && lf -remote "send $id cd $file" && return 0
2023-03-21 19:21:46 +01:00
[ -f $file ] && lf -remote "send $id select $file"
}}
cmd fzfmarks ${{
2024-02-01 00:33:30 +01:00
file="$(cat ${XDG_DATA_HOME:-$HOME/.local/share}/lf/marks | sed 's/^.://' | fzf --header="Searching Marks")"
2023-04-04 11:42:59 +02:00
[ -d $file ] && lf -remote "send $id cd $file" && return 0
2023-03-21 19:21:46 +01:00
[ -f $file ] && lf -remote "send $id select $file"
}}
2023-11-17 11:12:50 +01:00
cmd fzfshortcut ${{
2024-02-01 00:33:30 +01:00
file="$(cat ${XDG_CONFIG_HOME:-$HOME/.config}/lf/shortcutrc | cut -d '"' -f2 | fzf --header="Searching Shortcuts")"
2023-11-17 11:12:50 +01:00
[ -d $file ] && lf -remote "send $id cd $file" && return 0
[ -f $file ] && lf -remote "send $id select $file"
2023-03-21 19:21:46 +01:00
}}
2023-06-15 17:27:56 +02:00
cmd fzfgrep ${{
2024-02-01 20:17:42 +01:00
set +ue
2024-02-02 19:31:02 +01:00
RG_PREFIX="rg --hidden --column --line-number --no-heading --color=always --smart-case --follow "
2023-06-15 17:27:56 +02:00
res="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX ''" \
fzf --bind "change:reload:$RG_PREFIX {q} || true" \
2024-02-01 00:33:30 +01:00
--ansi --layout=reverse --header 'Searching file contents' |\
2024-01-31 18:31:31 +01:00
grep -iv -e 'Trash/files' -e 'Trash/info'
2023-06-15 17:27:56 +02:00
)"
2024-02-02 19:31:02 +01:00
file="$(realpath "$(echo "$res" | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g')")"
2024-02-01 20:17:42 +01:00
row="$(echo "$res" | cut -d':' -f2)"
column="$(echo "$res" | cut -d':' -f3)"
2024-01-31 18:31:31 +01:00
if [ -n "$res" ]; then
2024-02-02 19:31:02 +01:00
# shellcheck disable=2154
2024-02-01 00:33:30 +01:00
lf -remote "send $id select '$file'"
if [ -n "$VIM" ]; then
lf -remote "send $id open '$file'"
2024-02-02 19:31:02 +01:00
elif { [ "$EDITOR" = "nvim" ] || [ "$EDITOR" = "vim" ]; } && [ -n "$EMBEDDED" ]; then
2024-02-01 20:17:42 +01:00
lf -remote "send $id \$$EDITOR +'call cursor($row, $column)' -- $([ -n "$EMBEDDED" ] && echo "--") '$file'"
2024-01-31 18:31:31 +01:00
else
lf -remote "send $id \$$EDITOR '$file'"
fi
fi
2023-06-15 17:27:56 +02:00
}}
2024-01-29 20:46:03 +01:00
2024-01-25 00:47:31 +01:00
cmd extract ${{
for f in $fx; do
aunpack "$f"
done
}}
2023-03-21 19:21:46 +01:00
2024-01-29 20:46:03 +01:00
# TODO: Move this to zsh config
# cmd fzfworkon ${{
# workon -n $(workon | fzf)
# }}
2024-01-29 20:46:03 +01:00
cmd set_previewer %{{
if [ "${1}" = "sixel" ]; then
lf -remote "send $id :set sixel; set previewer ~/.config/lf/preview/sixel"
2024-01-29 20:46:03 +01:00
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"
2024-01-29 20:46:03 +01:00
echo 'Previewer set to ueberzug'
else
lf -remote "send $id :set previewer ~/.config/lf/preview/chafa"
2024-01-29 20:46:03 +01:00
echo 'Previewer set to chafa'
fi
}}
2024-01-31 00:55:55 +01:00
# HACK: This is a dirty hack to have an lf terminal that I can "exit" out of into a shell
cmd new_lf_term &{{
2024-02-01 10:25:26 +01:00
mapcmd='map q $sh -c "tmux; kill $id"'
2024-01-31 00:55:55 +01:00
previewercmd="set_previewer $(basename "$lf_previewer")"
2024-02-05 15:37:19 +01:00
$TERMINAL -e lfX -command "${previewercmd}; ${mapcmd}"
2024-01-31 00:55:55 +01:00
}}
2024-01-29 20:46:03 +01:00
2024-02-05 14:27:18 +01:00
&{{
2024-02-01 20:34:38 +01:00
set +u
previewer=sixel
[ -n "$TMUX" ] && previewer=ueberzug
[ -n "$VIM" ] && previewer=chafa
lf -remote "send $id set_previewer $previewer"
}}
2024-02-22 14:45:42 +01:00
on-cd
2024-02-01 20:34:38 +01:00
2022-07-04 21:36:33 +02:00
# Bindings
2023-03-21 19:21:46 +01:00
map <c-c>a fzfsearch
map <c-c>t fzftags
map <c-c>m fzfmarks
2023-11-17 11:12:50 +01:00
map <c-c>f fzfshortcut
2023-06-15 17:27:56 +02:00
map <c-c>g fzfgrep
map T trash
map <c-t> $trash-restore $PWD
map <c-d> &rm -rf -- $fx
2024-01-25 00:47:31 +01:00
map <c-e> extract
2022-07-06 16:41:11 +02:00
map P link
# map S share
2023-11-22 20:42:33 +01:00
map <c-g> lazygit
map <a-g> $gdu
2024-02-01 00:33:30 +01:00
map <c-v> pushedit
2024-02-08 17:04:57 +01:00
map <c-n> push :&mkdir<space>-p<space>
map N push :&touch<space>
2022-07-04 21:36:33 +02:00
map <c-r> reload
map <c-s> set hidden!
map x $$f
map X !$f
2023-05-31 11:26:50 +02:00
map o open-with
2023-11-22 10:21:14 +01:00
map O $less $f
2023-06-21 00:55:58 +02:00
map a :rename; cmd-home # rename from beginning
map r :rename; cmd-end # rename from end
map i :rename # before extension
map c push r<c-u> # new rename
2022-07-04 21:36:33 +02:00
map B bulkrename
map b dupe
2022-09-17 02:39:38 +02:00
map u :clear; unselect
map n &echo $f | xclip -r -selection c
2022-10-28 12:16:11 +02:00
map <esc> quit
2022-11-07 10:21:29 +01:00
map g/ cd "/"
2024-01-31 00:55:55 +01:00
map W new_lf_term
2024-02-05 16:50:26 +01:00
map e :set user_multiedit "true" ; open; set user_multiedit "false"
2023-11-22 10:21:14 +01:00
map E $sudo -e $f
map R $lf -remote "send $id :select \"$(readlink $f)\""
2022-10-21 17:52:11 +02:00
# Load bookmark shortcuts
source "~/.config/lf/shortcutrc"