mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-10-02 18:17:27 +13:00
Small fixes for shells
This commit is contained in:
parent
b3cfae5a92
commit
1ca9e2c751
4 changed files with 27 additions and 25 deletions
|
@ -64,42 +64,41 @@ public interface ShellProcessControl extends ProcessControl {
|
||||||
SecretValue getElevationPassword();
|
SecretValue getElevationPassword();
|
||||||
|
|
||||||
default ShellProcessControl subShell(@NonNull ShellType type) {
|
default ShellProcessControl subShell(@NonNull ShellType type) {
|
||||||
return subShell(type.openCommand()).elevation(getElevationPassword());
|
return subShell(p -> type.openCommand(), (shellProcessControl, s) -> {
|
||||||
|
return s == null ? type.openCommand() : type.switchTo(s);
|
||||||
|
})
|
||||||
|
.elevation(getElevationPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
default ShellProcessControl subShell(@NonNull List<String> command) {
|
default ShellProcessControl subShell(@NonNull List<String> command) {
|
||||||
return subShell(shellProcessControl -> shellProcessControl.getShellType().flatten(command));
|
return subShell(
|
||||||
|
shellProcessControl -> shellProcessControl.getShellType().flatten(command), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default ShellProcessControl subShell(@NonNull String command) {
|
default ShellProcessControl subShell(@NonNull String command) {
|
||||||
return subShell(processControl -> command);
|
return subShell(processControl -> command, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShellProcessControl subShell(@NonNull Function<ShellProcessControl, String> command);
|
ShellProcessControl subShell(
|
||||||
|
@NonNull Function<ShellProcessControl, String> command,
|
||||||
default ShellProcessControl consoleCommand(@NonNull String command) {
|
BiFunction<ShellProcessControl, String, String> terminalCommand);
|
||||||
return consoleCommand((shellProcessControl, c) -> command);
|
|
||||||
}
|
|
||||||
|
|
||||||
ShellProcessControl consoleCommand(@NonNull BiFunction<ShellProcessControl, String, String> command);
|
|
||||||
|
|
||||||
void executeCommand(String command) throws Exception;
|
void executeCommand(String command) throws Exception;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
ShellProcessControl start() throws Exception;
|
ShellProcessControl start() throws Exception;
|
||||||
|
|
||||||
default CommandProcessControl commandListFunction(Function<ShellProcessControl, List<String>> command) {
|
CommandProcessControl command(Function<ShellProcessControl, String> command);
|
||||||
return commandFunction(shellProcessControl -> shellProcessControl.getShellType().flatten(command.apply(shellProcessControl)));
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandProcessControl commandFunction(Function<ShellProcessControl, String> command);
|
CommandProcessControl command(
|
||||||
|
Function<ShellProcessControl, String> command, Function<ShellProcessControl, String> terminalCommand);
|
||||||
|
|
||||||
default CommandProcessControl command(String command) {
|
default CommandProcessControl command(String command) {
|
||||||
return commandFunction(shellProcessControl -> command);
|
return command(shellProcessControl -> command);
|
||||||
}
|
}
|
||||||
|
|
||||||
default CommandProcessControl command(List<String> command) {
|
default CommandProcessControl command(List<String> command) {
|
||||||
return commandFunction(shellProcessControl -> shellProcessControl.getShellType().flatten(command));
|
return command(shellProcessControl -> shellProcessControl.getShellType().flatten(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
void exitAndWait() throws IOException;
|
void exitAndWait() throws IOException;
|
||||||
|
|
|
@ -24,7 +24,11 @@ public interface ShellType {
|
||||||
|
|
||||||
default String flatten(List<String> command) {
|
default String flatten(List<String> command) {
|
||||||
return command.stream()
|
return command.stream()
|
||||||
.map(s -> s.contains(" ") && !(s.startsWith("\"") && s.endsWith("\"")) ? "\"" + s + "\"" : s)
|
.map(s -> s.contains(" ")
|
||||||
|
&& !(s.startsWith("\"") && s.endsWith("\""))
|
||||||
|
&& !(s.startsWith("'") && s.endsWith("'"))
|
||||||
|
? "\"" + s + "\""
|
||||||
|
: s)
|
||||||
.collect(Collectors.joining(" "));
|
.collect(Collectors.joining(" "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +74,7 @@ public interface ShellType {
|
||||||
|
|
||||||
String getPrintVariableCommand(String prefix, String name);
|
String getPrintVariableCommand(String prefix, String name);
|
||||||
|
|
||||||
List<String> openCommand();
|
String openCommand();
|
||||||
|
|
||||||
String switchTo(String cmd);
|
String switchTo(String cmd);
|
||||||
|
|
||||||
|
|
|
@ -11,19 +11,19 @@ public interface MachineStore extends FileSystemStore, ShellStore {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public default InputStream openInput(String file) throws Exception {
|
public default InputStream openInput(String file) throws Exception {
|
||||||
return create().commandListFunction(proc -> proc.getShellType().createFileReadCommand(proc.getOsType().normalizeFileName(file)))
|
return create().command(proc -> proc.getShellType().flatten(proc.getShellType().createFileReadCommand(proc.getOsType().normalizeFileName(file))))
|
||||||
.startExternalStdout();
|
.startExternalStdout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public default OutputStream openOutput(String file) throws Exception {
|
public default OutputStream openOutput(String file) throws Exception {
|
||||||
return create().commandFunction(proc -> proc.getShellType().createFileWriteCommand(proc.getOsType().normalizeFileName(file)))
|
return create().command(proc -> proc.getShellType().createFileWriteCommand(proc.getOsType().normalizeFileName(file)))
|
||||||
.startExternalStdin();
|
.startExternalStdin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public default boolean exists(String file) throws Exception {
|
public default boolean exists(String file) throws Exception {
|
||||||
try (var pc = create().commandFunction(proc -> proc.getShellType().createFileExistsCommand(proc.getOsType().normalizeFileName(file)))
|
try (var pc = create().command(proc -> proc.getShellType().createFileExistsCommand(proc.getOsType().normalizeFileName(file)))
|
||||||
.start()) {
|
.start()) {
|
||||||
return pc.discardAndCheckExit();
|
return pc.discardAndCheckExit();
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public interface MachineStore extends FileSystemStore, ShellStore {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public default boolean mkdirs(String file) throws Exception {
|
public default boolean mkdirs(String file) throws Exception {
|
||||||
try (var pc = create().commandListFunction(proc -> proc.getShellType().createMkdirsCommand(proc.getOsType().normalizeFileName(file)))
|
try (var pc = create().command(proc -> proc.getShellType().flatten(proc.getShellType().createMkdirsCommand(proc.getOsType().normalizeFileName(file))))
|
||||||
.start()) {
|
.start()) {
|
||||||
return pc.discardAndCheckExit();
|
return pc.discardAndCheckExit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class CustomComboBoxBuilder<T> {
|
||||||
cb.setButtonCell(new SelectedCell());
|
cb.setButtonCell(new SelectedCell());
|
||||||
SimpleChangeListener.apply(selected, c -> {
|
SimpleChangeListener.apply(selected, c -> {
|
||||||
var item = nodeMap.entrySet().stream()
|
var item = nodeMap.entrySet().stream()
|
||||||
.filter(e -> e.getValue() != null && e.getValue().equals(c))
|
.filter(e -> Objects.equals(c, e.getValue()))
|
||||||
.map(e -> e.getKey())
|
.map(e -> e.getKey())
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
@ -118,7 +118,6 @@ public class CustomComboBoxBuilder<T> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (filterPredicate != null) {
|
if (filterPredicate != null) {
|
||||||
|
|
||||||
SimpleChangeListener.apply(filterString, c -> {
|
SimpleChangeListener.apply(filterString, c -> {
|
||||||
var filteredNodes = nodes.stream()
|
var filteredNodes = nodes.stream()
|
||||||
.filter(e -> e.equals(cb.getValue())
|
.filter(e -> e.equals(cb.getValue())
|
||||||
|
|
Loading…
Reference in a new issue