4 ms·
How do I do this in nushell? It's an alias I created recently to ripgrep through java and go files and tell me which have both of two words: function both {
by zellyn 7y ago
How do I do this in nushell? It's an alias I created recently to ripgrep through java and go files and tell me which have both of two words:
function both {
comm -1 -2 <(rg -i -l -t java -t go $1 | sort) <(rg -i -l -t java -t go $2 | sort)
}
Example usage: `both sharded jobqueue`
- tux1968 7y agoYour question brings to light some of the deep flexibility current shells allow with a very terse syntax. At least from Nu you can accept and process the output of your script. As an aside, your one liner is having to process every file twice, even ones that have already been excluded by the other ripgrep... something like this should be more performant: rg -il $2 $(rg -il -t java -t go $1)
- zellyn 7y agoNice. Perhaps with an xargs thrown in to be safe...
- tux1968 7y agoAfter playing with Nushell a bit, I think that you would do something like this: rg -0 -il -t java -t go sharded | split-row "\0" | rg -il jobqueue $it Instructing "rg" to use Nul as a separator and where "split-row" acts like xargs. (This only worked after I modified Nushell to recognize "\0" as the Nul separator. It's surprising that this case hasn't come up many times previously, so maybe i just missed the proper way to do it). Edit: Of course, not many filenames contain the newline character embedded in them, so usually this would be fine in an unmodified Nushell: rg -il -t java -t go sharded | lines | rg -il jobqueue $it