lf config

This commit is contained in:
Tristan 2024-01-06 00:16:18 +00:00
parent f3685dcbf5
commit 026035fe52
2 changed files with 41 additions and 38 deletions

View file

@ -1,26 +1,34 @@
{pkgs, ...}: let {pkgs, ...}: let
readScript = path: '' ''${{ readScript = path: ''
${builtins.readFile path} ''${{
}}''; ${builtins.readFile path}
}}'';
in { in {
home.packages = with pkgs; [ home.packages = with pkgs; [
# previewer # previewer
## get file type
file
## convert to sixels
chafa chafa
## get file info
exiftool exiftool
## pretty print text files
bat bat
## format json
jq
## get thumbnails from videos
ffmpegthumbnailer ffmpegthumbnailer
# commands
## trash utility
trash-cli trash-cli
imagemagick
gnumeric
poppler_utils
odt2txt
python311Packages.docx2txt
catdoc
libcdio
p7zip
file
gnome-epub-thumbnailer
]; ];
programs.lf.enable = true; programs.lf.enable = true;
@ -37,12 +45,13 @@ in {
drag = "%${pkgs.ripdrag}/bin/ripdrag -x \"$fx\""; drag = "%${pkgs.ripdrag}/bin/ripdrag -x \"$fx\"";
trash = "%trash-put \"$fx\""; trash = "%trash-put \"$fx\"";
open = "$set -f; ${pkgs.ranger}/bin/rifle -p 0 \"$fx\""; open = "$set -f; ${pkgs.ranger}/bin/rifle -p 0 \"$fx\"";
open-with = '' ''${{ open-with = ''
set -f ''${{
${pkgs.ranger}/bin/rifle -l "$fx" set -f
read -p "Open with: " method ${pkgs.ranger}/bin/rifle -l "$fx"
${pkgs.ranger}/bin/rifle -p "$method" "$fx" read -p "Open with: " method
}}''; ${pkgs.ranger}/bin/rifle -p "$method" "$fx"
}}'';
bulk-rename = readScript ./bulk-rename.sh; bulk-rename = readScript ./bulk-rename.sh;
}; };
programs.lf.previewer.source = ./preview.sh; programs.lf.previewer.source = ./preview.sh;

View file

@ -1,6 +1,9 @@
#!/bin/sh #!/bin/sh
HASH=$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$1")" | md5sum $1 | cut -f 1 -d " ") file=${1}
HASH=$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$(readlink -f "$file")" \
| md5sum | cut -f 1 -d " ")-${2}x${3}
CACHEDIR=/tmp/lf/thumbnail/ CACHEDIR=/tmp/lf/thumbnail/
mkdir -p $CACHEDIR mkdir -p $CACHEDIR
@ -10,20 +13,23 @@ image () {
[ ! -f "$CACHE" ] && \ [ ! -f "$CACHE" ] && \
chafa -f sixel -s "$2x$3" --animate off --polite on "$1" > "$CACHE" chafa -f sixel -s "$2x$3" --animate off --polite on "$1" > "$CACHE"
cat "$CACHE" cat "$CACHE"
exit 1
} }
case "$(file -Lb --mime-type -- "$1")" in case "$(file -Lb --mime-type -- "$file")" in
image/*) image/*)
image $@ image $@
exit 1 ;;
application/json)
jq '.' "$1" | bat --color always -l json --file-name $file
;; ;;
text/*) text/*)
bat "$1" bat --color always "$file"
;; ;;
application/pdf) application/pdf)
[ ! -f "$CACHE.jpeg" ] && \ [ ! -f "$CACHE.jpg" ] && \
pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE.jpeg" pdftoppm -jpeg -f 1 -singlefile "$file" "$CACHE"
image "$CACHE.jpeg" "$2" "$3" "$4" "$5" image "$CACHE.jpg" "$2" "$3" "$4" "$5"
;; ;;
*) *)
exiftool "$1" exiftool "$1"
@ -47,18 +53,9 @@ case "$(printf "%s\n" "$(readlink -f "$1")" | awk '{print tolower($0)}')" in
*.odt|*.ods|*.odp|*.sxw) odt2txt "$1" ;; *.odt|*.ods|*.odp|*.sxw) odt2txt "$1" ;;
*.doc) catdoc "$1" ;; *.doc) catdoc "$1" ;;
*.docx) docx2txt "$1" - ;; *.docx) docx2txt "$1" - ;;
*.xml|*.html) w3m -dump "$1";;
*.xls|*.xlsx) *.xls|*.xlsx)
ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1" ssconvert --export-type=Gnumeric_stf:stf_csv "$1" "fd://1"
;; ;;
*.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx]|*.mka)
exiftool "$1"
;;
*.pdf)
[ ! -f "$CACHE.jpg" ] && \
pdftoppm -jpeg -f 1 -singlefile "$1" "$CACHE"
image "$CACHE.jpg" "$2" "$3" "$4" "$5"
;;
*.epub) *.epub)
[ ! -f "$CACHE" ] && \ [ ! -f "$CACHE" ] && \
epub-thumbnailer "$1" "$CACHE" 1024 epub-thumbnailer "$1" "$CACHE" 1024
@ -69,9 +66,6 @@ case "$(printf "%s\n" "$(readlink -f "$1")" | awk '{print tolower($0)}')" in
ffmpegthumbnailer -i "$1" -o "$CACHE.jpg" -s 0 -q 5 ffmpegthumbnailer -i "$1" -o "$CACHE.jpg" -s 0 -q 5
image "$CACHE.jpg" "$2" "$3" "$4" "$5" image "$CACHE.jpg" "$2" "$3" "$4" "$5"
;; ;;
*.bmp|*.jpg|*.jpeg|*.png|*.xpm|*.webp|*.jfif)
image "$1" "$2" "$3" "$4" "$5"
;;
*.svg) *.svg)
[ ! -f "$CACHE.jpg" ] && \ [ ! -f "$CACHE.jpg" ] && \
convert "$1" "$CACHE.jpg" convert "$1" "$CACHE.jpg"