From 3ebe0d46390f8c33dfc78fc8f2925fd8da79d86a Mon Sep 17 00:00:00 2001 From: crschnick Date: Mon, 27 Mar 2023 18:59:17 +0000 Subject: [PATCH] More shell fixes --- .../io/xpipe/app/browser/FileListModel.java | 2 +- .../app/browser/OpenFileSystemModel.java | 16 ------- .../java/io/xpipe/app/util/ScriptHelper.java | 8 ++-- .../core/process/ProcessControlProvider.java | 5 +- .../io/xpipe/core/process/ShellControl.java | 46 +++++++++++++++++-- .../io/xpipe/core/process/ShellDialect.java | 2 +- 6 files changed, 49 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/browser/FileListModel.java b/app/src/main/java/io/xpipe/app/browser/FileListModel.java index 2aa1a8c1..44eb5083 100644 --- a/app/src/main/java/io/xpipe/app/browser/FileListModel.java +++ b/app/src/main/java/io/xpipe/app/browser/FileListModel.java @@ -99,7 +99,7 @@ final class FileListModel { } if (entry.isDirectory()) { - fileSystemModel.navigate(entry.getPath(), true); + fileSystemModel.cd(entry.getPath()); } else { FileOpener.openInTextEditor(entry); } diff --git a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java index 3c0b6fa3..85dabb25 100644 --- a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java @@ -283,22 +283,10 @@ final class OpenFileSystemModel { }); } - /////////////////////////////////////////////////////////////////////////// - // Properties // - /////////////////////////////////////////////////////////////////////////// - - public ReadOnlyObjectProperty currentPathProperty() { - return currentPath.getReadOnlyProperty(); - } - public FileBrowserNavigationHistory getHistory() { return history; } - /////////////////////////////////////////////////////////////////////////// - // Commands // - /////////////////////////////////////////////////////////////////////////// - public void back() { history.back().ifPresent(currentPath::set); } @@ -306,8 +294,4 @@ final class OpenFileSystemModel { public void forth() { history.forth().ifPresent(currentPath::set); } - - public void navigate(String path, boolean saveInHistory) { - currentPath.set(path); - } } diff --git a/app/src/main/java/io/xpipe/app/util/ScriptHelper.java b/app/src/main/java/io/xpipe/app/util/ScriptHelper.java index 89b17aa8..b5b12d9e 100644 --- a/app/src/main/java/io/xpipe/app/util/ScriptHelper.java +++ b/app/src/main/java/io/xpipe/app/util/ScriptHelper.java @@ -54,13 +54,13 @@ public class ScriptHelper { ShellDialect t = processControl.getShellDialect(); // We always want to generate and init file -// if (init.size() == 0 && toExecuteInShell == null) { -// return null; -// } + if (init.size() == 0 && toExecuteInShell == null) { + return createExecScript(processControl, processControl.getShellDialect().getNewLine().getNewLineString()); + } if (init.size() == 0) { // Check for special case of the command to be executed just being another shell script - if (toExecuteInShell != null && (toExecuteInShell.endsWith(".sh") || toExecuteInShell.endsWith(".bat"))) { + if (toExecuteInShell.endsWith(".sh") || toExecuteInShell.endsWith(".bat")) { return toExecuteInShell; } } diff --git a/core/src/main/java/io/xpipe/core/process/ProcessControlProvider.java b/core/src/main/java/io/xpipe/core/process/ProcessControlProvider.java index b85a465a..123f1b85 100644 --- a/core/src/main/java/io/xpipe/core/process/ProcessControlProvider.java +++ b/core/src/main/java/io/xpipe/core/process/ProcessControlProvider.java @@ -1,6 +1,5 @@ package io.xpipe.core.process; -import io.xpipe.core.util.FailableBiFunction; import io.xpipe.core.util.FailableFunction; import lombok.NonNull; @@ -29,7 +28,7 @@ public abstract class ProcessControlProvider { public static ShellControl createSub( ShellControl parent, @NonNull FailableFunction commandFunction, - FailableBiFunction terminalCommand) { + ShellControl.TerminalOpenFunction terminalCommand) { return INSTANCES.stream() .map(localProcessControlProvider -> localProcessControlProvider.sub(parent, commandFunction, terminalCommand)) @@ -61,7 +60,7 @@ public abstract class ProcessControlProvider { public abstract ShellControl sub( ShellControl parent, @NonNull FailableFunction commandFunction, - FailableBiFunction terminalCommand); + ShellControl.TerminalOpenFunction terminalCommand); public abstract CommandControl command( ShellControl parent, diff --git a/core/src/main/java/io/xpipe/core/process/ShellControl.java b/core/src/main/java/io/xpipe/core/process/ShellControl.java index f15d2015..57ab2ce1 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellControl.java +++ b/core/src/main/java/io/xpipe/core/process/ShellControl.java @@ -1,6 +1,5 @@ package io.xpipe.core.process; -import io.xpipe.core.util.FailableBiFunction; import io.xpipe.core.util.FailableFunction; import io.xpipe.core.util.SecretValue; import lombok.NonNull; @@ -73,16 +72,53 @@ public interface ShellControl extends ProcessControl { SecretValue getElevationPassword(); default ShellControl subShell(@NonNull ShellDialect type) { - return subShell(p -> type.getOpenCommand(), null).elevationPassword(getElevationPassword()); + return subShell(p -> type.getOpenCommand(), new TerminalOpenFunction() { + @Override + public boolean changesEnvironment() { + return false; + } + + @Override + public String prepare(ShellControl sc, String command) throws Exception { + return command; + } + }).elevationPassword(getElevationPassword()); + } + + interface TerminalOpenFunction { + + boolean changesEnvironment(); + + String prepare(ShellControl sc, String command) throws Exception; } default ShellControl identicalSubShell() { - return subShell(p -> p.getShellDialect().getOpenCommand(), null) + return subShell(p -> p.getShellDialect().getOpenCommand(), new TerminalOpenFunction() { + @Override + public boolean changesEnvironment() { + return false; + } + + @Override + public String prepare(ShellControl sc, String command) throws Exception { + return command; + } + }) .elevationPassword(getElevationPassword()); } default ShellControl subShell(@NonNull String command) { - return subShell(processControl -> command, null); + return subShell(processControl -> command, new TerminalOpenFunction() { + @Override + public boolean changesEnvironment() { + return false; + } + + @Override + public String prepare(ShellControl sc, String command) throws Exception { + return command; + } + }); } default T enforceDialect(@NonNull ShellDialect type, Function sc) throws Exception { @@ -97,7 +133,7 @@ public interface ShellControl extends ProcessControl { ShellControl subShell( FailableFunction command, - FailableBiFunction terminalCommand); + TerminalOpenFunction terminalCommand); void executeLine(String command) throws Exception; diff --git a/core/src/main/java/io/xpipe/core/process/ShellDialect.java b/core/src/main/java/io/xpipe/core/process/ShellDialect.java index 9e0423f8..665afe1a 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellDialect.java +++ b/core/src/main/java/io/xpipe/core/process/ShellDialect.java @@ -93,7 +93,7 @@ public interface ShellDialect { String getOpenCommand(); - String prepareTerminalInitFileOpenCommand(ShellControl parent, String file) throws Exception; + String prepareTerminalInitFileOpenCommand(ShellDialect parentDialect, ShellControl sc, String file) throws Exception; String runScript(String file);