diff --git a/game.gd b/game.gd index d4e8eeb..27f6c91 100644 --- a/game.gd +++ b/game.gd @@ -1,31 +1,11 @@ extends Node var tmp_prefix = "/tmp/" -var cwd var global_shell func _ready(): global_shell = Shell.new() global_shell.cd(tmp_prefix) - - cwd = global_shell.run("pwd") - # Remove trailing newline. - cwd = cwd.substr(0,len(cwd)-1) - -# Run a simple command with arguments, blocking, using OS.execute. -func exec(command, args=[]): - var debug = true - if debug: - print("game.exec: %s [%s]" % [command, PoolStringArray(args).join(", ")]) - - var output = [] - OS.execute(command, args, true, output, true) - output = output[0] - - if debug: - print(output) - - return output func read_file(path): print ("reading " + path) diff --git a/main.gd b/main.gd index 65466ef..2e05ca1 100644 --- a/main.gd +++ b/main.gd @@ -67,8 +67,8 @@ func load_level(id): get_tree().quit() # Danger zone! - game.exec("rm", ["-rf", active_repository_path]) - game.exec("rm", ["-rf", goal_repository_path]) + game.global_shell.run("rm -rf '%s'" % active_repository_path) + game.global_shell.run("rm -rf '%s'" % goal_repository_path) construct_repo(goal_script, goal_repository_path) construct_repo(active_script, active_repository_path) diff --git a/shell.gd b/shell.gd index 701f16e..7514748 100644 --- a/shell.gd +++ b/shell.gd @@ -9,7 +9,7 @@ func _init(): _fake_editor = game.tmp_prefix + "fake-editor" var content = game.read_file("res://scripts/fake-editor") game.write_file(_fake_editor, content) - run("chmod u+x " + _fake_editor) + _exec("chmod", ["u+x", _fake_editor]) func cd(dir): _cwd = dir @@ -17,7 +17,7 @@ func cd(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 = false + var debug = true if debug: print("$ %s" % command) @@ -31,9 +31,25 @@ func run(command): hacky_command += "cd '%s';" % _cwd hacky_command += command - var output = game.exec("/bin/sh", ["-c", hacky_command]) + var output = _exec("/bin/sh", ["-c", hacky_command]) if debug: print(output) return output + +# Run a simple command with arguments, blocking, using OS.execute. +func _exec(command, args=[]): + var debug = false + + if debug: + print("exec: %s [%s]" % [command, PoolStringArray(args).join(", ")]) + + var output = [] + OS.execute(command, args, true, output, true) + output = output[0] + + if debug: + print(output) + + return output