From 8501e598a4f48739a01bc4bf031883e086cb7bc4 Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Tue, 6 Oct 2020 16:50:31 +0200 Subject: [PATCH] Changes for OSX --- file_browser.gd | 4 ++-- game.gd | 4 ++-- helpers.gd | 2 ++ level.gd | 2 +- scripts/fake-editor | 7 +++++-- shell.gd | 5 +++-- terminal.gd | 2 +- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/file_browser.gd b/file_browser.gd index cbef3c4..6d0d618 100644 --- a/file_browser.gd +++ b/file_browser.gd @@ -11,7 +11,7 @@ func update(): var root_item = $FileTree.create_item() root_item.set_text(0, "FILES") - var file_string = shell.run("find -type f") + var file_string = shell.run("find . -type f") var files = file_string.split("\n") files = Array(files) # The last entry is an empty string, remove it. @@ -28,7 +28,7 @@ func _on_item_selected(): var item = $FileTree.get_selected() var file_path = item.get_text(0) - shell.run("%s/fake-editor-noblock %s" % [game.tmp_prefix_inside, file_path]) + shell.run("'%s'/fake-editor-noblock '%s'" % [game.tmp_prefix_inside, file_path]) func very_best_sort(a,b): # We're looking at the third character because all entries have the form diff --git a/game.gd b/game.gd index df6ac4c..92ad7ed 100644 --- a/game.gd +++ b/game.gd @@ -53,13 +53,13 @@ func copy_file_to_game_env(filename): var file_inside = tmp_prefix_inside + filename var content = helpers.read_file("res://scripts/"+filename) helpers.write_file(file_outside, content) - global_shell.run("chmod u+x " + file_inside) + global_shell.run("chmod u+x " + '"'+file_inside+'"') return file_inside func _tmp_prefix_inside(): var os = OS.get_name() var path - if os == "X11": + if os == "X11" or os == "OSX": path = OS.get_user_data_dir() elif os == "Windows": helpers.crash("Need to figure out Windows tmp_prefix_inside...") diff --git a/helpers.gd b/helpers.gd index e9c6dd7..d5b6344 100644 --- a/helpers.gd +++ b/helpers.gd @@ -75,6 +75,8 @@ func careful_delete(path_inside): if os == "X11": expected_prefix = "/home/%s/.local/share/git-hydra/tmp/" % OS.get_environment("USER") + elif os == "OSX": + expected_prefix = "/Users/%s/Library/Application Support/git-hydra/tmp/" % OS.get_environment("USER") elif os == "Windows": helpers.crash("Need to figure out delete_prefix on Windows") else: diff --git a/level.gd b/level.gd index a65b660..049c2d4 100644 --- a/level.gd +++ b/level.gd @@ -77,7 +77,7 @@ func construct(): # Make sure that active_repository is in a temporary directory. helpers.careful_delete(repo.path) - game.global_shell.run("mkdir " + repo.path) + game.global_shell.run("mkdir '%s'" % repo.path) game.global_shell.cd(repo.path) game.global_shell.run("git init") game.global_shell.run("git symbolic-ref HEAD refs/heads/main") diff --git a/scripts/fake-editor b/scripts/fake-editor index 208e82a..223c058 100755 --- a/scripts/fake-editor +++ b/scripts/fake-editor @@ -1,16 +1,19 @@ #!/usr/bin/env perl use IO::Socket; +use File::Spec; $socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1", PeerPort => 1234, Proto => "tcp", Type => SOCK_STREAM); +my $absolute_path = File::Spec->rel2abs($ARGV[0]); + # Send the length of the first argument as a byte. -$socket->send(chr(length($ARGV[0]))); +$socket->send(chr(length($absolute_path))); # Send the first argument as a string. -$socket->send($ARGV[0]); +$socket->send($absolute_path); # This call is intended to block, we're waiting for Godot to close the connection. my $reply; diff --git a/shell.gd b/shell.gd index f839109..c3f268b 100644 --- a/shell.gd +++ b/shell.gd @@ -20,7 +20,8 @@ func run(command, crash_on_fail=true): print("$ %s" % command) var env = {} - env["GIT_EDITOR"] = game.fake_editor + if game.fake_editor: + env["GIT_EDITOR"] = game.fake_editor.replace(" ", "\\ ") env["GIT_AUTHOR_NAME"] = "You" env["GIT_COMMITTER_NAME"] = "You" env["GIT_AUTHOR_EMAIL"] = "you@example.com" @@ -59,7 +60,7 @@ func run(command, crash_on_fail=true): func _shell_binary(): var os = OS.get_name() - if os == "X11": + if os == "X11" or os == "OSX": return "bash" elif os == "Windows": return "dependencies\\windows\\git\\bin\\bash.exe" diff --git a/terminal.gd b/terminal.gd index d77d51e..7acf1da 100644 --- a/terminal.gd +++ b/terminal.gd @@ -202,7 +202,7 @@ func generate_completions(command): # Part2: Prevent autocompletion to only show filename at the beginning of a command. if !(command.substr(0,4) == "git " and command.split(" ").size() <= 2) and command.split(" ").size() > 1: var last_word = Array(command.split(" ")).pop_back() - var file_string = repository.shell.run("find -type f") + var file_string = repository.shell.run("find . -type f") var files = file_string.split("\n") files = Array(files) # The last entry is an empty string, remove it.