Add custom title to opened terminal windows

This commit is contained in:
crschnick 2023-05-07 23:58:19 +00:00
parent 0845c7e27d
commit 7b36c1a96b
11 changed files with 20 additions and 13 deletions

View file

@ -83,7 +83,7 @@ final class FileContextMenu extends ContextMenu {
if (e != null) {
pc.executeSimpleBooleanCommand(e);
}
var cmd = pc.command("\"" + entry.getPath() + "\"").prepareTerminalOpen();
var cmd = pc.command("\"" + entry.getPath() + "\"").prepareTerminalOpen("?");
TerminalHelper.open(FilenameUtils.getBaseName(entry.getPath()), cmd);
});
event.consume();

View file

@ -6,6 +6,7 @@ import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.util.BusyProperty;
import io.xpipe.app.util.TerminalHelper;
import io.xpipe.app.util.ThreadHelper;
import io.xpipe.app.util.XPipeDaemon;
import io.xpipe.core.impl.FileNames;
import io.xpipe.core.store.ConnectionFileSystem;
import io.xpipe.core.store.FileSystem;
@ -277,7 +278,7 @@ final class OpenFileSystemModel {
var connection = ((ConnectionFileSystem) fileSystem).getShellControl();
var command = s.control()
.initWith(connection.getShellDialect().getCdCommand(directory))
.prepareTerminalOpen();
.prepareTerminalOpen(directory + " - " + XPipeDaemon.getInstance().getStoreName(store.getValue()).orElse("?"));
TerminalHelper.open(directory, command);
}
});

View file

@ -14,7 +14,7 @@ public class LaunchExchangeImpl extends LaunchExchange
public Response handleRequest(BeaconHandler handler, Request msg) throws Exception {
var store = getStoreEntryByName(msg.getName(), false);
if (store.getStore() instanceof LaunchableStore s) {
var command = s.prepareLaunchCommand();
var command = s.prepareLaunchCommand(store.getName());
var split = CommandLine.parse(command);
return Response.builder().command(List.of(split.toStrings())).build();
}

View file

@ -39,11 +39,15 @@ public class ScriptHelper {
}
public static String constructInitFile(
ShellControl processControl, List<String> init, String toExecuteInShell, boolean login) {
ShellControl processControl, List<String> init, String toExecuteInShell, boolean login, String displayName) {
ShellDialect t = processControl.getShellDialect();
String nl = t.getNewLine().getNewLineString();
var content = String.join(nl, init.stream().filter(s -> s != null).toList()) + nl;
if (displayName != null) {
content = t.changeTitleCommand(displayName) + "\n" + content;
}
if (login) {
var applyProfilesCommand = t.applyProfileFilesCommand();
if (applyProfilesCommand != null) {

View file

@ -9,7 +9,7 @@ import java.io.IOException;
public class TerminalHelper {
public static void open(String title, CommandControl cc) throws Exception {
var command = cc.prepareTerminalOpen();
var command = cc.prepareTerminalOpen(title);
open(title, command);
}

View file

@ -17,7 +17,7 @@ public interface ProcessControl extends Closeable, AutoCloseable {
ProcessControl sensitive();
String prepareTerminalOpen() throws Exception;
String prepareTerminalOpen(String displayName) throws Exception;
void closeStdin() throws IOException;

View file

@ -21,9 +21,9 @@ public interface ShellControl extends ProcessControl {
ShellControl withMessageFormatter(Function<String, String> formatter);
String prepareTerminalOpen() throws Exception;
String prepareTerminalOpen(String displayName) throws Exception;
String prepareIntermediateTerminalOpen(String content) throws Exception;
String prepareIntermediateTerminalOpen(String content, String displayName) throws Exception;
String getTemporaryDirectory() throws Exception;

View file

@ -28,6 +28,8 @@ public interface ShellDialect {
return null;
}
String changeTitleCommand(String newTitle);
default String applyProfileFilesCommand() {
return null;
}

View file

@ -5,8 +5,8 @@ import io.xpipe.core.process.CommandControl;
public interface CommandExecutionStore extends DataStore, LaunchableStore {
@Override
default String prepareLaunchCommand() throws Exception {
return create().prepareTerminalOpen();
default String prepareLaunchCommand(String displayName) throws Exception {
return create().prepareTerminalOpen(displayName);
}
CommandControl create() throws Exception;

View file

@ -2,5 +2,5 @@ package io.xpipe.core.store;
public interface LaunchableStore extends DataStore {
String prepareLaunchCommand() throws Exception;
String prepareLaunchCommand(String displayName) throws Exception;
}

View file

@ -23,8 +23,8 @@ public interface ShellStore extends DataStore, StatefulDataStore, LaunchableStor
}
@Override
default String prepareLaunchCommand() throws Exception {
return control().prepareTerminalOpen();
default String prepareLaunchCommand(String displayName) throws Exception {
return control().prepareTerminalOpen(displayName);
}
default ShellControl control() {