mirror of
https://github.com/xpipe-io/xpipe.git
synced 2025-04-17 01:33:36 +00:00
Rework prompts
This commit is contained in:
parent
312368ed7d
commit
b9ac594d55
10 changed files with 363 additions and 69 deletions
|
@ -19,9 +19,6 @@ import java.nio.file.Path;
|
|||
|
||||
public class ClinkHelper {
|
||||
|
||||
private static String downloadUrl = null;
|
||||
private static Path downloadFile = null;
|
||||
|
||||
public static FilePath getTargetDir(ShellControl sc) throws Exception {
|
||||
var targetDir = ShellTemp.createUserSpecificTempDataDirectory(sc, null).join("bin", "clink");
|
||||
return targetDir;
|
||||
|
@ -42,16 +39,13 @@ public class ClinkHelper {
|
|||
var temp = GithubReleaseDownloader.getDownloadTempFile("chrisant996/clink", "clink.zip", name -> name.endsWith(".zip") && !name.endsWith("symbols.zip"));
|
||||
try (var fs = FileSystems.newFileSystem(temp)) {
|
||||
var exeFile = fs.getPath("clink_x64.exe");
|
||||
var exeBytes = Files.readAllBytes(exeFile);
|
||||
sc.view().writeStreamFile(targetDir.join("clink_x64.exe"), new ByteArrayInputStream(exeBytes), exeBytes.length);
|
||||
sc.view().transferLocalFile(exeFile, targetDir.join("clink_x64.exe"));
|
||||
|
||||
var batFile = fs.getPath("clink.bat");
|
||||
var batBytes = Files.readAllBytes(batFile);
|
||||
sc.view().writeStreamFile(targetDir.join("clink.bat"), new ByteArrayInputStream(batBytes), batBytes.length);
|
||||
sc.view().transferLocalFile(batFile, targetDir.join("clink.bat"));
|
||||
|
||||
var dllFile = fs.getPath("clink_dll_x64.dll");
|
||||
var dllBytes = Files.readAllBytes(dllFile);
|
||||
sc.view().writeStreamFile(targetDir.join("clink_dll_x64.dll"), new ByteArrayInputStream(dllBytes), dllBytes.length);
|
||||
sc.view().transferLocalFile(dllFile, targetDir.join("clink_dll_x64.dll"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ import java.util.function.Function;
|
|||
@SuperBuilder
|
||||
public abstract class ConfigFileTerminalPrompt implements TerminalPrompt {
|
||||
|
||||
protected static <T extends ConfigFileTerminalPrompt> OptionsBuilder createOptions(Property<T> p, String extension, Function<String, T> creator) {
|
||||
protected static <T extends ConfigFileTerminalPrompt> OptionsBuilder createOptions(Property<T> p, Function<String, T> creator) {
|
||||
var prop = new SimpleObjectProperty<>(p.getValue() != null ? p.getValue().configuration : null);
|
||||
return new OptionsBuilder()
|
||||
.nameAndDescription("terminalPromptConfig")
|
||||
.addComp(new IntegratedTextAreaComp(prop, false, p.getValue() != null ? p.getValue().getId() : "config",
|
||||
new SimpleStringProperty(extension)).prefHeight(400), prop)
|
||||
new SimpleStringProperty(p.getValue() != null ? p.getValue().getConfigFileExtension() : null)).prefHeight(400), prop)
|
||||
.bind(
|
||||
() -> {
|
||||
return creator.apply(prop.getValue());
|
||||
|
@ -34,9 +34,9 @@ public abstract class ConfigFileTerminalPrompt implements TerminalPrompt {
|
|||
|
||||
protected String configuration;
|
||||
|
||||
protected abstract FilePath prepareCustomConfigFile(ShellControl sc) throws Exception;
|
||||
|
||||
protected abstract FilePath getDefaultConfigFile(ShellControl sc) throws Exception;
|
||||
protected void prepareCustomConfigFile(ShellControl sc, FilePath file) throws Exception {
|
||||
sc.view().writeTextFile(file, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShellTerminalInitCommand terminalCommand() throws Exception {
|
||||
|
@ -47,11 +47,12 @@ public abstract class ConfigFileTerminalPrompt implements TerminalPrompt {
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
FilePath configFile;
|
||||
FilePath configFile = getTargetConfigFile(shellControl);
|
||||
if (configuration == null || configuration.isBlank()) {
|
||||
configFile = getDefaultConfigFile(shellControl);
|
||||
shellControl.view().deleteFileIfPossible(configFile);
|
||||
configFile = null;
|
||||
} else {
|
||||
configFile = prepareCustomConfigFile(shellControl);
|
||||
prepareCustomConfigFile(shellControl, configFile);
|
||||
shellControl.view().writeTextFile(configFile, configuration);
|
||||
}
|
||||
|
||||
|
@ -66,5 +67,12 @@ public abstract class ConfigFileTerminalPrompt implements TerminalPrompt {
|
|||
};
|
||||
}
|
||||
|
||||
protected FilePath getTargetConfigFile(ShellControl shellControl) throws Exception {
|
||||
FilePath configFile = getConfigurationDirectory(shellControl).join(getId() + "." + getConfigFileExtension());
|
||||
return configFile;
|
||||
}
|
||||
|
||||
protected abstract String getConfigFileExtension();
|
||||
|
||||
protected abstract ShellScript setupTerminalCommand(ShellControl shellControl, FilePath config) throws Exception;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import lombok.ToString;
|
|||
import lombok.experimental.SuperBuilder;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.nio.file.FileSystems;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -19,21 +20,114 @@ import java.util.List;
|
|||
@SuperBuilder
|
||||
@ToString
|
||||
@Jacksonized
|
||||
@JsonTypeName("starship")
|
||||
@JsonTypeName("ohmyposh")
|
||||
public class OhMyPoshTerminalPrompt extends ConfigFileTerminalPrompt {
|
||||
|
||||
public static OptionsBuilder createOptions(Property<OhMyPoshTerminalPrompt> p) {
|
||||
return createOptions(p, "toml", s -> OhMyPoshTerminalPrompt.builder().configuration(s).build());
|
||||
return createOptions(p, s -> OhMyPoshTerminalPrompt.builder().configuration(s).build());
|
||||
}
|
||||
|
||||
public static OhMyPoshTerminalPrompt createDefault() {
|
||||
return OhMyPoshTerminalPrompt.builder().configuration(
|
||||
"""
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
|
||||
"blocks": [
|
||||
{
|
||||
"segments": [
|
||||
{
|
||||
"foreground": "#007ACC",
|
||||
"template": " {{ .CurrentDate | date .Format }} ",
|
||||
"properties": {
|
||||
"time_format": "15:04:05"
|
||||
},
|
||||
"style": "plain",
|
||||
"type": "time"
|
||||
}
|
||||
],
|
||||
"type": "rprompt"
|
||||
},
|
||||
{
|
||||
"alignment": "left",
|
||||
"newline": true,
|
||||
"segments": [
|
||||
{
|
||||
"background": "#ffb300",
|
||||
"foreground": "#ffffff",
|
||||
"leading_diamond": "",
|
||||
"template": " {{ .UserName }} ",
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "",
|
||||
"type": "session"
|
||||
},
|
||||
{
|
||||
"background": "#61AFEF",
|
||||
"foreground": "#ffffff",
|
||||
"powerline_symbol": "",
|
||||
"template": " {{ .Path }} ",
|
||||
"properties": {
|
||||
"style": "folder"
|
||||
},
|
||||
"exclude_folders": [
|
||||
"/super/secret/project"
|
||||
],
|
||||
"style": "powerline",
|
||||
"type": "path"
|
||||
},
|
||||
{
|
||||
"background": "#2e9599",
|
||||
"background_templates": [
|
||||
"{{ if or (.Working.Changed) (.Staging.Changed) }}#f36943{{ end }}",
|
||||
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}#a8216b{{ end }}",
|
||||
"{{ if gt .Ahead 0 }}#35b5ff{{ end }}",
|
||||
"{{ if gt .Behind 0 }}#f89cfa{{ end }}"
|
||||
],
|
||||
"foreground": "#193549",
|
||||
"foreground_templates": [
|
||||
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}#ffffff{{ end }}"
|
||||
],
|
||||
"powerline_symbol": "",
|
||||
"template": " {{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }} ",
|
||||
"properties": {
|
||||
"branch_template": "{{ trunc 25 .Branch }}",
|
||||
"fetch_status": true
|
||||
},
|
||||
"style": "powerline",
|
||||
"type": "git"
|
||||
},
|
||||
{
|
||||
"background": "#00897b",
|
||||
"background_templates": [
|
||||
"{{ if gt .Code 0 }}#e91e63{{ end }}"
|
||||
],
|
||||
"foreground": "#ffffff",
|
||||
"template": "<parentBackground></> ",
|
||||
"properties": {
|
||||
"always_enabled": true
|
||||
},
|
||||
"style": "diamond",
|
||||
"trailing_diamond": "",
|
||||
"type": "status"
|
||||
}
|
||||
],
|
||||
"type": "prompt"
|
||||
}
|
||||
],
|
||||
"final_space": true,
|
||||
"version": 3
|
||||
}
|
||||
"""
|
||||
).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDocsLink() {
|
||||
return "https://starship.rs/guide/";
|
||||
return "https://ohmyposh.dev/docs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "starship";
|
||||
return "oh-my-posh";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,12 +143,12 @@ public class OhMyPoshTerminalPrompt extends ConfigFileTerminalPrompt {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (sc.view().findProgram("starship").isPresent()) {
|
||||
if (sc.view().findProgram("oh-my-posh").isPresent()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var extension = OsType.getLocal() == OsType.WINDOWS ? ".exe" : "";
|
||||
return sc.view().fileExists(getBinaryDirectory(sc).join("starship" + extension));
|
||||
return sc.view().fileExists(getBinaryDirectory(sc).join("oh-my-posh" + extension));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,7 +157,7 @@ public class OhMyPoshTerminalPrompt extends ConfigFileTerminalPrompt {
|
|||
ClinkHelper.install(sc);
|
||||
var configDir = getConfigurationDirectory(sc);
|
||||
sc.view().mkdir(configDir);
|
||||
sc.view().writeTextFile(configDir.join("starship.lua"), "load(io.popen('starship init cmd'):read(\"*a\"))()");
|
||||
sc.view().writeTextFile(configDir.join("oh-my-posh.lua"), "load(io.popen('oh-my-posh init cmd'):read(\"*a\"))()");
|
||||
}
|
||||
|
||||
var dir = getBinaryDirectory(sc);
|
||||
|
@ -73,39 +167,34 @@ public class OhMyPoshTerminalPrompt extends ConfigFileTerminalPrompt {
|
|||
"JanDeDobbeleer/oh-my-posh",
|
||||
"posh-windows-amd64.exe",
|
||||
s -> s.equals("posh-windows-amd64.exe"));
|
||||
sc.view().transferLocalFile(file, dir.join("starship.exe"));
|
||||
sc.view().transferLocalFile(file, dir.join("oh-my-posh.exe"));
|
||||
} else {
|
||||
sc.command("curl -sS https://starship.rs/install.sh | sh /dev/stdin -y --bin-dir \"" + dir + "\" > /dev/null").execute();
|
||||
var configDir = getConfigurationDirectory(sc);
|
||||
sc.command("curl -s https://ohmyposh.dev/install.sh | bash -s -- -d \"" + dir + "\" -t \"" + configDir + "\"").execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePath prepareCustomConfigFile(ShellControl sc) throws Exception {
|
||||
var file = getConfigurationDirectory(sc).join("starship.toml");
|
||||
sc.view().writeTextFile(file, configuration);
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePath getDefaultConfigFile(ShellControl sc) throws Exception {
|
||||
return sc.view().userHome().join(".config").join("starship.toml");
|
||||
protected String getConfigFileExtension() {
|
||||
return "json";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShellScript setupTerminalCommand(ShellControl shellControl, FilePath config) throws Exception {
|
||||
var lines = new ArrayList<String>();
|
||||
if (shellControl.getShellDialect() == ShellDialects.CMD) {
|
||||
lines.add(shellControl.getShellDialect().addToPathVariableCommand(List.of(ClinkHelper.getTargetDir(shellControl).toString()), false));
|
||||
var dialect = shellControl.getOriginalShellDialect();
|
||||
if (dialect == ShellDialects.CMD) {
|
||||
lines.add(dialect.addToPathVariableCommand(List.of(ClinkHelper.getTargetDir(shellControl).toString()), false));
|
||||
}
|
||||
lines.add(shellControl.getShellDialect().getSetEnvironmentVariableCommand("STARSHIP_CONFIG", config.toString()));
|
||||
if (shellControl.getShellDialect() == ShellDialects.CMD) {
|
||||
var configArg = config != null ? " --config \"" + config + "\"" : "";
|
||||
if (dialect == ShellDialects.CMD) {
|
||||
lines.add("clink inject --quiet --profile \"" + getConfigurationDirectory(shellControl) + "\"");
|
||||
} else if (ShellDialects.isPowershell(shellControl)) {
|
||||
lines.add("Invoke-Expression (&starship init powershell)");
|
||||
} else if (shellControl.getShellDialect() == ShellDialects.FISH) {
|
||||
lines.add("starship init fish | source");
|
||||
lines.add("& ([ScriptBlock]::Create((oh-my-posh init $(oh-my-posh get shell) --print" + configArg + ") -join \"`n\"))");
|
||||
} else if (dialect == ShellDialects.FISH) {
|
||||
lines.add("oh-my-posh init fish" + configArg + " | source");
|
||||
} else {
|
||||
lines.add("eval \"$(starship init " + shellControl.getShellDialect().getId() + ")\"");
|
||||
lines.add("eval \"$(oh-my-posh init " + dialect.getId() + configArg + ")\"");
|
||||
}
|
||||
return ShellScript.lines(lines);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
package io.xpipe.app.terminal;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import io.xpipe.app.util.CommandSupport;
|
||||
import io.xpipe.app.util.GithubReleaseDownloader;
|
||||
import io.xpipe.app.util.OptionsBuilder;
|
||||
import io.xpipe.app.util.ShellTemp;
|
||||
import io.xpipe.core.process.*;
|
||||
import io.xpipe.core.store.FilePath;
|
||||
import javafx.beans.property.Property;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@SuperBuilder
|
||||
@ToString
|
||||
@Jacksonized
|
||||
@JsonTypeName("ohmyzsh")
|
||||
public class OhMyZshTerminalPrompt extends ConfigFileTerminalPrompt {
|
||||
|
||||
public static OptionsBuilder createOptions(Property<OhMyZshTerminalPrompt> p) {
|
||||
return createOptions(p, s -> OhMyZshTerminalPrompt.builder().configuration(s).build());
|
||||
}
|
||||
|
||||
public static OhMyZshTerminalPrompt createDefault() {
|
||||
return OhMyZshTerminalPrompt.builder().configuration(
|
||||
"""
|
||||
# Set name of the theme to load --- if set to "random", it will
|
||||
# load a random theme each time Oh My Zsh is loaded, in which case,
|
||||
# to know which specific one was loaded, run: echo $RANDOM_THEME
|
||||
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
|
||||
ZSH_THEME="robbyrussell"
|
||||
|
||||
# Set list of themes to pick from when loading at random
|
||||
# Setting this variable when ZSH_THEME=random will cause zsh to load
|
||||
# a theme from this variable instead of looking in $ZSH/themes/
|
||||
# If set to an empty array, this variable will have no effect.
|
||||
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
|
||||
|
||||
# Uncomment the following line to use case-sensitive completion.
|
||||
# CASE_SENSITIVE="true"
|
||||
|
||||
# Uncomment the following line to use hyphen-insensitive completion.
|
||||
# Case-sensitive completion must be off. _ and - will be interchangeable.
|
||||
# HYPHEN_INSENSITIVE="true"
|
||||
|
||||
# Uncomment one of the following lines to change the auto-update behavior
|
||||
# zstyle ':omz:update' mode disabled # disable automatic updates
|
||||
# zstyle ':omz:update' mode auto # update automatically without asking
|
||||
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
|
||||
|
||||
# Uncomment the following line to change how often to auto-update (in days).
|
||||
# zstyle ':omz:update' frequency 13
|
||||
|
||||
# Uncomment the following line if pasting URLs and other text is messed up.
|
||||
# DISABLE_MAGIC_FUNCTIONS="true"
|
||||
|
||||
# Uncomment the following line to disable colors in ls.
|
||||
# DISABLE_LS_COLORS="true"
|
||||
|
||||
# Uncomment the following line to disable auto-setting terminal title.
|
||||
# DISABLE_AUTO_TITLE="true"
|
||||
|
||||
# Uncomment the following line to enable command auto-correction.
|
||||
# ENABLE_CORRECTION="true"
|
||||
|
||||
# Uncomment the following line to display red dots whilst waiting for completion.
|
||||
# You can also set it to another string to have that shown instead of the default red dots.
|
||||
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
|
||||
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
|
||||
# COMPLETION_WAITING_DOTS="true"
|
||||
|
||||
# Uncomment the following line if you want to disable marking untracked files
|
||||
# under VCS as dirty. This makes repository status check for large repositories
|
||||
# much, much faster.
|
||||
# DISABLE_UNTRACKED_FILES_DIRTY="true"
|
||||
|
||||
# Uncomment the following line if you want to change the command execution time
|
||||
# stamp shown in the history command output.
|
||||
# You can set one of the optional three formats:
|
||||
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
|
||||
# or set a custom format using the strftime function format specifications,
|
||||
# see 'man strftime' for details.
|
||||
# HIST_STAMPS="mm/dd/yyyy"
|
||||
|
||||
# Would you like to use another custom folder than $ZSH/custom?
|
||||
# ZSH_CUSTOM=/path/to/new-custom-folder
|
||||
|
||||
# Which plugins would you like to load?
|
||||
# Standard plugins can be found in $ZSH/plugins/
|
||||
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
|
||||
# Example format: plugins=(rails git textmate ruby lighthouse)
|
||||
# Add wisely, as too many plugins slow down shell startup.
|
||||
plugins=(git)
|
||||
"""
|
||||
).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDocsLink() {
|
||||
return "https://github.com/ohmyzsh/ohmyzsh";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "oh-my-zsh";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FilePath getTargetConfigFile(ShellControl shellControl) throws Exception {
|
||||
FilePath configFile = getConfigurationDirectory(shellControl).join(getId() + "-custom." + getConfigFileExtension());
|
||||
return configFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkCanInstall(ShellControl sc) throws Exception {
|
||||
CommandSupport.isInPathOrThrow(sc, "curl");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkIfInstalled(ShellControl sc) throws Exception {
|
||||
var configDir = getConfigurationDirectory(sc);
|
||||
return sc.view().fileExists(configDir.join("oh-my-zsh.sh"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install(ShellControl sc) throws Exception {
|
||||
var configDir = getConfigurationDirectory(sc);
|
||||
sc.view().deleteDirectory(configDir);
|
||||
sc.command("KEEP_ZSHRC=yes ZSH=\"" + configDir + "\" sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\" \"\" --unattended").execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfigFileExtension() {
|
||||
return "sh";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShellScript setupTerminalCommand(ShellControl shellControl, FilePath config) throws Exception {
|
||||
var script = config != null ? shellControl.view().readTextFile(config) : "";
|
||||
var fixed = script != null ? script.replaceAll("source \\$ZSH/oh-my-zsh.sh", "")
|
||||
.replaceAll("export ZSH=\"\\$HOME/.oh-my-zsh\"", "") : null;
|
||||
return ShellScript.lines("export ZSH=\"" + getConfigurationDirectory(shellControl) + "\"", fixed, "source $ZSH/oh-my-zsh.sh");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ShellDialect> getSupportedDialects() {
|
||||
return List.of(ShellDialects.ZSH);
|
||||
}
|
||||
}
|
|
@ -25,7 +25,32 @@ import java.util.List;
|
|||
public class StarshipTerminalPrompt extends ConfigFileTerminalPrompt {
|
||||
|
||||
public static OptionsBuilder createOptions(Property<StarshipTerminalPrompt> p) {
|
||||
return createOptions(p, "toml", s -> StarshipTerminalPrompt.builder().configuration(s).build());
|
||||
return createOptions(p, s -> StarshipTerminalPrompt.builder().configuration(s).build());
|
||||
}
|
||||
|
||||
public static StarshipTerminalPrompt createDefault() {
|
||||
return StarshipTerminalPrompt.builder().configuration(
|
||||
"""
|
||||
# Get editor completions based on the config schema
|
||||
"$schema" = 'https://starship.rs/config-schema.json'
|
||||
|
||||
# Inserts a blank line between shell prompts
|
||||
add_newline = true
|
||||
|
||||
# Replace the '❯' symbol in the prompt with '➜'
|
||||
[character] # The name of the module we are configuring is 'character'
|
||||
success_symbol = '[➜](bold green)' # The 'success_symbol' segment is being set to '➜' with the color 'bold green'
|
||||
|
||||
# Disable the package module, hiding it from the prompt completely
|
||||
[package]
|
||||
disabled = true
|
||||
"""
|
||||
).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfigFileExtension() {
|
||||
return "toml";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,37 +104,28 @@ public class StarshipTerminalPrompt extends ConfigFileTerminalPrompt {
|
|||
sc.view().transferLocalFile(exeFile, dir.join("starship.exe"));
|
||||
}
|
||||
} else {
|
||||
sc.command("curl -sS https://starship.rs/install.sh | sh /dev/stdin -y --bin-dir \"" + dir + "\" > /dev/null").execute();
|
||||
sc.command("curl -sS https://starship.rs/install.sh | sh /dev/stdin -y --bin-dir \"" + dir + "\"").execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePath prepareCustomConfigFile(ShellControl sc) throws Exception {
|
||||
var file = getConfigurationDirectory(sc).join("starship.toml");
|
||||
sc.view().writeTextFile(file, configuration);
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilePath getDefaultConfigFile(ShellControl sc) throws Exception {
|
||||
return sc.view().userHome().join(".config").join("starship.toml");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShellScript setupTerminalCommand(ShellControl shellControl, FilePath config) throws Exception {
|
||||
var lines = new ArrayList<String>();
|
||||
if (shellControl.getShellDialect() == ShellDialects.CMD) {
|
||||
lines.add(shellControl.getShellDialect().addToPathVariableCommand(List.of(ClinkHelper.getTargetDir(shellControl).toString()), false));
|
||||
var dialect = shellControl.getOriginalShellDialect();
|
||||
if (dialect == ShellDialects.CMD) {
|
||||
lines.add(dialect.addToPathVariableCommand(List.of(ClinkHelper.getTargetDir(shellControl).toString()), false));
|
||||
}
|
||||
lines.add(shellControl.getShellDialect().getSetEnvironmentVariableCommand("STARSHIP_CONFIG", config.toString()));
|
||||
if (shellControl.getShellDialect() == ShellDialects.CMD) {
|
||||
if (config != null) {
|
||||
lines.add(dialect.getSetEnvironmentVariableCommand("STARSHIP_CONFIG", config.toString()));
|
||||
}
|
||||
if (dialect == ShellDialects.CMD) {
|
||||
lines.add("clink inject --quiet --profile \"" + getConfigurationDirectory(shellControl) + "\"");
|
||||
} else if (ShellDialects.isPowershell(shellControl)) {
|
||||
lines.add("Invoke-Expression (&starship init powershell)");
|
||||
} else if (shellControl.getShellDialect() == ShellDialects.FISH) {
|
||||
} else if (dialect == ShellDialects.FISH) {
|
||||
lines.add("starship init fish | source");
|
||||
} else {
|
||||
lines.add("eval \"$(starship init " + shellControl.getShellDialect().getId() + ")\"");
|
||||
lines.add("eval \"$(starship init " + dialect.getId() + ")\"");
|
||||
}
|
||||
return ShellScript.lines(lines);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ public interface TerminalPrompt {
|
|||
static List<Class<?>> getClasses() {
|
||||
var l = new ArrayList<Class<?>>();
|
||||
l.add(StarshipTerminalPrompt.class);
|
||||
l.add(OhMyPoshTerminalPrompt.class);
|
||||
l.add(OhMyZshTerminalPrompt.class);
|
||||
return l;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,17 @@ public class OptionsChoiceBuilder {
|
|||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return new OptionsBuilder();
|
||||
}
|
||||
|
||||
private static Object createDefaultInstanceForClass(Class<?> c) {
|
||||
try {
|
||||
var cd = c.getDeclaredMethod("createDefault");
|
||||
cd.setAccessible(true);
|
||||
var defValue = cd.invoke(null);
|
||||
return defValue;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
var bm = c.getDeclaredMethod("builder");
|
||||
|
@ -48,17 +59,16 @@ public class OptionsChoiceBuilder {
|
|||
var m = b.getClass().getDeclaredMethod("build");
|
||||
m.setAccessible(true);
|
||||
var defValue = c.cast(m.invoke(b));
|
||||
var def = new OptionsBuilder().bind(() -> defValue, property);
|
||||
return def;
|
||||
return defValue;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
var defConstructor = c.getDeclaredConstructor();
|
||||
var defValue = defConstructor.newInstance();
|
||||
return new OptionsBuilder().bind(() -> defValue, property);
|
||||
return defValue;
|
||||
} catch (Exception e) {
|
||||
return new OptionsBuilder();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +96,7 @@ public class OptionsChoiceBuilder {
|
|||
}
|
||||
for (int i = 0; i < sub.size(); i++) {
|
||||
var compatible = sub.get(i).isInstance(s.getValue());
|
||||
properties.add(new SimpleObjectProperty<>(compatible ? s.getValue() : null));
|
||||
properties.add(new SimpleObjectProperty<>(compatible ? s.getValue() : createDefaultInstanceForClass(sub.get(i))));
|
||||
}
|
||||
|
||||
property.addListener((obs, oldValue, newValue) -> {
|
||||
|
|
|
@ -68,6 +68,24 @@ public class ShellView {
|
|||
.executeAndCheck();
|
||||
}
|
||||
|
||||
public void deleteDirectory(FilePath path) throws Exception {
|
||||
getDialect()
|
||||
.deleteFileOrDirectory(shellControl, path.toString())
|
||||
.execute();
|
||||
}
|
||||
|
||||
public void deleteFile(FilePath path) throws Exception {
|
||||
getDialect()
|
||||
.getFileDeleteCommand(shellControl, path.toString())
|
||||
.execute();
|
||||
}
|
||||
|
||||
public void deleteFileIfPossible(FilePath path) throws Exception {
|
||||
getDialect()
|
||||
.getFileDeleteCommand(shellControl, path.toString())
|
||||
.executeAndCheck();
|
||||
}
|
||||
|
||||
public void mkdir(FilePath path) throws Exception {
|
||||
shellControl.command(getDialect()
|
||||
.getMkdirsCommand(path.toString()))
|
||||
|
|
2
lang/strings/fixed_en.properties
generated
2
lang/strings/fixed_en.properties
generated
|
@ -121,3 +121,5 @@ zellij=zellij
|
|||
tmux=tmux
|
||||
onePassword=1Password
|
||||
starship=Starship
|
||||
ohmyposh=Oh My Posh
|
||||
ohmyzsh=Oh My Zsh
|
||||
|
|
2
lang/strings/translations_en.properties
generated
2
lang/strings/translations_en.properties
generated
|
@ -1381,7 +1381,7 @@ refreshOpenpubkey=Refresh openpubkey identity
|
|||
refreshOpenpubkeyDescription=Run opkssh refresh to make the openpubkey identity valid again
|
||||
all=All
|
||||
terminalPrompt=Terminal prompt
|
||||
terminalPromptDescription=The terminal prompt tool to use in your remote terminals.\n\nEnabling a terminal prompt will automatically set up and configure the prompt tool on the target system when opening a terminal session. This will increase the terminal loading time for the first time while the prompt is being set up on the remote system.
|
||||
terminalPromptDescription=The terminal prompt tool to use in your remote terminals.\n\nEnabling a terminal prompt will automatically set up and configure the prompt tool on the target system when opening a terminal session. This does not modify any existing prompt configurations or profile files on a system.\n\nThis will increase the terminal loading time for the first time while the prompt is being set up on the remote system.
|
||||
terminalPromptConfiguration=Terminal prompt configuration
|
||||
terminalPromptConfig=Config file
|
||||
terminalPromptConfigDescription=The custom config file to apply to the prompt. This config will be automatically set up on the target system when the terminal is initialized and used as the default prompt config.\n\nIf you want to use the existing default config file on each system, you can leave this field empty.
|
||||
|
|
Loading…
Add table
Reference in a new issue