aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/list-desktop-files37
1 files changed, 37 insertions, 0 deletions
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)))