Skip to content

Instantly share code, notes, and snippets.

@Dkendal
Created February 8, 2024 17:22
Show Gist options
  • Save Dkendal/712c4de689bb69dac50d570746b3350d to your computer and use it in GitHub Desktop.
Save Dkendal/712c4de689bb69dac50d570746b3350d to your computer and use it in GitHub Desktop.
#!/usr/bin/env elixir
for path <- Path.wildcard("_build/test/lib/*/.mix/.mix_test_failures", match_dot: true),
{{mod, name}, path} <-
path
|> File.read!()
|> :erlang.binary_to_term()
|> elem(1)
|> Map.to_list(),
grep_match <-
name
|> to_string()
|> String.split()
|> Stream.unfold(fn
[] ->
nil
[_ | words] ->
search_term = Enum.join(words, " ")
System.cmd("rg", ["-w", search_term, "--vimgrep", path])
|> case do
{"", 1} -> {nil, words}
{matches, 0} -> {matches, []}
end
end)
|> Stream.reject(&is_nil/1)
|> Enum.to_list(),
into: IO.stream(:stdio, :line) do
[path, line, col, _] = String.split(grep_match, ":", parts: 4)
"#{Path.relative_to_cwd(path)}:#{line}:#{col}: #{mod} #{name}\n"
end
@Dkendal
Copy link
Author

Dkendal commented Feb 8, 2024

image

Example output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment