diff --git a/app/src/main/java/io/xpipe/app/terminal/TabbyTerminalType.java b/app/src/main/java/io/xpipe/app/terminal/TabbyTerminalType.java index cffade904..81b44dea7 100644 --- a/app/src/main/java/io/xpipe/app/terminal/TabbyTerminalType.java +++ b/app/src/main/java/io/xpipe/app/terminal/TabbyTerminalType.java @@ -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() { 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 6dbe1bc2f..d02d0fded 100644 --- a/app/src/main/java/io/xpipe/app/util/ScriptHelper.java +++ b/app/src/main/java/io/xpipe/app/util/ScriptHelper.java @@ -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 init, - String toExecuteInShell, + List preInit, + List 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(); diff --git a/app/src/main/java/io/xpipe/app/util/TerminalLauncher.java b/app/src/main/java/io/xpipe/app/util/TerminalLauncher.java index 28ff57e91..984e0cceb 100644 --- a/app/src/main/java/io/xpipe/app/util/TerminalLauncher.java +++ b/app/src/main/java/io/xpipe/app/util/TerminalLauncher.java @@ -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()