1
0
Fork 0

update lfrc and lfwrap widget

This commit is contained in:
Luca Bilke 2023-11-24 16:00:50 +01:00
parent a3e6c33cdc
commit 724dd5d1b7
2 changed files with 31 additions and 61 deletions

View File

@ -21,6 +21,16 @@ cmd open ${{
cmd mkdir $mkdir -p "$(echo $* | tr ' ' '\ ')"
cmd lazygit ${{
clear
if [ ! -e "$PWD/.git" ]; then
echo "Not in a git repository. Create a new git repository? (y/n): "
[ $(echo "Yes\nNo" | fzf) = "Yes" ] && git init && lazygit -p $PWD
else
lazygit -p $PWD
fi
}}
cmd dupe %{{
for file in $fx; do
find "$PWD" "$file" -maxdepth 0 | grep -oP '(?<=.\.~)\d+(?=~$)' | sort -n | tail -1 | (
@ -31,34 +41,6 @@ cmd dupe %{{
done
}}
cmd edit ${{
clear
if [ -w $f ]; then
$EDITOR $f
else
sudo -e $f
fi
clear
}}
cmd extract ${{
clear; tput cup $(($(tput lines)/3)); tput bold
set -f
printf "%s\n\t" "$fx"
printf "extract?[y/N]"
read ans
[ $ans = "y" ] && aunpack $fx
}}
cmd delete ${{
clear; tput cup $(($(tput lines)/3)); tput bold
set -f
printf "%s\n\t" "$fx"
printf "delete?[y/N]"
read ans
[ $ans = "y" ] && rm -rf -- $fx
}}
cmd trash ${{
clear; tput cup $(($(tput lines)/3)); tput bold
set -f
@ -87,7 +69,7 @@ cmd rsyncto ${{
# y (select for copy) and P to paste soft-link
# d (select for cut) and P to paste hard-link
cmd link %{{
cmd link &{{
set -- $(cat ~/.local/share/lf/files)
mode="$1"
shift
@ -175,12 +157,12 @@ map <c-c>m fzfmarks
map <c-c>f fzfshortcut
map <c-c>g fzfgrep
map D trash
map <c-d> delete
map T $trash-restore $PWD
map <c-e> extract
map <c-d> $trash-restore $PWD
map T &rm -rf -- $fx
map <c-e> $aunpack $fx
map R rsyncto
map P link
map <c-g> $lazygit
map <c-g> lazygit
map <c-v> push :!$EDITOR<space>
map <c-n> push :mkdir<space>
map <c-t> push :&touch<space>
@ -200,10 +182,9 @@ map b dupe
map u :clear; unselect
map n &echo $f | xclip -r -selection c
map <esc> quit
map N
map g/ cd "/"
map W &setsid $TERMINAL -e $SHELL -c "lf; $SHELL"
map e edit
map e $$EDITOR $f
map E $sudo -e $f
# Load bookmark shortcuts
source "~/.config/lf/shortcutrc"

View File

@ -63,34 +63,23 @@ function write_title_wd() { echo -ne "\033]0;$(print -P "%n@%m [%3~]")\007" }
add-zsh-hook precmd write_title_wd
# Use lf to switch directories and bind it to ctrl-o
lfwrap () {
tmp="$(mktemp)"
fid="$(mktemp)"
lf -command '$printf $id > '"$fid"'' -last-dir-path="$tmp" "$@"
id="$(cat "$fid")"
archivemount_dir="/tmp/__lf_archivemount_$id"
if [ -f "$archivemount_dir" ]; then
cat "$archivemount_dir" | \
while read -r line; do
sudo umount "$line"
rmdir "$line"
done
command rm -f "$archivemount_dir"
function lfwrap () {
LF_DIRFILE="/tmp/lfdir.$(uuidgen)"
lfub -last-dir-path="$LF_DIRFILE"
dir="$(cat "$LF_DIRFILE")"
rm "$LF_DIRFILE"
if [ -d "$dir" ]; then
if [ "$dir" != "$(pwd)" ]; then
cd "$dir"
fi
fi
if [ -f "$tmp" ]; then
dir="$(cat "$tmp")"
command rm -f "$tmp"
[ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir"
fi
tput cuu1;tput el
zle reset-prompt
zle redisplay
write_title_wd
reset_beam
}
_lf () {
BUFFER="lfwrap"
zle accept-line
}
zle -N _lf
bindkey '^e' _lf
zle -N lfwrap
# bind lazygit to ctrl-g
lg () {