Skip to content

Instantly share code, notes, and snippets.

@asonge
Created October 27, 2014 04:12
Show Gist options
  • Save asonge/6021e043bab3cb63c7bd to your computer and use it in GitHub Desktop.
Save asonge/6021e043bab3cb63c7bd to your computer and use it in GitHub Desktop.
defmodule Shell.Mixfile do
use Mix.Project
def project do
[
app: :shell,
version: "0.0.1",
elixir: "~> 1.0",
deps: deps,
escript: [
app: nil,
main_module: Shell,
emu_args: "-noinput",
consolidate_protocols: false
]
]
end
# Configuration for the OTP application
#
# Type `mix help compile.app` for more information
def application do
[applications: [:logger]]
end
# Dependencies can be Hex packages:
#
# {:mydep, "~> 0.3.0"}
#
# Or git/path repositories:
#
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
#
# Type `mix help deps` for more examples and options
defp deps do
[]
end
end
defmodule Shell do
def main(_) do
:user_drv.start([:'tty_sl -c -e',{__MODULE__,:start_loop,[]}])
:timer.sleep :infinity
end
def start_loop, do: spawn_link(&loop/0)
def loop() do
read |> eval |> print
loop
end
def read() do
IO.gets("Myprompt> ")
|> parse
end
def eval(["echo" | stuff]), do: stuff
def eval([cmd|_]) do
IO.puts "Unknown command #{inspect cmd}"
nil
end
def eval([]), do: nil
def print(value) do
IO.inspect value
end
defp parse(stmt), do: stmt |> to_string |> String.split
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment