Ah yes. To avoid the XY problem: I’d like to have a ‘good enough’ and uniform solution for aliasing in the project’s root .iex.exs file, across disparate projects. This would serve as a quick mean to get to the ‘leaves’ of namespaces.
And if the ordering might be off, f.e., if the above automated ‘batch aliasing’ would effectively do
alias Foo.Bar
alias Foo.Bar.Bar
but I’d like the direct access to the first Bar, I can still override it with an additional/manual alias:
I came up with this code block that allows me to load all project aliases for the quick terminal usage
defmodule Console do
defmacro aliases(expression) do
{:ok, modules} = :application.get_key(:<YOUR_APP>, :modules)
modules =
for module <- modules do
quote do
alias unquote(module)
end
end
quote do
unquote(modules)
unquote(expression)
end
end
end