Skip to content

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

https://github.com/emacsorphanage/helm-ag/blob/900f6a001f92215018292be4bee85a56aa8f3050/helm-ag.el#L284

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