Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify wakatime-find-binary with locate-file. #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 16 additions & 39 deletions wakatime-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -102,45 +102,22 @@ the wakatime subprocess occurs."

(defun wakatime-find-binary (program)
"Find the full path to an executable program."
(cond
((file-exists-p (format "/usr/local/bin/%s" program))
(format "/usr/local/bin/%s" program))
((file-exists-p (format "/usr/bin/%s" program))
(format "/usr/bin/%s" program))
((file-exists-p (format "/bin/%s" program))
(format "/bin/%s" program))
((file-exists-p (format "/usr/local/sbin/%s" program))
(format "/usr/local/sbin/%s" program))
((file-exists-p (format "/usr/sbin/%s" program))
(format "/usr/sbin/%s" program))
((file-exists-p (format "/sbin/%s" program))
(format "/sbin/%s" program))
;; For linux users
((file-exists-p "~/.wakatime/wakatime-cli")
"~/.wakatime/wakatime-cli")
;; For windows 10+ fix to get wakatime-cli.exe
((file-exists-p (concat
(string-replace "\\" "/" (concat
(substitute-env-vars "$HOMEDRIVE")
(substitute-env-vars "$HOMEPATH")))
(format "/.wakatime/%s" program)))
(concat (string-replace "\\" "/" (concat
(substitute-env-vars "$HOMEDRIVE")
(substitute-env-vars "$HOMEPATH")))
(format "/.wakatime/%s" program)))
;; For windows 10+ fix to get wakatime-cli-amd64.exe
((file-exists-p (concat
(string-replace "\\" "/" (concat
(substitute-env-vars "$HOMEDRIVE")
(substitute-env-vars "$HOMEPATH")))
"/.wakatime/wakatime-cli-windows-amd64.exe"))
(concat (string-replace "\\" "/" (concat
(substitute-env-vars "$HOMEDRIVE")
(substitute-env-vars "$HOMEPATH")))
"/.wakatime/wakatime-cli-windows-amd64.exe"))
((not (s-blank (executable-find "wakatime")))
(executable-find "wakatime"))
(t program)))
(let ((paths
(append exec-path
(list "/usr/local/bin" "/usr/bin" "/bin"
"/usr/local/sbin" "/usr/sbin" "/sbin"
(or (getenv "WAKATIME_HOME") "~/.wakatime")
;; nil is acceptable.
(unless (s-blank (substitute-env-vars "$HOMEDRIVE"))
(concat (string-replace "\\" "/" (concat
(substitute-env-vars "$HOMEDRIVE")
(substitute-env-vars "$HOMEPATH")))
"/.wakatime")))))
(suffixes
(append exec-suffixes '("-windows-amd64.exe"))))
;; `executable-find' internally uses `locate-file'.
(or (locate-file program paths suffixes 1)
(locate-file "wakatime" paths suffixes 1))))

(defun wakatime-client-command (savep)
"Return client command executable and arguments.
Expand Down