From 80cbff92a1e4f3915b3b87858bee11228a3b17ed Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 1 Sep 2020 14:03:18 +0200 Subject: [PATCH] Run commands in the terminal using /bin/sh And some hacks that set the EDITOR and the PATH. --- main.gd | 13 ++++--------- scripts/fake-editor | 6 ++++++ terminal.gd | 29 +++++++++++++++++------------ 3 files changed, 27 insertions(+), 21 deletions(-) create mode 100755 scripts/fake-editor diff --git a/main.gd b/main.gd index 53f8ce9..8061864 100644 --- a/main.gd +++ b/main.gd @@ -105,13 +105,16 @@ func git(args, splitlines = false): var a = args.split(" ") #print ("Running: ", a) a.insert(0, "-C") - a.insert(1, "/home/seb/tmp/godotgit") + a.insert(1, "/tmp/githydragit") OS.execute("git", a, true, output, true) var o = output[0] + if splitlines: o = o.split("\n") + # Remove last empty line. o.remove(len(o)-1) else: + # Remove trailing newline. o = o.substr(0,len(o)-1) return o @@ -124,14 +127,6 @@ func update_head(): n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y)) objects["HEAD"] = n add_child(n) - - n = node.instance() - n.id = "refs/heads/master" - n.type = "ref" - n.content = "" - n.position = Vector2(rand_range(0, viewport_size.x), rand_range(0, viewport_size.y)) - objects[n.id] = n - add_child(n) var n = objects["HEAD"] n.children = {symref_target("HEAD"): ""} diff --git a/scripts/fake-editor b/scripts/fake-editor new file mode 100755 index 0000000..37ef7e5 --- /dev/null +++ b/scripts/fake-editor @@ -0,0 +1,6 @@ +#!/bin/sh + +echo Hi, I am commit-hook +echo $* +zenity --question +echo Goodbye diff --git a/terminal.gd b/terminal.gd index f447bff..3e9e9de 100644 --- a/terminal.gd +++ b/terminal.gd @@ -1,17 +1,22 @@ extends Node2D -func _ready(): - pass - - - -func send_command(new_text): - var parts = new_text.split(" ") - var cmd = parts[0] - var args = parts - args.remove(0) +func send_command(command): + var cwd = run("pwd") + var output = [] - OS.execute(cmd, args, true, output, true) + + var hacky_command = command + hacky_command = "cd /tmp/githydragit;"+hacky_command + hacky_command = "export EDITOR=fake-editor;"+hacky_command + hacky_command = "export PATH=\"$PATH\":"+cwd+"/scripts;"+hacky_command + OS.execute("/bin/sh", ["-c", hacky_command], true, output, true) + $Input.text = "" - $Output.text = $Output.text + "$ " + new_text + "\n" + output[0] + $Output.text = $Output.text + "$ " + command + "\n" + output[0] $Output.scroll_vertical = 999999 + +func run(command): + var output = [] + OS.execute(command, [], true, output, true) + # Remove trailing newline. + return output[0].substr(0,len(output[0])-1)