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

320 lines
8.5 KiB
Plaintext
Raw Normal View History

2024-04-09 18:25:23 +02:00
# Functions
cmd open ${{
set +u
2024-03-06 17:50:10 +01:00
files=${@:-$fx}
2024-02-22 16:34:43 +01:00
[ "$lf_user_multiedit" = "true" ] && {
2024-04-10 23:10:24 +02:00
$EDITOR $fx
lf -remote "send $id unselect"
return
2024-02-22 16:34:43 +01:00
}
$OPENER "$f"
2024-02-01 00:33:30 +01:00
}}
cmd pushedit %{{
2024-02-22 16:34:43 +01:00
set +u
2024-03-04 10:06:53 +01:00
files=$1
[ -z $files ] && {
2024-03-06 17:50:10 +01:00
echo "Open: " && read -r files
2024-03-04 10:06:53 +01:00
echo
}
2024-02-22 16:34:43 +01:00
echo $files | xargs -r touch
2024-04-10 23:10:24 +02:00
lf -remote "send $id \$$OPENER $files"
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 &{{
2024-05-02 19:43:30 +02:00
trash-cli put $fx
2024-02-01 00:33:30 +01:00
lf -remote "send load"
2022-07-07 16:23:55 +02:00
}}
2024-05-02 19:43:30 +02:00
cmd trash-restore ${{
fileid=$(
trash-cli list "$PWD" |
fzf -d '\0' \
--with-nth=1 \
--nth=1 \
--preview='printf "Original path: %s\nInfo path: %s\nTrashed on: %s\n" {1} {2} {3}' |
cut -d '' -f 2
)
[ -z "$fileid" ] && exit
trash-cli restore $fileid
}}
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
}}
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
copy) ln -sr -t . -- "$@";;
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-03-13 17:44:20 +01:00
lf -remote "send $id set promptfmt \"$(zsh -c 'source $ZDOTDIR/configs/prompt; source $ZDOTDIR/configs/hashes; print -P $LF_PROMPT')\""
printf "%b" "\033]0;$(zsh -c 'source $ZDOTDIR/configs/prompt; source $ZDOTDIR/configs/hashes; print -P $LF_TITLE')\007" > /dev/tty
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
2024-02-28 02:44:43 +01:00
copy)
rsync -aP --del -- "$@" . &
i=0
while ps -p "$!" >/dev/null; do
i=$(((i + 1) % 3))
dots=""
for i in $(seq 0 $i); do
dots="${dots}."
2023-11-17 11:12:50 +01:00
done
2024-02-28 02:44:43 +01:00
lf -remote "send $id echo 'Copying$dots'"
sleep 0.3
done
;;
move) mv -n -- "$@" . ;;
2022-09-15 20:27:44 +02:00
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
}}
2024-03-20 11:53:22 +01:00
cmd fzf ${{
2024-03-20 12:17:15 +01:00
name="$1" input="$2" delimiter="$3" field="$4" path_field="$5" width="$6" query="${7:-}"
histfile="$XDG_DATA_HOME/lf/$(echo $name | tr '[:upper:]' '[:lower:]')_history"
2024-03-20 11:53:22 +01:00
2024-03-19 22:39:41 +01:00
clear
2024-03-20 11:53:22 +01:00
file="$(eval "$input" | fzf \
--query "$query" \
--delimiter "$delimiter" \
--cycle \
2024-03-20 12:17:15 +01:00
--nth="$field" \
--with-nth="$field" \
2024-03-20 11:53:22 +01:00
--preview-window="right,$width" \
2024-03-20 14:28:39 +01:00
--bind="space:accept,focus:transform-preview-label(echo {} | cut -d '$delimiter' -f '$path_field')" \
2024-03-20 11:53:22 +01:00
--scheme='history' \
--history="$histfile" \
--header="$name" \
--preview='
2024-03-20 12:17:15 +01:00
file=$(echo {} | cut -d '$delimiter' -f '$path_field')
2024-03-19 22:39:41 +01:00
if [ -f "$file" ] && [ -r "$file" ]; then
head -$LINES "$file"
elif [ -d "$file" ] && [ -r "$file" ]; then
2024-03-20 11:53:22 +01:00
ls -pLHAN1 --color=always --group-directories-first "$file"
2024-03-19 22:39:41 +01:00
fi
2024-03-20 11:53:22 +01:00
' |
2024-03-20 12:17:15 +01:00
cut -d "$delimiter" -f "$path_field" |
2024-03-19 22:39:41 +01:00
tr -d '\n'
)"
2024-03-20 12:17:15 +01:00
[ -d "$file" ] && lf -remote "send $id cd $file"
2024-03-20 11:53:22 +01:00
[ -f "$file" ] && lf -remote "send $id select $file"
2024-03-20 12:17:15 +01:00
return 0
2023-03-21 19:21:46 +01:00
}}
2024-03-20 11:53:22 +01:00
2024-03-19 22:39:41 +01:00
cmd find_word ${{
2024-02-01 20:17:42 +01:00
set +ue
2024-03-07 05:26:34 +01:00
RG_PREFIX="rg --hidden --column --line-number --no-heading --color=always --smart-case --follow --no-ignore "
2023-06-15 17:27:56 +02:00
res="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX ''" \
2024-03-19 22:39:41 +01:00
fzf --bind "change:reload:$RG_PREFIX {q} || true" \
--ansi --layout=reverse --header 'Searching file contents' |\
grep -iv -e 'Trash/files' -e 'Trash/info'
2023-06-15 17:27:56 +02:00
)"
2024-02-28 12:43:06 +01:00
file="$(realpath "$(echo "$res" | cut -d':' -f1 | sed 's/\\/\\\\/g;s/"/\\"/g')" 2>/dev/null)"
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-04-10 23:10:24 +02:00
if { [ "$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
2024-03-20 12:17:15 +01:00
return 0
2023-06-15 17:27:56 +02:00
}}
2024-01-29 20:46:03 +01:00
2024-04-05 21:43:47 +02:00
cmd find_project ${{
dirs=$(echo $XDG_DOCUMENTS_DIR/dev/*/*)
histfile="$XDG_DATA_HOME/lf/project_history"
clear
project="$(echo $dirs | xargs -n1 basename | fzf \
--cycle \
--preview-window="right,33%" \
--bind="space:accept,focus:transform-preview-label(echo {})" \
--scheme='history' \
--history="$histfile" \
--header="Projects" \
--preview='
f={}
file=$(echo $XDG_DOCUMENTS_DIR/dev/*/* | xargs -n1 | sed -n "/\/$f$/p")
if [ -f "$file" ] && [ -r "$file" ]; then
head -$LINES "$file"
elif [ -d "$file" ] && [ -r "$file" ]; then
ls -pLHAN1 --color=always --group-directories-first "$file"
fi
' |
tr -d '\n'
)"
file=$(echo $dirs | xargs -n1 | sed -n "/\/$project$/p")
[ -d "$file" ] && lf -remote "send $id cd $file"
[ -f "$file" ] && lf -remote "send $id select $file"
return 0
}}
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-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"'
$TERMINAL -e lfX -command "$mapcmd"
2024-01-31 00:55:55 +01:00
}}
2024-01-29 20:46:03 +01:00
2024-05-15 17:58:35 +02:00
cmd confirm_delete %{{
echo Delete? [y/N] && read -r v
echo
[ "$v" = y ] && rm -rf -- $fx
}}
2024-02-22 14:45:42 +01:00
on-cd
2024-02-01 20:34:38 +01:00
2024-04-09 18:25:23 +02:00
# Basic vars
set ratios 1:2:5
set shellopts '-eu'
set ifs "\n"
set findlen 1
set scrolloff 10
set icons
set wrapscroll
set period 1
set cursorpreviewfmt "\033[7;90m"
set promptfmt # this is set in a function later
2024-04-18 11:13:07 +02:00
set sixel
set previewer ~/.config/lf/preview/preview
2024-04-09 18:25:23 +02:00
set cleaner ~/.config/lf/preview/clean
2022-07-04 21:36:33 +02:00
# Bindings
2024-03-12 22:41:46 +01:00
clearmaps
map <esc> quit
map <space> :toggle; down
map <enter> shell
map <a-enter> shell-wait
2024-04-09 18:25:23 +02:00
map <tab><tab> find_project
2024-04-05 20:47:36 +02:00
map <tab>t fzf 'Tags' 'cat $XDG_DATA_HOME/lf/tags 2>/dev/null' ':' '1' '1' '50%'
map <tab>m fzf 'Marks' 'cat $XDG_DATA_HOME/lf/marks 2>/dev/null' ':' '1' '2' '85%' '^'
map <tab>f fzf 'Files' 'find -L $PWD' ':' '1' '1' '50%'
2024-04-05 21:43:47 +02:00
map <tab>g find_word
2024-03-12 22:41:46 +01:00
map "'" mark-load
2024-03-20 11:54:06 +01:00
map '"' mark-remove
2024-03-12 22:41:46 +01:00
map "$" shell
map "!" shell-wait
map "&" shell-async
2024-05-15 17:58:35 +02:00
map "%" shell-pipe
2024-03-20 11:53:22 +01:00
map ";" find-next
map "," find-prev
map "/" search
2024-04-17 19:46:52 +02:00
map a :rename; cmd-end # rename from end
2024-03-12 22:41:46 +01:00
map <c-b> page-up
map b dupe
map B bulkrename
map <c-c> quit
map c push r<c-u> # new rename
2024-05-15 17:58:35 +02:00
map <c-d> confirm_delete
2024-03-13 12:34:16 +01:00
map d cut
2024-05-15 17:58:35 +02:00
map D &dragon-drop -a -x $fx
2024-03-12 22:41:46 +01:00
map <c-e> scroll-down
map e :set user_multiedit "true" ; open; set user_multiedit "false"
map E $sudo -e $f
map f find
map F find-back
2023-11-22 20:42:33 +01:00
map <c-g> lazygit
map <a-g> $gdu
2024-03-12 22:41:46 +01:00
map gg top
2024-03-27 17:23:20 +01:00
map g/ cd /
2024-04-09 18:25:23 +02:00
# NOTE: g* is used for shortcuts generated by the shortcuts script
source ~/.config/lf/shortcuts
2024-03-12 22:41:46 +01:00
map G bottom
map h updir
2024-04-17 19:46:52 +02:00
map i :rename; cmd-home # rename from beginning
2024-03-12 22:41:46 +01:00
map j down
map k up
map l open
map m mark-save
2024-02-08 17:04:57 +01:00
map <c-n> push :&mkdir<space>-p<space>
2024-03-12 22:41:46 +01:00
map n search-next
map N search-prev
2023-05-31 11:26:50 +02:00
map o open-with
2023-11-22 10:21:14 +01:00
map O $less $f
2024-03-12 22:41:46 +01:00
map p paste
map P link
map q quit
map <c-r> reload
map r :rename # before extension
map R $lf -remote "send $id :select \"$(readlink $f)\""
2024-03-19 22:39:41 +01:00
map sh :set hidden!
2024-03-12 22:41:46 +01:00
map sn :set sortby natural; set info
map ss :set sortby size; set info size
map st :set sortby time; set info time
map sa :set sortby atime; set info atime
map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info
2024-05-02 19:43:30 +02:00
map <c-t> trash-restore
2024-03-12 22:41:46 +01:00
map t tag-toggle
map T trash
2022-09-17 02:39:38 +02:00
map u :clear; unselect
2024-03-12 22:41:46 +01:00
map <c-v> pushedit
map v invert
2024-01-31 00:55:55 +01:00
map W new_lf_term
2024-03-12 22:41:46 +01:00
map x $$f
map X !$f
map <c-y> scroll-down
map y copy
map Y &echo $f | xclip -r -selection c
map zh set hidden!
map zr set reverse!
map zn set info
map zs set info size
map zt set info time
map za set info size:time