mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-22 07:30:24 +00:00
Fix terminal open when script file path contains bases
This commit is contained in:
parent
bd9cc5cfcb
commit
b132ed9555
3 changed files with 32 additions and 42 deletions
|
@ -18,8 +18,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
public static final ExternalTerminalType CMD = new SimpleType("cmd", "cmd", "cmd.exe") {
|
public static final ExternalTerminalType CMD = new SimpleType("cmd", "cmd", "cmd.exe") {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String toCommand(String name, String command) {
|
protected String toCommand(String name, String file) {
|
||||||
return "cmd.exe /C " + command;
|
return "cmd.exe /C \"" + file + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,8 +32,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
new SimpleType("powershell", "powershell", "PowerShell") {
|
new SimpleType("powershell", "powershell", "PowerShell") {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String toCommand(String name, String command) {
|
protected String toCommand(String name, String file) {
|
||||||
return "powershell.exe -Command " + command;
|
return "powershell.exe -ExecutionPolicy Bypass -Command \"" + file + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,12 +46,12 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
new SimpleType("windowsTerminal", "wt.exe", "Windows Terminal") {
|
new SimpleType("windowsTerminal", "wt.exe", "Windows Terminal") {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String toCommand(String name, String command) {
|
protected String toCommand(String name, String file) {
|
||||||
// A weird behavior in Windows Terminal causes the trailing
|
// A weird behavior in Windows Terminal causes the trailing
|
||||||
// backslash of a filepath to escape the closing quote in the title argument
|
// backslash of a filepath to escape the closing quote in the title argument
|
||||||
// So just remove that slash
|
// So just remove that slash
|
||||||
var fixedName = FileNames.removeTrailingSlash(name);
|
var fixedName = FileNames.removeTrailingSlash(name);
|
||||||
return "-w 1 nt --title \"" + fixedName + "\" " + command;
|
return "-w 1 nt --title \"" + fixedName + "\" \"" + file + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,20 +64,22 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
new SimpleType("gnomeTerminal", "gnome-terminal", "Gnome Terminal") {
|
new SimpleType("gnomeTerminal", "gnome-terminal", "Gnome Terminal") {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launch(String name, String command) throws Exception {
|
public void launch(String name, String file) throws Exception {
|
||||||
try (ShellControl pc = LocalStore.getShell()) {
|
try (ShellControl pc = LocalStore.getShell()) {
|
||||||
ApplicationHelper.checkSupport(pc, executable, getDisplayName());
|
ApplicationHelper.checkSupport(pc, executable, getDisplayName());
|
||||||
|
|
||||||
var toExecute = executable + " " + toCommand(name, command);
|
var toExecute = executable + " " + toCommand(name, file);
|
||||||
// In order to fix this bug which also affects us: https://askubuntu.com/questions/1148475/launching-gnome-terminal-from-vscode
|
// In order to fix this bug which also affects us:
|
||||||
toExecute = "GNOME_TERMINAL_SCREEN=\"\" nohup " + toExecute + " </dev/null &>/dev/null & disown";
|
// https://askubuntu.com/questions/1148475/launching-gnome-terminal-from-vscode
|
||||||
|
toExecute =
|
||||||
|
"GNOME_TERMINAL_SCREEN=\"\" nohup " + toExecute + " </dev/null &>/dev/null & disown";
|
||||||
pc.executeSimpleCommand(toExecute);
|
pc.executeSimpleCommand(toExecute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String toCommand(String name, String command) {
|
protected String toCommand(String name, String file) {
|
||||||
return "-v --title \"" + name + "\" -- " + command;
|
return "-v --title \"" + name + "\" -- \"" + file + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -89,8 +91,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
public static final ExternalTerminalType KONSOLE = new SimpleType("konsole", "konsole", "Konsole") {
|
public static final ExternalTerminalType KONSOLE = new SimpleType("konsole", "konsole", "Konsole") {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String toCommand(String name, String command) {
|
protected String toCommand(String name, String file) {
|
||||||
return "--new-tab -e " + command;
|
return "--new-tab -e \"" + file + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,8 +104,8 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
public static final ExternalTerminalType XFCE = new SimpleType("xfce", "xfce4-terminal", "Xfce") {
|
public static final ExternalTerminalType XFCE = new SimpleType("xfce", "xfce4-terminal", "Xfce") {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String toCommand(String name, String command) {
|
protected String toCommand(String name, String file) {
|
||||||
return "--tab --title \"" + name + "\" --command " + command;
|
return "--tab --title \"" + name + "\" --command \"" + file + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -142,7 +144,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void launch(String name, String command) throws Exception;
|
public abstract void launch(String name, String file) throws Exception;
|
||||||
|
|
||||||
static class MacOsTerminalType extends ExternalApplicationType.MacApplication implements ExternalTerminalType {
|
static class MacOsTerminalType extends ExternalApplicationType.MacApplication implements ExternalTerminalType {
|
||||||
|
|
||||||
|
@ -151,11 +153,11 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launch(String name, String command) throws Exception {
|
public void launch(String name, String file) throws Exception {
|
||||||
try (ShellControl pc = LocalStore.getShell()) {
|
try (ShellControl pc = LocalStore.getShell()) {
|
||||||
var suffix = command.equals(pc.getShellDialect().getOpenCommand())
|
var suffix = file.equals(pc.getShellDialect().getOpenCommand())
|
||||||
? "\"\""
|
? "\"\""
|
||||||
: "\"" + command.replaceAll("\"", "\\\\\"") + "\"";
|
: "\"" + file.replaceAll("\"", "\\\\\"") + "\"";
|
||||||
var cmd = "osascript -e 'tell app \"" + "Terminal" + "\" to do script " + suffix + "'";
|
var cmd = "osascript -e 'tell app \"" + "Terminal" + "\" to do script " + suffix + "'";
|
||||||
pc.executeSimpleCommand(cmd);
|
pc.executeSimpleCommand(cmd);
|
||||||
}
|
}
|
||||||
|
@ -169,7 +171,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launch(String name, String command) throws Exception {
|
public void launch(String name, String file) throws Exception {
|
||||||
var custom = AppPrefs.get().customTerminalCommand().getValue();
|
var custom = AppPrefs.get().customTerminalCommand().getValue();
|
||||||
if (custom == null || custom.isBlank()) {
|
if (custom == null || custom.isBlank()) {
|
||||||
throw new IllegalStateException("No custom terminal command specified");
|
throw new IllegalStateException("No custom terminal command specified");
|
||||||
|
@ -177,7 +179,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
|
|
||||||
var format = custom.contains("$cmd") ? custom : custom + " $cmd";
|
var format = custom.contains("$cmd") ? custom : custom + " $cmd";
|
||||||
try (var pc = LocalStore.getShell()) {
|
try (var pc = LocalStore.getShell()) {
|
||||||
var toExecute = format.replace("$cmd", command);
|
var toExecute = format.replace("$cmd", "\"" + file + "\"");
|
||||||
if (pc.getOsType().equals(OsType.WINDOWS)) {
|
if (pc.getOsType().equals(OsType.WINDOWS)) {
|
||||||
toExecute = "start \"" + name + "\" " + toExecute;
|
toExecute = "start \"" + name + "\" " + toExecute;
|
||||||
} else {
|
} else {
|
||||||
|
@ -205,7 +207,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launch(String name, String command) throws Exception {
|
public void launch(String name, String file) throws Exception {
|
||||||
try (ShellControl pc = LocalStore.getShell()) {
|
try (ShellControl pc = LocalStore.getShell()) {
|
||||||
var cmd = String.format(
|
var cmd = String.format(
|
||||||
"""
|
"""
|
||||||
|
@ -226,7 +228,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
end tell
|
end tell
|
||||||
end if
|
end if
|
||||||
EOF""",
|
EOF""",
|
||||||
command.replaceAll("\"", "\\\\\""), command.replaceAll("\"", "\\\\\""));
|
file.replaceAll("\"", "\\\\\""), file.replaceAll("\"", "\\\\\""));
|
||||||
pc.executeSimpleCommand(cmd);
|
pc.executeSimpleCommand(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,7 +241,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launch(String name, String command) throws Exception {
|
public void launch(String name, String file) throws Exception {
|
||||||
if (!MacOsPermissions.waitForAccessibilityPermissions()) {
|
if (!MacOsPermissions.waitForAccessibilityPermissions()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -259,7 +261,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
end tell
|
end tell
|
||||||
EOF
|
EOF
|
||||||
""",
|
""",
|
||||||
command.replaceAll("\"", "\\\\\""));
|
file.replaceAll("\"", "\\\\\""));
|
||||||
pc.executeSimpleCommand(cmd);
|
pc.executeSimpleCommand(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,11 +279,11 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launch(String name, String command) throws Exception {
|
public void launch(String name, String file) throws Exception {
|
||||||
try (ShellControl pc = LocalStore.getShell()) {
|
try (ShellControl pc = LocalStore.getShell()) {
|
||||||
ApplicationHelper.checkSupport(pc, executable, displayName);
|
ApplicationHelper.checkSupport(pc, executable, displayName);
|
||||||
|
|
||||||
var toExecute = executable + " " + toCommand(name, command);
|
var toExecute = executable + " " + toCommand(name, file);
|
||||||
if (pc.getOsType().equals(OsType.WINDOWS)) {
|
if (pc.getOsType().equals(OsType.WINDOWS)) {
|
||||||
toExecute = "start \"" + name + "\" " + toExecute;
|
toExecute = "start \"" + name + "\" " + toExecute;
|
||||||
} else {
|
} else {
|
||||||
|
@ -291,7 +293,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String toCommand(String name, String command);
|
protected abstract String toCommand(String name, String file);
|
||||||
|
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
try (ShellControl pc = LocalStore.getShell()) {
|
try (ShellControl pc = LocalStore.getShell()) {
|
||||||
|
|
|
@ -37,18 +37,6 @@ public class ScriptHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String unquote(String input) {
|
|
||||||
if (input.startsWith("\"") && input.endsWith("\"")) {
|
|
||||||
return input.substring(1, input.length() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.startsWith("'") && input.endsWith("'")) {
|
|
||||||
return input.substring(1, input.length() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String constructInitFile(
|
public static String constructInitFile(
|
||||||
ShellControl processControl, List<String> init, String toExecuteInShell,boolean login) {
|
ShellControl processControl, List<String> init, String toExecuteInShell,boolean login) {
|
||||||
ShellDialect t = processControl.getShellDialect();
|
ShellDialect t = processControl.getShellDialect();
|
||||||
|
|
|
@ -12,7 +12,7 @@ public class TerminalHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void open(String title, String command) throws Exception {
|
public static void open(String title, String command) throws Exception {
|
||||||
if (command.contains("\n") || command.contains(" ")) {
|
if (command.contains("\n") || command.contains(" ") || command.contains("\"") || command.contains("'")) {
|
||||||
command = ScriptHelper.createLocalExecScript(command);
|
command = ScriptHelper.createLocalExecScript(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue