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
|
2024-02-01 18:47:57 +01:00
|
|
|
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-03-06 17:50:10 +01:00
|
|
|
if [ -z "$TAOLF" ]; then
|
2024-02-22 16:34:43 +01:00
|
|
|
$EDITOR $fx
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
}
|
2024-02-01 18:47:57 +01:00
|
|
|
$OPENER "$f"
|
2024-02-01 00:33:30 +01:00
|
|
|
}}
|
|
|
|
|
2024-02-01 18:47:57 +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
|
|
|
|
if [ -n "$TAOLF" ]; then
|
2024-03-06 17:50:10 +01:00
|
|
|
set -- $files
|
2024-02-23 16:32:27 +01:00
|
|
|
lf -remote "send $id unselect
|
|
|
|
send $id toggle $files
|
2024-03-06 17:50:10 +01:00
|
|
|
send $id select $1
|
|
|
|
send $id open"
|
2024-02-23 16:32:27 +01:00
|
|
|
else
|
|
|
|
lf -remote "send $id \$$OPENER $files"
|
2024-02-22 16:34:43 +01:00
|
|
|
fi
|
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
|
|
|
|
|
2023-06-30 12:53:37 +02:00
|
|
|
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
|
|
|
}}
|
2022-08-01 14:30:07 +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"
|
|
|
|
}}
|
2022-07-31 13:15:03 +02:00
|
|
|
|
2023-11-22 10:21:14 +01:00
|
|
|
cmd dupe &{{
|
2023-05-29 22:20:46 +02:00
|
|
|
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
|
2022-10-22 16:35:03 +02:00
|
|
|
}}
|
|
|
|
|
2023-05-29 22:20:46 +02:00
|
|
|
# cmd share $curl -F"file=@$fx" https://0x0.snaile.de | xclip -r -selection c
|
2022-07-07 16:23:55 +02:00
|
|
|
|
2024-03-12 22:41:46 +01:00
|
|
|
# TODO: Move this to zsh config
|
2023-03-21 19:21:46 +01:00
|
|
|
cmd fzfsearch ${{
|
2024-03-18 22:42:48 +01:00
|
|
|
file="$(find -L $PWD | fzf --header='Searching Filenames' --preview='head -$LINES {} 2>/dev/null || ls -lhpAN --color=always --group-directories-first {}' || true)"
|
2024-03-12 22:41:46 +01:00
|
|
|
[ -z "$file" ] && return
|
2024-03-18 22:42:48 +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
|
|
|
}}
|
|
|
|
cmd fzftags ${{
|
2024-03-18 22:42:48 +01:00
|
|
|
file="$(cat $XDG_DATA_HOME/lf/tags | fzf --header='Searching Tags' | sed 's/:.$//' || true)"
|
2024-03-12 22:41:46 +01:00
|
|
|
[ -z "$file" ] && return
|
2024-03-18 22:42:48 +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
|
|
|
}}
|
|
|
|
cmd fzfmarks ${{
|
2024-03-18 22:42:48 +01:00
|
|
|
file="$(cat $XDG_DATA_HOME/lf/marks | fzf --header='Searching Marks' | cut -b 3- || true)"
|
2024-03-12 22:41:46 +01:00
|
|
|
[ -z "$file" ] && return
|
2024-03-18 22:42:48 +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-11-17 11:12:50 +01:00
|
|
|
cmd fzfshortcut ${{
|
2024-03-18 22:42:48 +01:00
|
|
|
file="$(cat $XDG_DATA_HOME/lf/dirs | fzf --header='Searching Shortcuts' --preview='echo '{}' | cut -f2 | xargs ls' | cut -f2 )"
|
2024-03-12 22:41:46 +01:00
|
|
|
[ -z "$file" ] && return
|
2024-03-18 22:42:48 +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
|
|
|
}}
|
2024-03-12 22:41:46 +01:00
|
|
|
# cmd fzfworkon ${{
|
|
|
|
# workon -n $(workon | fzf)
|
|
|
|
# }}
|
2023-06-15 17:27:56 +02:00
|
|
|
cmd fzfgrep ${{
|
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 ''" \
|
|
|
|
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-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-02-01 00:33:30 +01:00
|
|
|
if [ -n "$VIM" ]; then
|
2024-03-06 16:52:03 +01:00
|
|
|
lf -remote "send $id unselect
|
|
|
|
send $id cd "$(dirname $file)"
|
|
|
|
send $id set hidden
|
|
|
|
send $id select "$file"
|
|
|
|
send $id open
|
|
|
|
send $id unselect"
|
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
|
|
|
cmd set_previewer %{{
|
|
|
|
if [ "${1}" = "sixel" ]; then
|
2024-02-06 10:42:25 +01:00
|
|
|
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
|
2024-02-06 10:42:25 +01:00
|
|
|
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
|
2024-02-06 10:42:25 +01:00
|
|
|
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
|
2024-02-28 02:08:27 +01:00
|
|
|
# [ -n "$SCRATCHPAD" ] && previewer=sixel
|
2024-02-01 20:34:38 +01:00
|
|
|
[ -n "$TMUX" ] && previewer=ueberzug
|
|
|
|
[ -n "$VIM" ] && previewer=chafa
|
|
|
|
lf -remote "send $id set_previewer $previewer"
|
2024-03-06 15:34:19 +01:00
|
|
|
|
|
|
|
# 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"
|
2024-02-01 20:34:38 +01:00
|
|
|
}}
|
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
|
2024-03-12 22:41:46 +01:00
|
|
|
clearmaps
|
|
|
|
|
|
|
|
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 "'" mark-load
|
|
|
|
map '"' mark-save
|
|
|
|
map "$" shell
|
|
|
|
map "!" shell-wait
|
|
|
|
map "&" shell-async
|
|
|
|
map ; find-next
|
|
|
|
map , find-prev
|
|
|
|
map / search
|
|
|
|
map a :rename; cmd-home # rename from beginning
|
|
|
|
map <c-b> page-up
|
|
|
|
map b dupe
|
|
|
|
map B bulkrename
|
|
|
|
map <c-c> quit
|
|
|
|
map c push r<c-u> # new rename
|
2024-01-24 00:55:35 +01:00
|
|
|
map <c-d> &rm -rf -- $fx
|
2024-03-13 12:34:16 +01:00
|
|
|
map d cut
|
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
|
2024-02-01 18:47:57 +01:00
|
|
|
map <a-g> $gdu
|
2024-03-12 22:41:46 +01:00
|
|
|
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
|
|
|
|
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)\""
|
|
|
|
map <c-s> 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
|
|
|
|
map sa :set sortby atime; set info atime
|
|
|
|
map sc :set sortby ctime; set info ctime
|
|
|
|
map se :set sortby ext; set info
|
|
|
|
map <c-t> $trash-restore $PWD
|
|
|
|
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
|
2023-05-29 22:20:46 +02:00
|
|
|
|
2022-10-21 17:52:11 +02:00
|
|
|
# Load bookmark shortcuts
|
|
|
|
source "~/.config/lf/shortcutrc"
|