aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorGravatar Tom Willemse2025-07-22 11:12:19 -0700
committerGravatar Tom Willemse2025-07-22 11:13:12 -0700
commit066a07b091167f378f640c10a1693be8d37f8afe (patch)
treea13751238231ebcbec005c49274ace8eaf0b89fc /scripts
parent5d87feff0d487e669ee049eda1a43f445fbb7870 (diff)
downloadnew-dotfiles-066a07b091167f378f640c10a1693be8d37f8afe.tar.gz
new-dotfiles-066a07b091167f378f640c10a1693be8d37f8afe.zip
Add script to list desktop files
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)))