mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-03 19:04:40 +01:00
579f18736a
game.exec is now the only point in the code that calls OS.execute. shell.run is the only point that refers to /bin/sh.
35 lines
636 B
GDScript
35 lines
636 B
GDScript
extends Node
|
|
class_name Shell
|
|
|
|
var _cwd
|
|
|
|
func _init():
|
|
pass
|
|
|
|
func cd(dir):
|
|
_cwd = dir
|
|
|
|
# Run a shell command given as a string. Run this if you're interested in the
|
|
# output of the command.
|
|
func run(command):
|
|
var debug = true
|
|
|
|
if debug:
|
|
print("$ %s" % command)
|
|
|
|
var env = {}
|
|
env["EDITOR"] = game.cwd+"/scripts/fake-editor"
|
|
env["TEST"] = "hi"
|
|
|
|
var hacky_command = ""
|
|
for variable in env:
|
|
hacky_command += "export %s='%s';" % [variable, env[variable]]
|
|
hacky_command += "cd '%s';" % _cwd
|
|
hacky_command += command
|
|
|
|
var output = game.exec("/bin/sh", ["-c", hacky_command])
|
|
|
|
if debug:
|
|
print(output)
|
|
|
|
return output
|