From 066a07b091167f378f640c10a1693be8d37f8afe Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 22 Jul 2025 11:12:19 -0700 Subject: Add script to list desktop files --- scripts/list-desktop-files | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 scripts/list-desktop-files (limited to 'scripts') diff --git a/scripts/list-desktop-files b/scripts/list-desktop-files new file mode 100755 index 0000000..91bb2cf --- /dev/null +++ b/scripts/list-desktop-files @@ -0,0 +1,37 @@ +#!/usr/bin/env -S scsh -e main -s +;; -*- mode: scheme; -*- +!# + +;; https://cookbook.scheme.org/split-string/ +(define (string-split char-delimiter? string) + (define (maybe-add a b parts) + (if (= a b) parts (cons (substring string a b) parts))) + (let ((n (string-length string))) + (let loop ((a 0) (b 0) (parts '())) + (if (< b n) + (if (not (char-delimiter? (string-ref string b))) + (loop a (+ b 1) parts) + (loop (+ b 1) (+ b 1) (maybe-add a b parts))) + (reverse (maybe-add a b parts)))))) + +(define (char-space? char) + (char=? char #\space)) + +(define (read-application file) + (let* ((output (string-trim-right + (run/string (| (grep -EHi "^name=" ,file) + (head -n 1) + (sed "s/:name=/ /i"))))) + (strings (string-split char-space? output))) + (cons (car strings) (string-join (cdr strings) " ")))) + +(define (main args) + (let* ((files (run/strings (find /usr/share/applications + ,(string-append (getenv "HOME") "/.local/share/applications") + ,(string-append (getenv "HOME") "/.local/share/flatpak/exports/share/applications") + -type "f,l" + -name "*.desktop"))) + (applications (map read-application files))) + (for-each (lambda (pair) + (format #t "~a\t~a~%" (cdr pair) (file-name-nondirectory (car pair)))) + applications))) -- cgit v1.3-2-g0d8e