Skip to content

Instantly share code, notes, and snippets.

@wende
Created April 16, 2015 22:29
Show Gist options
  • Select an option

  • Save wende/1493441b5d7b5d3cdd11 to your computer and use it in GitHub Desktop.

Select an option

Save wende/1493441b5d7b5d3cdd11 to your computer and use it in GitHub Desktop.
loadAll = fn(dir) ->
dir
|> Path.join("**/*.ex")
|> Path.wildcard()
|> Enum.map(&Code.require_file/1)
end
formatResult = fn({exists, one, multi}) ->
[exists, one, Enum.join(multi, ",")] |> (&(Enum.join(&1, "|"))).()
end
execute = fn
("l", input) -> Code.require_file(input)
("a", input) -> IEx.Autocomplete.expand Enum.reverse to_char_list(input)
end
loop = fn(y) ->
[command, input] = IO.gets("") |> String.split
IO.puts formatResult.(execute.(command, input)) <> "\nok."
y.(y)
end
[first|_] = System.argv()
loadAll.(first)
loop.(loop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment