lf.scm (2178B)
1 (define-module (home lukejw lf) 2 #:use-module (guix gexp)) 3 4 (define* (mixed-executable-file name #:key guile #:rest text) 5 "This is the exact same as mixed-executable-file, except that it provides 6 executable permissions. Great for procedurally generating shell scripts." 7 (define build 8 (let ((text (if guile (drop text 2) text))) 9 (gexp (call-with-output-file (ungexp output "out") 10 (lambda (port) 11 (set-port-encoding! port "UTF-8") 12 (display (string-append (ungexp-splicing text)) port) 13 (chmod port #o555)))))) 14 15 (computed-file name build #:guile guile)) 16 17 ;; Previewer program for use with lf 18 ;; TODO: Convert to scheme program (this is terrible) 19 (define previewer (mixed-text-file "previewer" "\ 20 #!" dash "/bin/dash 21 case \"$(" file "/bin/file -Lb --mime-type -- \"$1\")\" in 22 # Preview images with sixel 23 image/*) 24 " chafa "/bin/chafa -f sixel --view-size \"$2x$3\" --animate off --polite on -t 1 --bg black \"$1\" 25 ;; 26 # Preview text files with formatting 27 text/*) 28 " coreutils "/bin/fold -w \"$2\" --spaces \"$1\" 29 ;; 30 # Preview videos by pulling and scaling the first frame to the correct size and subsequently converting it to sixel 31 video/*) 32 THUMB=\"/tmp/$(basename $1).png\" 33 " ffmpeg "/bin/ffmpeg -i \"$1\" -frames:v 1 -update true \"$THUMB\" 34 " chafa "/bin/chafa -f sixel --view-size \"$2x$3\" --animate off --polite on -t 1 --bg black \"$THUMB\" 35 " coreutils "/bin/rm \"$THUMB\" 36 ;; 37 # Preview audio metadata 38 audio/*) 39 " ffmpeg "/bin/ffprobe -hide_banner \"$1\" 2>&1 40 ;; 41 *) 42 " coreutils "/bin/echo \"No preview is available for this file type.\" 43 ;; 44 esac 45 ")) 46 47 ;; TODO: Add opener 48 (define lf-configuration-files 49 `(("lf/lfrc" ,(mixed-text-file "lfrc" "\ 50 set sixel true 51 set previewer " ,previewer "\ 52 ")) 53 ("lf/previewer" ,previewer))) 54 55 ;; TODO: Add advanced options 56 (define home-lf-service-type 57 (service-type 58 (name 'home-lf) 59 (extensions 60 (list (service-extension home-xdg-configuration-files-service-type 61 lf-configuration-files))) 62 (description 63 "Install and configure the `lf` file manager."))) 64
