Wilfred / ag.el

An Emacs frontend to The Silver Searcher
http://agel.readthedocs.org/en/latest/
525 stars 61 forks source link

ag-dired doesn't work on Mac OSX #33

Closed ShingoFukuyama closed 10 years ago

ShingoFukuyama commented 10 years ago

This feature is very cool. I love dired manipulation. Unfortunately, Mac OSX's xargs doesn't have -r and -d options. Without these options, it seems to work fine. I'm not sure, but are these options indispensable?

Wilfred commented 10 years ago

Argh, I only tested this feature on Linux.

-d specifies the delimiter to be \n, but I think this is the xargs default anyway. -r is --no-run-if-empty, and if we don't pass it, I think you can end up with the contents of the local directory in results (because ls is called without any arguments).

Rather than using xargs, a loop that calls ls for every line would work. It might be a performance hit, but that's probably the best solution.

I will try to get round to this, but patches welcome in the meantime.

Wilfred commented 10 years ago

Actually, looking at this some more, I'm not convinced that -d or -r are necessary. @Fuco1 would you agree?

Fuco1 commented 10 years ago

-r is actually a GNU extension (I wasn't aware of that), -d should work everywhere---it's probably not necessary though.

-r it is there to handle case when no match is found as you said, otherwise it lists current directory which is silly. Looping on each file with ls would be pretty silly too. If you want to go that route, I would make it optional, so people on OSX or windows could use ls and systems which support xargs the current solution.

However, doing something like ag -g bla | ls -la works just fine. The problem that xargs handles is when the input line is too long---shell has a certain limit which might be 2000 chars or more. So if many files match it would break in unpredictable ways. Xargs splits the input in chunks and sends that to the program in parts.

Splitting the output of ag manually and piping that to ls is another option (probably better than calling it for each file).

I can write a fix tomorrow or friday, depending on how my schedule turns out.

Wilfred commented 10 years ago

OK, I've opened a pull request with a fix. @ShingoFukuyama would you mind confirming that it works?

ShingoFukuyama commented 10 years ago

Thanks problem solved :+1: