Search code examples
windowsemacsfindinteractive-shell

Invoking a complex piped find within Emacs eshell-command


I'm trying to do something seemingly simple: create an Emacs function to create a TAGS file for me. There are simple instructions for doing this here

(defun create-tags (dir-name)
 "Create tags file."
 (interactive "DDirectory: ")
 (eshell-command 
  (format "find %s -type f -name \"*.[ch]\" | etags -" dir-name)))

The problem is I need "cpp" files instead of "c". That means my find command has to change to this:

find %s -type f -iname "*.cpp" -or -iname "*.h"

That works great on the command line. The problem I'm having is that eshell doesn't seem to like that at all. When I execute this function, I keep getting: File not found - "*.h": Invalid argument.

The answer to this question suggests that proper use of shell-quote-argument might fix these kinds of issues, but I haven't been able to hack out a solution that works. For instance, this produces the same error:

(format "find %s -type f -iname %s -or -iname %s | etags -"
   dir-name
   (shell-quote-argument "*.cpp")
   (shell-quote-argument "*.h"))

Solution

  • You're trying to use the posix syntax with the Windows find command. This is wrong for two reasons:

    • Surely you cannot hope that it supports a syntax from a different OS.
    • Windows find acts like grep, use dir instead.

    Hope it'll help you.