forked from vjohansen/emacs-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin-detect.el
64 lines (52 loc) · 1.69 KB
/
bin-detect.el
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
;;; bin-detect.el --- Search for program locations in paths
;;; Commentary:
;;
;; Search for programs in paths
;;
;; (bin-detect-find "git" '("c:/temp" "c:/tools/git/bin"))
;; (bin-detect-find "git.exe" '("c:/temp" "c:/tools/git/bin"))
;; (bin-detect-find "git/bin/git" (bin-detect-windows-paths))
;;
;;; Code:
(defvar bin-detect-tools-dir "c:/tools")
(defvar bin-detect-git nil)
(defun bin-detect-windows-paths ()
"Return a list of typical program paths"
(interactive)
(let (result try)
(setq try bin-detect-tools-dir)
(if (file-directory-p try)
(add-to-list 'result try))
(setq try "c:\\Program Files")
(if (file-directory-p try)
(add-to-list 'result try t))
(setq try "c:\\Program Files (x86)")
(if (file-directory-p try)
(add-to-list 'result try t))
result))
(defun bin-detect--find (program paths)
"Search for PROGRAM in PATHS.
Returns first match."
(interactive)
(let (result candidate)
(dolist (path paths)
(setq candidate (concat
(replace-regexp-in-string "\\([^/\\]\\)$" "\\1/" path)
program))
(if (and (file-exists-p candidate) (not result)
(not (file-directory-p candidate)))
(setq result candidate)))
result
))
(defun bin-detect-find (program paths)
"Search for PROGRAM in PATHS.
Will try to append .exe.
Returns first match."
(if (not (string-match "\\.exe$" (downcase program)))
(or
(bin-detect--find (concat program ".exe") paths)
(bin-detect--find program paths))
;; else
(bin-detect--find program paths)))
(provide 'bin-detect)
;;; bin-detect.el ends here