More init script rework

This commit is contained in:
crschnick 2024-04-21 12:56:12 +00:00
parent a87cbb2344
commit 10d1382327
3 changed files with 31 additions and 9 deletions

View file

@ -4,6 +4,7 @@ import io.xpipe.app.util.LocalShell;
import io.xpipe.app.util.WindowsRegistry;
import io.xpipe.core.process.CommandBuilder;
import io.xpipe.core.process.ShellDialects;
import io.xpipe.core.process.TerminalInitFunction;
import java.nio.file.Path;
import java.util.Optional;
@ -33,6 +34,27 @@ public interface TabbyTerminalType extends ExternalTerminalType {
return true;
}
@Override
default TerminalInitFunction additionalInitCommands() {
// return TerminalInitFunction.of(sc -> {
// if (sc.getShellDialect() == ShellDialects.ZSH) {
// return "export PS1=\"$PS1\\[\\e]1337;CurrentDir=\"'$(pwd)\\a\\]'";
// }
// if (sc.getShellDialect() == ShellDialects.BASH) {
// return "precmd () { echo -n \"\\x1b]1337;CurrentDir=$(pwd)\\x07\" }";
// }
// if (sc.getShellDialect() == ShellDialects.FISH) {
// return """
// function __tabby_working_directory_reporting --on-event fish_prompt
// echo -en "\\e]1337;CurrentDir=$PWD\\x7"
// end
// """;
// }
// return null;
// });
return null;
}
static class Windows extends ExternalTerminalType.WindowsType implements TabbyTerminalType {
public Windows() {

View file

@ -10,6 +10,7 @@ import lombok.SneakyThrows;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.stream.Collectors;
public class ScriptHelper {
@ -31,8 +32,8 @@ public class ScriptHelper {
ShellDialect t,
ShellControl processControl,
WorkingDirectoryFunction workingDirectory,
List<String> init,
String toExecuteInShell,
List<String> preInit,
List<String> postInit,
TerminalInitScriptConfig config,
boolean exit)
throws Exception {
@ -44,6 +45,9 @@ public class ScriptHelper {
content += clear + nl;
}
// Normalize line endings
content += nl + preInit.stream().flatMap(s -> s.lines()).collect(Collectors.joining(nl)) + nl;
var applyRcCommand = t.applyRcFileCommand();
if (applyRcCommand != null) {
content += nl + applyRcCommand + nl;
@ -67,12 +71,8 @@ public class ScriptHelper {
}
}
content += nl + String.join(nl, init.stream().filter(s -> s != null).toList()) + nl;
if (toExecuteInShell != null) {
// Normalize line endings
content += String.join(nl, toExecuteInShell.lines().toList()) + nl;
}
// Normalize line endings
content += nl + postInit.stream().flatMap(s -> s.lines()).collect(Collectors.joining(nl)) + nl;
if (exit) {
content += nl + t.getPassthroughExitCommand();

View file

@ -27,7 +27,7 @@ public class TerminalLauncher {
sc,
WorkingDirectoryFunction.none(),
List.of(),
command.apply(sc),
List.of(command.apply(sc)),
new TerminalInitScriptConfig(
title,
type.shouldClear()