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

251 lines
7.3 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
2024-01-29 20:46:03 +01:00
set previewer "~/.config/lf/preview/chafa"
2023-06-16 10:20:47 +02:00
set cursorpreviewfmt "\033[7;90m"
set promptfmt "\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m%d\033[35m]\033[32m » \033[33m%f\033[0m"
2024-02-01 00:33:30 +01:00
set opener=opener
2022-07-04 21:36:33 +02:00
2024-02-01 00:33:30 +01:00
cmd pushedit %{{
2024-02-01 09:33:43 +01:00
echo "Open: " && read files
2024-02-01 00:33:30 +01:00
if sh -c '[ -n "$VIM" ]'; then
lf -remote "send $id vimopen $files"
else
lf -remote "send $id \$echo $files | xargs -or nvim +wa"
fi
lf -remote "send $id reload"
}}
cmd edit ${{
rifle -c "$XDG_CONFIG_HOME/lf/rifle.conf" -p 0 $fx
# if sh -c "[ -n '\$VIM' ]"; then
# lf -remote "send $id vimopen $fx"
# else
# lf -remote "send $id '\$echo $fx | xargs -or nvim +wa'"
# fi
}}
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
}}
2024-02-01 00:33:30 +01:00
cmd vimopen &{{
touch "$@"
lf -remote "$(
for f in "$@"; do printf "%b" "send $id toggle $f\n"; done
printf "%b" "send $id select $f\n"
printf "%b" "send $id open\n"
printf "%b" "send $id unselect\n"
)"
}}
2023-11-22 10:21:14 +01:00
cmd mkdir &mkdir -p "$(echo $* | tr ' ' '\ ')"
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-01 09:33:43 +01:00
cmd lazygit %{{
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-01-17 12:21:06 +01:00
printf "%b" "\033]0;$(zsh -c 'source $XDG_CONFIG_HOME/zsh/configs/autogenerated/hashes; print -Pn "$USER@$HOST [%3~]"') \007" > /dev/tty
2023-06-14 22:08:16 +02:00
fmt="\033[34;1m%u\033[36m@\033[34m%h \033[35m[\033[0;1m$(zsh -c 'source $XDG_CONFIG_HOME/zsh/configs/autogenerated/hashes; print -Pn "%3~"')\033[35m]\033[32m » \033[33m%f\033[0m"
2023-06-14 21:03:45 +02:00
lf -remote "send $id set promptfmt \"$fmt\""
2022-07-07 16:23:55 +02:00
}}
on-cd
cmd on-quit ${{
DIR=$(echo $PWD | sed "s|$HOME|~|")
printf "\033]0; $DIR\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)
rsync -av --ignore-existing --progress -- "$@" . |
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-01-31 18:31:31 +01:00
RG_PREFIX="rg --hidden --column --line-number --no-heading --color=always --smart-case "
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-01-31 18:31:31 +01:00
file="$(echo $res | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g')"
row="$(echo $res | cut -d':' -f2)"
column="$(echo $res | cut -d':' -f3)"
if [ -n "$res" ]; then
2024-02-01 00:33:30 +01:00
lf -remote "send $id select '$file'"
if [ -n "$VIM" ]; then
lf -remote "send $id open '$file'"
elsif [ "$EDITOR" = "nvim" ] || [ "$EDITOR" = "vim" ]; then
2024-01-31 18:31:31 +01:00
lf -remote "send $id \$$EDITOR '$file' +'call cursor($row, $column)'"
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"
lf -remote "send $id set previewer ~/.config/lf/preview/sixel"
lf -remote "send $id reload"
echo 'Previewer set to sixel'
elif [ "${1}" = "ueberzug" ]; then
lf -remote "send $id set cleaner ~/.config/lf/preview/clean"
lf -remote "send $id set previewer ~/.config/lf/preview/ueberzug"
lf -remote "send $id reload"
echo 'Previewer set to ueberzug'
else
lf -remote "send $id set previewer ~/.config/lf/preview/chafa"
lf -remote "send $id reload"
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 &{{
mapcmd='map q $tmux'
previewercmd="set_previewer $(basename "$lf_previewer")"
$TERMINAL -e lf -command "${previewercmd}; ${mapcmd}"
}}
2024-01-29 20:46:03 +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
2024-02-01 00:33:30 +01:00
map <c-v> pushedit
2022-07-04 21:36:33 +02:00
map <c-n> push :mkdir<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-01 00:33:30 +01:00
map e edit
2023-11-22 10:21:14 +01:00
map E $sudo -e $f
2022-10-21 17:52:11 +02:00
# Load bookmark shortcuts
source "~/.config/lf/shortcutrc"