wheeeeee lf

This commit is contained in:
_N0x 2024-01-14 23:14:39 +01:00
parent fc00db05bf
commit a4a1cb0242
3 changed files with 55 additions and 24 deletions

View File

@ -41,5 +41,5 @@ image/png=nsxiv.desktop
image/jpg=nsxiv.desktop
application/json=codium.desktop
application/xml=codium.desktop
inode/directory=pcmanfm.desktop
inode/directory=file.desktop;pcmanfm.desktop
text/plain=codium.desktop

View File

@ -0,0 +1,18 @@
# Change working dir in fish to last dir in lf on exit (adapted from ranger).
#
# You may put this file to a directory in $fish_function_path variable:
#
# mkdir -p ~/.config/fish/functions
# ln -s "/path/to/lfcd.fish" ~/.config/fish/functions
#
# You may also like to assign a key (Ctrl-O) to this command:
#
# bind \co 'set old_tty (stty -g); stty sane; lfcd; stty $old_tty; commandline -f repaint'
#
# You may put this in a function called fish_user_key_bindings.
function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)"
# `command` is needed in case `lfcd` is aliased to `lf`.
# Quotes will cause `cd` to not change directory if `lf` prints nothing to stdout due to an error.
cd "$(command lf -print-last-dir $argv)"
end

View File

@ -14,7 +14,7 @@ cmd edit-config ${{
cmd open ${{
switch $(file --mime-type "$(readlink -f $f)" -b)
case image/vnd.djvu application/pdf application/octet-stream application/postscript
case image/vnd.djvu application/pdf application/octet-stream application/postscript application/pdf application/vnd.djvu "application/epub*"
setsid -f zathura $fx >/dev/null 2>&1
case "text/*" application/json inode/x-empty application/x-subrip
$EDITOR $fx
@ -22,49 +22,62 @@ cmd open ${{
setsid -f gimp $f >/dev/null 2>&1
case image/svg+xml
display -- $f
#case "image/*"
# rotdir $f | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|avif\|tif\|ico\)\(_large\)*$" |
# setsid -f nsxiv -aio 2>/dev/null |
# while read -r file [ -z "$file" ] && continue; lf -remote "send select \"$file\""; lf -remote "send toggle"; end
case "image/*"
rotdir $f | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|avif\|tif\|ico\)\(_large\)*\$" |
setsid -f nsxiv -aio 2>/dev/null |
while read -r file;
[ -z "$file" ] && continue;
lf -remote "send select \"$file\"";
lf -remote "send toggle";
end
case "audio/*" video/x-ms-asf
mpv --volume=45 --audio-display=no $f
case "video/*"
setsid -f mpv --volume=45 $f -quiet >/dev/null 2>&1
case application/pdf application/vnd.djvu "application/epub*"
setsid -f zathura $fx >/dev/null 2>&1
case application/pgp-encrypted
$EDITOR $fx
case application/vnd.openxmlformats-officedocument.wordprocessingml.document application/vnd.oasis.opendocument.text application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/octet-stream application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.spreadsheet-template application/vnd.openxmlformats-officedocument.presentationml.presentation application/vnd.oasis.opendocument.presentation-template application/vnd.oasis.opendocument.presentation application/vnd.ms-powerpoint application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.graphics-template application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.database
setsid -f libreoffice $fx >/dev/null 2>&1
case "*"
for f in $fx; do setsid -f $OPENER $f >/dev/null 2>&1; done
for f in $fx
setsid -f $OPENER $f >/dev/null 2>&1
end
end
}}
cmd bulkrename ${{
tmpfile_old="$(mktemp)"
tmpfile_new="$(mktemp)"
set tmpfile_old (mktemp)
set tmpfile_new (mktemp)
[ -n "$fs" ] && fs=$(basename -a $fs) || fs=$(ls)
if test -n "$fs"
set fs (basename -a $fs)
else
set fs (ls)
end
echo "$fs" > "$tmpfile_old"
echo "$fs" > "$tmpfile_new"
$EDITOR "$tmpfile_new"
[ "$(wc -l < "$tmpfile_old")" -eq "$(wc -l < "$tmpfile_new")" ] || { rm -f "$tmpfile_old" "$tmpfile_new"; exit 1; }
paste "$tmpfile_old" "$tmpfile_new" | while IFS="$(printf '\t')" read -r src dst
do
[ "$src" = "$dst" ] || [ -e "$dst" ] || mv -- "$src" "$dst"
done
if test (wc -l < "$tmpfile_old") -eq (wc -l < "$tmpfile_new")
paste "$tmpfile_old" "$tmpfile_new" | while IFS="$(printf '\t')" read -r src dst
if test "$src" = "$dst" -o -e "$dst"
mv -- "$src" "$dst"
end
end
else
rm -f "$tmpfile_old" "$tmpfile_new"
exit 1
end
rm -f "$tmpfile_old" "$tmpfile_new"
lf -remote "send $id unselect"
}}
cmd move-parent &{{
dironly="setlocal '$(dirname "$PWD")' dironly"
lf -remote "send $id :updir; $dironly true; $1; $dironly false; open"
set dironly "setlocal (dirname "$PWD") dironly"
lf -remote "send $id :updir; $dironly true; $argv; $dironly false; open"
}}
### Mappings and stuff ###