dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.config/lf/lfrc

287 lines
6.8 KiB
Plaintext

# Basic Settings
set shell zsh
set shellopts '-eu:--shwordsplit'
set ifs "\n"
set scrolloff 5
set previewer ~/.config/lf/lf-preview
set wrapscroll
set sortby time
set info size:time
set reverse
set incsearch
set color256
set icons
%{{
w=$(tput cols)
if [ $w -le 80 ]; then
lf -remote "send $id set ratios 1:1"
elif [ $w -le 160 ]; then
lf -remote "send $id set ratios 1:2:2"
else
lf -remote "send $id set ratios 1:3:2"
fi
}}
# Custom Functions
cmd open ${{
case $(file --mime-type $f -bL) in
text/troff) man ./ $f;;
text/*) $EDITOR $fx;;
image/x-xcf|image/svg+xml) setsid gimp $f >/dev/null 2>&1 & ;;
image/gif) setsid sxiv-gif $f 2>/dev/null & ;;
image/*) setsid sxiv-rifle $f 2>/dev/null & ;;
audio/*) mpv --input-ipc-server=/tmp/mpvsoc$(date +%%s) $f ;;
video/*) setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%%s) $f -quiet >/dev/null 2>&1 & ;;
application/pdf|application/cbz|application/cbr) setsid zathura $fx >/dev/null 2>&1 & ;;
*) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
esac
}}
cmd bulkrename ${{
old=$(mktemp)
new=$(mktemp)
[ -n $fs ] && fs=$(ls)
printf "$fs\n" > $old
printf "$fs\n" > $new
$EDITOR $new
[ $(cat $new | wc -l) -ne $(cat $old | wc -l) ] && exit
paste $old $new | while read names; do
src=$(printf $names | cut -f1)
dst=$(printf $names | cut -f2)
[ $src = $dst ] && continue
[ -e $dst ] && continue
mv $src $dst
done
rm $old $new
lf -remote "send $id unselect"
}}
# insert
cmd rename-insert &{{
if [ "$(echo "$fx" | wc -l)" -gt 1 ]; then
lf -remote "send $id echo You can't change more than one file name"
lf -remote "send $id unselect"
else
len="$(basename "$f" | wc -m)" # length of selected file/directory
for i in $(seq "$len"); do
pos="${pos}<left>" # how many times do I have to press <left> in order to get first char
done
lf -remote "send $id rename"
lf -remote "send $id push $pos"
fi
}}
# append before ext
cmd rename-before-ext &{{
if [ "$(echo "$fx" | wc -l)" -gt 1 ]; then
lf -remote "send $id echo You can't change more than one file name"
lf -remote "send $id unselect"
else
if [ -d "$f" ]; then
lf -remote "send $id rename"
else
ext_len="$(echo ${f##*.} | wc -m)" # extention length
for i in $(seq "$ext_len"); do
pos="${pos}<left>"
done
lf -remote "send $id rename"
lf -remote "send $id push "$pos""
fi
fi
}}
# change its name entirely
cmd rename-new &{{
if [ "$(echo "$fx" | wc -l)" -gt 1 ]; then
lf -remote "send $id echo You can't change more than one file name"
lf -remote "send $id unselect"
else
lf -remote "send $id rename"
lf -remote "send $id push <c-u>"
fi
}}
cmd moveto ${{
set -f
clear; echo "Move to where?"
dest="$(cut -d' ' -f2- ~/.config/directories | fzf)" &&
eval mv -iv $fx $dest &&
notify-send "File(s) moved to $dest."
}}
cmd copyto ${{
set -f
clear; echo "Copy to where?"
dest="$(cut -d' ' -f2- ~/.config/directories | fzf)" &&
eval cp -ivr $fx $dest &&
notify-send "File(s) copies to $dest."
}}
cmd paste ${{
send="while read -r line; do lf -remote \"send $id echo \$line\"; done && lf -remote 'send reload'"
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
s='' && [ ! -w . ] && s='sudo'
case "$mode" in
copy) cmd='cp-p';; move) cmd='mv-p';;
esac
cmd="$cmd --new-line"
for f in $list; do
$s sh -c "$cmd --backup=numbered \"$f\" . | $send &"
done
lf -remote 'send load'
lf -remote 'send clear'
}}
cmd paste-rsync &{{
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy']; then
rsync -av --ignore-existing --progress $list . \
| stdbuf -i0 -o0 -e0 tr '\r' '\n' \
| while read line; do
lf -remote "send $id echo $line"
done
elif [ $mode = 'move' ]; then
mv -n $list .
fi
lf -remote 'send load'
lf -remote 'send clear'
}}
cmd fzf_jump ${{
res="$(find . -maxdepth 3 | fzf-tmux --reverse --header='Jump to location')"
if [ -f "$res" ]; then
cmd="select"
elif [ -d "$res" ]; then
cmd="cd"
fi
lf -remote "send $id $cmd \"$res\""
}}
cmd broot_jump ${{
f=$(mktemp)
res="$(broot --outcmd $f && cat $f | sed 's/cd //')"
rm -f "$f"
if [ -f "$res" ]; then
cmd="select"
elif [ -d "$res" ]; then
cmd="cd"
fi
lf -remote "send $id $cmd \"$res\""
}}
cmd Link %{{
lf -remote 'load' | while read file; do
if [ ! -n "${mode+1}" ]; then
mode="$file"
continue
fi
files+=("$file")
done
if [ "${#files[@]}" -le 1 ]; then
lf -remote "send $id echo no files to link"
exit 0
fi
# symbolicly copy mode is indicating a soft link
if [[ "$mode" == copy ]]; then
ln -sr $files -t .
# while a move mode is indicating a hard link
elif [[ "$mode" == move ]]; then
ln $files -t .
fi
}}
cmd nopreview &{{
lf -remote "send $id set nopreview"
lf -remote "send $id set ratios 1:3" # or whatever
}}
# Bindings
# Remove some defaults
map m
map n
map "'"
map '"'
map d
map p
map w
map y
map c
map u
map e
map /
cmap <esc> cmd-escape
map | top
map ¿ bottom
map <f-2> push A<c-u>
map <f-3> cut
map <f-4> copy
map <f-5> reload
map <f-6> push $touch<space>
map <f-7> push $mkdir<space>
map <f-8> delete
map <f-9> paste
map <enter> open
map <delete> delete
map yy copy
map yn $basename -z $f | xsel -i -b
map yp $readlink -fn $f | xsel -i -b
map Y %cp -ri $fs .
map dd cut
map D %mv -i $fs .
map pp paste
map pr paste-rsync
map . set hidden!
map uu unselect
map uy clear
map S shell
map cc push A<c-u> # new rename
map I push A<c-a> # at the very beginning
map A rename # at the very end
map i push A<a-b><c-b>. # before extension
map a push A<a-b> # after extension
map B bulkrename
map P :Link
map f broot_jump
map <tab> $lf -remote "send $id select '$(fzf)'"
map / $lf -remote "send $id select \"$(FZF_DEFAULT_COMMAND='fd --max-depth=1' fzf-tmux)\""
map F $find | lf -remote "send $id select $(fzf-tmux --height 50% --reverse --border --margin 5% --inline-info --color border:#005688,bg+:#16252E,fg+:#26c6da,hl+:#ffffff,hl:#26c6da)"
map cx %chmod +x $f
map bg $setbg $f
map o open $f
map u %du -sh $f
# Movement
map gu cd ~/Documents/
map gE cd /etc
map gU cd /usr
map gd cd ~/Downloads
map g. cd ~/.config
map gs cd ~/.local/share
map gr cd /run/media/deadguy
map gm cd /mnt/remote
map gc cd /mnt/cel
map gb cd ~/.local/bin
map gR cd /
map gv cd ~/Videos/Learning
map gp cd ~/Pictures
map cg $$EDITOR ~/.config/lf/lfrc