1
0
Fork 0

update lfrc and lfwrap widget

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

View file

@ -21,6 +21,16 @@ cmd open ${{
cmd mkdir $mkdir -p "$(echo $* | tr ' ' '\ ')" 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 %{{ cmd dupe %{{
for file in $fx; do for file in $fx; do
find "$PWD" "$file" -maxdepth 0 | grep -oP '(?<=.\.~)\d+(?=~$)' | sort -n | tail -1 | ( find "$PWD" "$file" -maxdepth 0 | grep -oP '(?<=.\.~)\d+(?=~$)' | sort -n | tail -1 | (
@ -31,34 +41,6 @@ cmd dupe %{{
done 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 ${{ cmd trash ${{
clear; tput cup $(($(tput lines)/3)); tput bold clear; tput cup $(($(tput lines)/3)); tput bold
set -f set -f
@ -87,7 +69,7 @@ cmd rsyncto ${{
# y (select for copy) and P to paste soft-link # y (select for copy) and P to paste soft-link
# d (select for cut) and P to paste hard-link # d (select for cut) and P to paste hard-link
cmd link %{{ cmd link &{{
set -- $(cat ~/.local/share/lf/files) set -- $(cat ~/.local/share/lf/files)
mode="$1" mode="$1"
shift shift
@ -175,12 +157,12 @@ map <c-c>m fzfmarks
map <c-c>f fzfshortcut map <c-c>f fzfshortcut
map <c-c>g fzfgrep map <c-c>g fzfgrep
map D trash map D trash
map <c-d> delete map <c-d> $trash-restore $PWD
map T $trash-restore $PWD map T &rm -rf -- $fx
map <c-e> extract map <c-e> $aunpack $fx
map R rsyncto map R rsyncto
map P link map P link
map <c-g> $lazygit map <c-g> lazygit
map <c-v> push :!$EDITOR<space> map <c-v> push :!$EDITOR<space>
map <c-n> push :mkdir<space> map <c-n> push :mkdir<space>
map <c-t> push :&touch<space> map <c-t> push :&touch<space>
@ -200,10 +182,9 @@ map b dupe
map u :clear; unselect map u :clear; unselect
map n &echo $f | xclip -r -selection c map n &echo $f | xclip -r -selection c
map <esc> quit map <esc> quit
map N
map g/ cd "/" map g/ cd "/"
map W &setsid $TERMINAL -e $SHELL -c "lf; $SHELL" map e $$EDITOR $f
map e edit map E $sudo -e $f
# Load bookmark shortcuts # Load bookmark shortcuts
source "~/.config/lf/shortcutrc" 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 add-zsh-hook precmd write_title_wd
# Use lf to switch directories and bind it to ctrl-o # Use lf to switch directories and bind it to ctrl-o
lfwrap () { function lfwrap () {
tmp="$(mktemp)" LF_DIRFILE="/tmp/lfdir.$(uuidgen)"
fid="$(mktemp)" lfub -last-dir-path="$LF_DIRFILE"
lf -command '$printf $id > '"$fid"'' -last-dir-path="$tmp" "$@" dir="$(cat "$LF_DIRFILE")"
id="$(cat "$fid")" rm "$LF_DIRFILE"
archivemount_dir="/tmp/__lf_archivemount_$id" if [ -d "$dir" ]; then
if [ -f "$archivemount_dir" ]; then if [ "$dir" != "$(pwd)" ]; then
cat "$archivemount_dir" | \ cd "$dir"
while read -r line; do fi
sudo umount "$line"
rmdir "$line"
done
command rm -f "$archivemount_dir"
fi fi
if [ -f "$tmp" ]; then zle reset-prompt
dir="$(cat "$tmp")" zle redisplay
command rm -f "$tmp" write_title_wd
[ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir" reset_beam
fi
tput cuu1;tput el
} }
_lf () { zle -N lfwrap
BUFFER="lfwrap"
zle accept-line
}
zle -N _lf
bindkey '^e' _lf
# bind lazygit to ctrl-g # bind lazygit to ctrl-g
lg () { lg () {