refactor(install\_software.sh): add support for lf previewer in the script and configure it

feat(install\_software.sh): install lf previewer and set it up as default previewer for various file types
[lf\_preview.sh]: new file: create a new script to handle file previews using lf previewer
This commit is contained in:
Digital Studium 2024-03-08 19:05:19 +03:00
parent fbfdde72ac
commit 93de6237de
2 changed files with 59 additions and 0 deletions

View File

@ -30,6 +30,21 @@ python3-pip `# pip` \
tensorrt-libs \ tensorrt-libs \
bat bat
# lf settings
sudo cp lf_preview.sh /usr/local/bin
cat << 'EOF' > lfrc
set previewer lf_preview.sh
cmd trash %set -f; mv $fx ~/.trash
map <delete> trash
map i $batcat --force-colorization $f
map x $$f
map o $mimeopen --ask $f
EOF
sudo mkdir /etc/lf
sudo cp lfrc /etc/lf
rm -f lfrc
if [ ! -f /etc/docker/daemon.json ] if [ ! -f /etc/docker/daemon.json ]
then then
sudo nvidia-ctk runtime configure --runtime=docker --set-as-default sudo nvidia-ctk runtime configure --runtime=docker --set-as-default

44
lf_preview.sh Executable file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env bash
MIME=$(mimetype --all --brief "$1")
#echo "$MIME"
case "$MIME" in
# .pdf
*application/pdf*)
pdftotext "$1" -
;;
# .jpeg
# *image/jpeg*)
# sxiv "$1"
# ;;
# .7z
*application/x-7z-compressed*)
7z l "$1"
;;
# .tar .tar.Z
*application/x-tar*)
tar -tvf "$1"
;;
# .tar.*
*application/x-compressed-tar*|*application/x-*-compressed-tar*)
tar -tvf "$1"
;;
# .rar
*application/vnd.rar*)
unrar l "$1"
;;
# .zip
*application/zip*)
unzip -l "$1"
;;
# any plain text file that doesn't have a specific handler
*text/plain*)
# return false to always repaint, in case terminal size changes
batcat --force-colorization --paging=never --style=changes,numbers \
--terminal-width $(($2 - 3)) "$1" && false
;;
*)
echo "unknown format"
;;
esac