-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdefaults.lisp
45 lines (41 loc) · 1.78 KB
/
defaults.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(in-package #:org.shirakumo.file-select)
(define-condition no-backend-found (file-select-error)
()
(:report (lambda (c s) (format s "No usable backend for file-select could be found!"))))
(defun split (char string)
(let ((paths ())
(buffer (make-string-output-stream)))
(flet ((maybe-commit ()
(let ((string (get-output-stream-string buffer)))
(when (string/= string "")
(push (parse-native-namestring string) paths)))))
(loop for c across string
do (if (char= c char)
(maybe-commit)
(write-char c buffer))
finally (maybe-commit)))
(nreverse paths)))
(defun find-in-path (file)
(dolist (path (split #\: (uiop:getenv "PATH")))
(when (probe-file (merge-pathnames file path))
(return (merge-pathnames file path)))))
(defun determine-default-backend ()
(cond ((find :win32 *features*)
'org.shirakumo.file-select.win32:win32)
((find :darwin *features*)
'org.shirakumo.file-select.macos:macos)
((find-in-path "kdialog")
'org.shirakumo.file-select.kdialog:kdialog)
((find-in-path "matedialog")
(make-instance 'org.shirakumo.file-select.zenity:zenity :program-name "matedialog"))
((find-in-path "qarma")
(make-instance 'org.shirakumo.file-select.zenity:zenity :program-name "qarma"))
((find-in-path "yad")
'org.shirakumo.file-select.yad:yad)
((find-in-path "zenity")
'org.shirakumo.file-select.zenity:zenity)
((ignore-errors (cffi:load-foreign-library 'org.shirakumo.file-select.gtk:gtk))
(cffi:close-foreign-library 'org.shirakumo.file-select.gtk:gtk)
'org.shirakumo.file-select.gtk:gtk)
(T
(error 'no-backend-found))))