code / tomo-shell

Lines59 Tomo32 Markdown24 INI3
(44 lines)
1 use commands
3 lang Shell
4 convert(text:Text -> Shell)
5 return Shell.from_text("'" ++ text.replace("'", `'"'"'`) ++ "'")
7 convert(texts:[Text] -> Shell)
8 return Shell.from_text(" ".join([Shell(t).text for t in texts]))
10 convert(path:Path -> Shell)
11 return Shell(Text(path.expand_home()))
13 convert(paths:[Path] -> Shell)
14 return Shell.from_text(" ".join([Shell(Text(p)).text for p in paths]))
16 convert(n:Int -> Shell) return Shell.from_text(Text(n))
17 convert(n:Int64 -> Shell) return Shell.from_text(Text(n))
18 convert(n:Int32 -> Shell) return Shell.from_text(Text(n))
19 convert(n:Int16 -> Shell) return Shell.from_text(Text(n))
20 convert(n:Int8 -> Shell) return Shell.from_text(Text(n))
21 convert(n:Num -> Shell) return Shell.from_text(Text(n))
22 convert(n:Num32 -> Shell) return Shell.from_text(Text(n))
24 func command(shell:Shell -> Command)
25 return Command("sh", ["-c", shell.text])
27 func result(shell:Shell, input="", input_bytes:[Byte]=[] -> ProgramResult)
28 return shell.command().result(input=input, input_bytes=input_bytes)
30 func run(shell:Shell -> ExitType)
31 return shell.command().run()
33 func get_output(shell:Shell, input="", trim_newline=yes -> Text?)
34 return shell.command().get_output(input=input, trim_newline=trim_newline)
36 func get_output_bytes(shell:Shell, input="", input_bytes:[Byte]=[] -> [Byte]?)
37 return shell.command().get_output_bytes(input=input, input_bytes=input_bytes)
39 func by_line(shell:Shell -> func(->Text?)?)
40 return shell.command().by_line()
42 func main(command:Shell)
43 for line in command.by_line()!
44 >> line