mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-03 19:04:40 +01:00
36 lines
636 B
GDScript3
36 lines
636 B
GDScript3
|
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
|