From f064efaa2997e441294072b4ba4744bc2b00cc67 Mon Sep 17 00:00:00 2001 From: crschnick Date: Thu, 11 May 2023 10:26:55 +0000 Subject: [PATCH] Partially revert no init script changes for terminals --- .../xpipe/app/prefs/ExternalTerminalType.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java index aab5c1785..a8615e8ff 100644 --- a/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java +++ b/app/src/main/java/io/xpipe/app/prefs/ExternalTerminalType.java @@ -35,7 +35,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { @Override protected String toCommand(String name, String file) { - return "-ExecutionPolicy Bypass -NoProfile -Command " + noInit(file); + return "-ExecutionPolicy Bypass -NoProfile -Command cmd /C '" + file + "'"; } @Override @@ -49,8 +49,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue { @Override protected String toCommand(String name, String file) { // Fix for https://github.com/PowerShell/PowerShell/issues/18530#issuecomment-1325691850 - var script = ScriptHelper.createLocalExecScript("set \"PSModulePath=\"\r\n\"" + noInit(file) + "\"\npause"); - return "-ExecutionPolicy Bypass -NoProfile -Command " + noInit(script); + var script = ScriptHelper.createLocalExecScript("set \"PSModulePath=\"\r\n\"" + file + "\"\npause"); + return "-ExecutionPolicy Bypass -NoProfile -Command cmd /C '" +script + "'"; } @Override @@ -68,7 +68,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { // backslash of a filepath to escape the closing quote in the title argument // So just remove that slash var fixedName = FileNames.removeTrailingSlash(name); - return "-w 1 nt --title \"" + fixedName + "\" " + noInit(file); + return "-w 1 nt --title \"" + fixedName + "\" \"" + file + "\""; } @Override @@ -89,7 +89,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { // In order to fix this bug which also affects us: // https://askubuntu.com/questions/1148475/launching-gnome-terminal-from-vscode toExecute = - "GNOME_TERMINAL_SCREEN=\"\" nohup " + noInit(file) + " /dev/null & disown"; + "GNOME_TERMINAL_SCREEN=\"\" nohup " + toExecute + " /dev/null & disown"; pc.executeSimpleCommand(toExecute); } } @@ -109,7 +109,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { @Override protected String toCommand(String name, String file) { - return "--new-tab -e " + noInit(file); + return "--new-tab -e \"" + file + "\""; } @Override @@ -122,7 +122,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { @Override protected String toCommand(String name, String file) { - return "--tab --title \"" + name + "\" --command " + noInit(file); + return "--tab --title \"" + name + "\" --command \"" + file + "\""; } @Override @@ -164,10 +164,6 @@ public interface ExternalTerminalType extends PrefsChoiceValue { public abstract void launch(String name, String file, boolean elevated) throws Exception; - default String noInit(String file) { - return ShellDialects.getPlatformDefault().executeWithNoInitFiles(ShellDialects.getPlatformDefault(), file); - } - static class MacOsTerminalType extends ExternalApplicationType.MacApplication implements ExternalTerminalType { public MacOsTerminalType() { @@ -236,7 +232,6 @@ public interface ExternalTerminalType extends PrefsChoiceValue { @Override public void launch(String name, String file, boolean elevated) throws Exception { - var toExecute = noInit(file).replaceAll("\"", "\\\\\""); try (ShellControl pc = LocalStore.getShell()) { var cmd = String.format( """ @@ -257,7 +252,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue { end tell end if EOF""", - toExecute, toExecute); + file.replaceAll("\"", "\\\\\""), file.replaceAll("\"", "\\\\\"")); pc.executeSimpleCommand(cmd); } }