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

Check if ag executable exists on remote system #310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

panaak
Copy link

@panaak panaak commented Dec 4, 2017

If you have ag installed locally and want to do helm-ag in a remote directory, helm-ag.el just says:

failed: 'search term'

This PR tries to report missing remote executable.

@jcs090218
Copy link
Collaborator

This probably make sense to me.

@syohex What are your thoughts on this PR? 😄

@syohex
Copy link
Contributor

syohex commented Mar 24, 2020

(unless (file-exists-p (concat (file-remote-p default-directory) (executable-find (car cmds))))

I suppose this PR is not enough because (executable-find (car cmds)) of that line returns local command path. So if the executable path is different between local and remote(for example, local: /usr/bin/ag, remote: /usr/local/bin/ag), above condition expression returns unexpected result. I suppose you should write code which checks executable is installed on local and remote as below.

diff --git a/helm-ag.el b/helm-ag.el
index d21d1f3..07836e8 100644
--- a/helm-ag.el
+++ b/helm-ag.el
@@ -264,6 +264,13 @@ Default behaviour shows finish and result in mode-line."
       (while (re-search-forward "^\\([^:]+\\)" nil t)
         (replace-match (abbreviate-file-name (match-string-no-properties 1)))))))
 
+(defun helm-ag--executable-find (cmd)
+  (if (not (file-remote-p default-directory))
+      (executable-find cmd)
+    (let ((remote-paths (cl-loop for p in (exec-path)
+                                 collect (concat (file-remote-p default-directory) p))))
+      (locate-file cmd remote-paths exec-suffixes #'file-executable-p))))
+
 (defun helm-ag--init ()
   (let ((buf-coding buffer-file-coding-system))
     (helm-attrset 'recenter t)
@@ -279,10 +286,9 @@ Default behaviour shows finish and result in mode-line."
           (if (zerop (length (buffer-string)))
               (error "No ag output: '%s'" helm-ag--last-query)
             (unless (zerop ret)
-              (unless (executable-find (car cmds))
-                (error "'ag' is not installed."))
-              (unless (file-exists-p (concat (file-remote-p default-directory) (executable-find (car cmds))))
-                (error "'ag' is not installed on remote system."))
+              (unless (helm-ag--executable-find (car cmds))
+                (error "'%s' is not installed on %s system"
+                       (car cmds) (if (file-remote-p default-directory) "remote" "local")))
               (error "Failed: '%s'" helm-ag--last-query))))
         (when helm-ag--buffer-search
           (helm-ag--abbreviate-file-name))

@jcs090218
Copy link
Collaborator

@panaak Ping! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants