More shell fixes

This commit is contained in:
crschnick 2023-03-27 18:59:17 +00:00
parent 97079fb58d
commit 3ebe0d4639
6 changed files with 49 additions and 30 deletions

View file

@ -99,7 +99,7 @@ final class FileListModel {
}
if (entry.isDirectory()) {
fileSystemModel.navigate(entry.getPath(), true);
fileSystemModel.cd(entry.getPath());
} else {
FileOpener.openInTextEditor(entry);
}

View file

@ -283,22 +283,10 @@ final class OpenFileSystemModel {
});
}
///////////////////////////////////////////////////////////////////////////
// Properties //
///////////////////////////////////////////////////////////////////////////
public ReadOnlyObjectProperty<String> 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);
}
}

View file

@ -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;
}
}

View file

@ -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<ShellControl, String, Exception> commandFunction,
FailableBiFunction<ShellControl, String, String, Exception> 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<ShellControl, String, Exception> commandFunction,
FailableBiFunction<ShellControl, String, String, Exception> terminalCommand);
ShellControl.TerminalOpenFunction terminalCommand);
public abstract CommandControl command(
ShellControl parent,

View file

@ -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> T enforceDialect(@NonNull ShellDialect type, Function<ShellControl, T> sc) throws Exception {
@ -97,7 +133,7 @@ public interface ShellControl extends ProcessControl {
ShellControl subShell(
FailableFunction<ShellControl, String, Exception> command,
FailableBiFunction<ShellControl, String, String, Exception> terminalCommand);
TerminalOpenFunction terminalCommand);
void executeLine(String command) throws Exception;

View file

@ -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);