aboutsummaryrefslogtreecommitdiff
path: root/modules/external-open-lib.el
blob: aa90eb67b11977a561d42e53c3ef29c60dd44a2d (plain)
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
;;; external-open-lib.el --- Pure helpers for OS open-with dispatch -*- lexical-binding: t; -*-

;; Author: Craig Jennings <c@cjennings.net>

;;; Commentary:

;; Pure helpers for resolving the OS-default "open" command and
;; recognizing desktop launchers.  No side effects, no state.  The
;; feature module (`external-open.el') uses these helpers; consumers
;; that only need the dispatch (system-utils' "open with command",
;; dirvish's "open file manager here") require this library directly
;; instead of the feature module.
;;
;; Pulled out of `external-open.el' as part of utility-consolidation
;; Phase 4.  See `docs/design/utility-consolidation.org'.

;;; Code:

(require 'host-environment)

(defun cj/external-open-command ()
  "Return the OS-default \"open\" command for this host, or nil if unsupported.
Returns one of \"xdg-open\" (Linux), \"open\" (macOS), \"start\" (Windows).
Callers that require a command should error on nil with a contextual
message so the user sees what feature is unavailable."
  (cond
   ((env-linux-p)   "xdg-open")
   ((env-macos-p)   "open")
   ((env-windows-p) "start")
   (t nil)))

(defun cj/external-open-launcher-p (command)
  "Return non-nil when COMMAND is a desktop launcher.
Launchers (xdg-open, open, start) need to be called with `call-process'
and a zero BUFFER argument so they fully detach from Emacs.  Other
commands get `start-process-shell-command' so their output is visible."
  (and (stringp command)
       (member command '("xdg-open" "open" "start"))
       t))

(provide 'external-open-lib)
;;; external-open-lib.el ends here