mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-07-15 11:16:13 +12:00
Improve substitution of variables in custom commands
This commit is contained in:
parent
068e79bbe6
commit
35ca2ae716
|
@ -117,8 +117,7 @@ public interface ExternalEditorType extends PrefsChoiceValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
var format = customCommand.contains("$file") ? customCommand : customCommand + " $file";
|
var format = customCommand.contains("$file") ? customCommand : customCommand + " $file";
|
||||||
var fileString = file.toString().contains(" ") ? "\"" + file + "\"" : file.toString();
|
ApplicationHelper.executeLocalApplication(sc -> ApplicationHelper.replaceFileArgument(format, "file", file.toString()), true);
|
||||||
ApplicationHelper.executeLocalApplication(sc -> format.replace("$file", fileString), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -349,7 +349,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", "\"" + file + "\"");
|
var toExecute = ApplicationHelper.replaceFileArgument(format, "cmd", file);
|
||||||
if (pc.getOsType().equals(OsType.WINDOWS)) {
|
if (pc.getOsType().equals(OsType.WINDOWS)) {
|
||||||
toExecute = "start \"" + name + "\" " + toExecute;
|
toExecute = "start \"" + name + "\" " + toExecute;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -9,6 +9,13 @@ import java.util.function.Function;
|
||||||
|
|
||||||
public class ApplicationHelper {
|
public class ApplicationHelper {
|
||||||
|
|
||||||
|
public static String replaceFileArgument(String format, String variable, String file) {
|
||||||
|
var fileString = file.contains(" ") ? "\"" + file + "\"" : file;
|
||||||
|
// Check if the variable is already quoted
|
||||||
|
var replaced = format.replace("\"$" + variable + "\"", fileString).replace("$" + variable, fileString);
|
||||||
|
return replaced;
|
||||||
|
}
|
||||||
|
|
||||||
public static void executeLocalApplication(Function<ShellControl, String> s, boolean detach) throws Exception {
|
public static void executeLocalApplication(Function<ShellControl, String> s, boolean detach) throws Exception {
|
||||||
try (var sc = LocalStore.getShell().start()) {
|
try (var sc = LocalStore.getShell().start()) {
|
||||||
var cmd = detach ? ScriptHelper.createDetachCommand(sc, s.apply(sc)) : s.apply(sc);
|
var cmd = detach ? ScriptHelper.createDetachCommand(sc, s.apply(sc)) : s.apply(sc);
|
||||||
|
|
Loading…
Reference in a new issue