oantolin / async-completing-read

An async-capable completing read function
GNU General Public License v3.0
21 stars 4 forks source link

Pass multiple arguments to command? #1

Closed protesilaos closed 4 years ago

protesilaos commented 4 years ago

Thank you @oantolin for making this!

I have been trying to make it read a find call, but it does not seem to work because it fails to parse my CLI arguments. My question is how exactly do you pass multiple arguments to a command.

I tried several variations of the following, with concat, format, etc.:

(let ((dir (vc-root-dir))
      (regexp (read-regexp "Search for regexp: ")))
  (completing-read "Files matching regexp: "
                   (acr-lines-from-process "find" dir "-type f -exec grep -ile" regexp "{} \;")))

The equivalent works on the command line, say:

find "/path/to/dir" -type f -exec grep -ile "search" {} \;

For completeness, the same fails with process-lines so there is something with how args are to be passed.

oantolin commented 4 years ago

Each argument to the command should be in a different list element. No shell is used so you shouldn't do quoting as you would for the shell (and also you don't get shell expansions such as ~ or $HOME both expanding to the home directory).

To run:

find "/path/to/dir" -type f -exec grep -ile "search" {} \;

use:

"find" "/path/to/dir" "-type" "f" "-exec" "grep" "-ile" "search" "{}" ";"

Notice that doesn't have extra quotes for "search" or the backslash on ";".

Internally async-completing-read calls start-process; that function, along with a few others, run programs directly without using a shell and have this pass-each-argument-separately interface.

protesilaos commented 4 years ago

Just to note that this can be closed. Thanks again!