oh-my-git/scenes/better_shell.gd
Jason Yundt b1d0bdd9e7 Fix debugger warnings about unused identifiers
If the identifier was used by code that was commented out, then I just
commented out the line that declared the identifier. If the identifier
wasn’t even used by code that was commented out, then I just deleted the
line that declared the identifier.
2023-05-16 08:13:31 -04:00

73 lines
1.8 KiB
GDScript

extends Node
class_name BetterShell
var exit_code
var _cwd
var _os = OS.get_name()
func _init():
# Create required directories and move into the tmp directory.
_cwd = "/tmp"
run("mkdir -p '%s/repos'" % game.tmp_prefix)
_cwd = game.tmp_prefix
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, crash_on_fail=true):
var shell_command = ShellCommand.new()
shell_command.command = command
shell_command.crash_on_fail = crash_on_fail
run_async_thread(shell_command)
exit_code = shell_command.exit_code
return shell_command.output
func run_async(command, crash_on_fail=true):
var shell_command = ShellCommand.new()
shell_command.command = command
shell_command.crash_on_fail = crash_on_fail
var t = Thread.new()
shell_command.thread = t
t.start(self, "run_async_thread", shell_command)
return shell_command
func run_async_thread(shell_command):
var debug = false
var command = shell_command.command
if debug:
print("$ %s" % command)
var env = {}
env["HOME"] = game.tmp_prefix
var hacky_command = ""
for variable in env:
hacky_command += "export %s='%s';" % [variable, env[variable]]
#hacky_command += "export PATH=\'"+game.tmp_prefix+":'\"$PATH\";"
hacky_command += "cd '%s' || exit 1;" % _cwd
hacky_command += command
#print(hacky_command)
var shell_command_internal = game.shell_test(hacky_command)
shell_command.output = shell_command_internal.output
shell_command.exit_code = shell_command_internal.exit_code
shell_command.emit_signal("done")
func _shell_binary():
if _os == "X11" or _os == "OSX":
return "bash"
elif _os == "Windows":
return "dependencies\\windows\\git\\bin\\bash.exe"
else:
helpers.crash("Unsupported OS: %s" % _os)