mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-22 15:40:31 -04:00
Scripting rework
This commit is contained in:
@@ -28,6 +28,26 @@ public interface ShellStore extends DataStore, FileSystemStore, ValidatableStore
|
||||
return new StubShellControl(getSession().getShellControl());
|
||||
}
|
||||
|
||||
default boolean checkSessionAlive() {
|
||||
var session = getSession();
|
||||
if (session == null || !session.isRunning()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
session.getShellControl().command(" echo xpipetest").execute();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
ErrorEvent.fromThrowable(e).expected().omit().handle();
|
||||
try {
|
||||
stopSessionIfNeeded();
|
||||
} catch (Exception se) {
|
||||
ErrorEvent.fromThrowable(se).expected().omit().handle();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default ShellSession newSession() throws Exception {
|
||||
var func = shellFunction();
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.xpipe.app.terminal;
|
||||
|
||||
import io.xpipe.app.comp.base.ButtonComp;
|
||||
import io.xpipe.app.comp.base.IntegratedTextAreaComp;
|
||||
import io.xpipe.app.core.AppI18n;
|
||||
import io.xpipe.app.password.KeePassXcAssociationKey;
|
||||
import io.xpipe.app.password.KeePassXcManager;
|
||||
import io.xpipe.app.util.OptionsBuilder;
|
||||
import io.xpipe.app.util.ThreadHelper;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellTerminalInitCommand;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@SuperBuilder
|
||||
public abstract class ConfigFileTerminalPrompt implements TerminalPrompt {
|
||||
|
||||
protected static OptionsBuilder createOptions(Property<ConfigFileTerminalPrompt> p, String extension, Function<String, ConfigFileTerminalPrompt> creator) {
|
||||
var prop = new SimpleObjectProperty<String>();
|
||||
return new OptionsBuilder()
|
||||
.nameAndDescription("configuration")
|
||||
.addComp(new IntegratedTextAreaComp(prop, false, "config", new SimpleStringProperty(extension)), prop)
|
||||
.bind(
|
||||
() -> {
|
||||
return creator.apply(prop.getValue());
|
||||
},
|
||||
p);
|
||||
}
|
||||
|
||||
protected String configuration;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package io.xpipe.app.terminal;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellTerminalInitCommand;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
@Getter
|
||||
@SuperBuilder
|
||||
@ToString
|
||||
@Jacksonized
|
||||
@JsonTypeName("starship")
|
||||
public class StarshipTerminalPrompt extends ConfigFileTerminalPrompt {
|
||||
|
||||
@Override
|
||||
public String getDocsLink() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkSupported(ShellControl sc) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShellTerminalInitCommand setup(ShellControl shellControl) throws Exception {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
31
app/src/main/java/io/xpipe/app/terminal/TerminalPrompt.java
Normal file
31
app/src/main/java/io/xpipe/app/terminal/TerminalPrompt.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package io.xpipe.app.terminal;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import io.xpipe.core.process.ShellControl;
|
||||
import io.xpipe.core.process.ShellScript;
|
||||
import io.xpipe.core.process.ShellTerminalInitCommand;
|
||||
import io.xpipe.core.process.TerminalInitScriptConfig;
|
||||
import io.xpipe.core.util.ValidationException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
public interface TerminalPrompt {
|
||||
|
||||
static List<Class<?>> getClasses() {
|
||||
var l = new ArrayList<Class<?>>();
|
||||
l.add(TmuxTerminalMultiplexer.class);
|
||||
l.add(ZellijTerminalMultiplexer.class);
|
||||
l.add(ScreenTerminalMultiplexer.class);
|
||||
return l;
|
||||
}
|
||||
|
||||
default void checkComplete() throws ValidationException {}
|
||||
|
||||
String getDocsLink();
|
||||
|
||||
void checkSupported(ShellControl sc) throws Exception;
|
||||
|
||||
ShellTerminalInitCommand setup(ShellControl shellControl) throws Exception;
|
||||
}
|
||||
@@ -190,6 +190,8 @@ public interface ShellControl extends ProcessControl {
|
||||
|
||||
ShellControl withInitSnippet(ShellTerminalInitCommand snippet);
|
||||
|
||||
Optional<ShellControl> getActiveReplacementBackgroundSession() throws Exception;
|
||||
|
||||
default ShellControl subShell(@NonNull ShellDialect type) {
|
||||
var o = new ShellOpenFunction() {
|
||||
|
||||
|
||||
@@ -343,6 +343,11 @@ public class WrapperShellControl implements ShellControl {
|
||||
return parent.withInitSnippet(snippet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ShellControl> getActiveReplacementBackgroundSession() throws Exception {
|
||||
return parent.getActiveReplacementBackgroundSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ShellControl subShell() {
|
||||
return parent.subShell();
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface ShellStoreProvider extends DataStoreProvider {
|
||||
public void execute() throws Exception {
|
||||
var replacement = ProcessControlProvider.get().replace(entry.ref());
|
||||
ShellStore store = replacement.getStore().asNeeded();
|
||||
var control = ScriptStoreSetup.controlWithDefaultScripts(store.tempControl());
|
||||
var control = ScriptStoreSetup.controlWithDefaultScripts(store.standaloneControl());
|
||||
TerminalLauncher.open(
|
||||
replacement.get(),
|
||||
DataStorage.get().getStoreEntryDisplayName(replacement.get()),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
WHERE clink >NUL 2>NUL
|
||||
WHERE /q clink
|
||||
IF %ERRORLEVEL%==0 (
|
||||
exit /b 0
|
||||
)
|
||||
@@ -15,5 +15,7 @@ $defaultCreds = [System.Net.CredentialCache]::DefaultCredentials;^
|
||||
if ($defaultCreds) {^
|
||||
$downloader.Credentials = $defaultCreds^
|
||||
}^
|
||||
$downloader.DownloadFile("https://github.com/chrisant996/clink/releases/download/v1.7.7/clink.1.7.7.521fa7.zip", "$env:TEMP\clink.zip");^
|
||||
$downloader.DownloadFile("https://github.com/chrisant996/clink/releases/download/v1.7.13/clink.1.7.13.ac5d42.zip", "$env:TEMP\clink.zip");^
|
||||
Expand-Archive -Force -LiteralPath "$env:TEMP\clink.zip" -DestinationPath "$env:TEMP\xpipe\scriptdata\clink"; | powershell -NoLogo >NUL
|
||||
|
||||
clink set clink.autoupdate off
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
WHERE /q winget && winget install JanDeDobbeleer.OhMyPosh -s winget || powershell -ExecutionPolicy Bypass -Command "Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))"
|
||||
SET "PATH=%PATH%;%USERPROFILE%\AppData\Local\Programs\oh-my-posh\bin"
|
||||
MKDIR "%TEMP%\\xpipe\\scriptdata\\starship" >NUL 2>NUL
|
||||
WHERE /q oh-my-posh
|
||||
IF NOT %ERRORLEVEL%==0 (
|
||||
IF NOT EXIST "%USERPROFILE%\AppData\Local\Programs\oh-my-posh\bin\oh-my-posh.exe" (
|
||||
WHERE /q winget
|
||||
IF NOT %ERRORLEVEL%==0 (
|
||||
winget install JanDeDobbeleer.OhMyPosh -s winget
|
||||
) ELSE (
|
||||
powershell -ExecutionPolicy Bypass -Command "Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))"
|
||||
)
|
||||
)
|
||||
SET "PATH=%PATH%;%USERPROFILE%\AppData\Local\Programs\oh-my-posh\bin"
|
||||
)
|
||||
|
||||
MKDIR "%TEMP%\\xpipe\\scriptdata\\ohmyposh" >NUL 2>NUL
|
||||
ECHO load(io.popen('oh-my-posh init cmd'):read("*a"))() > "%TEMP%\\xpipe\\scriptdata\\ohmyposh\\ohmyposh.lua"
|
||||
clink inject --quiet --profile "%TEMP%\\xpipe\\scriptdata\\ohmyposh"
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
if (Get-Command "winget" -ErrorAction SilentlyContinue) {
|
||||
winget install JanDeDobbeleer.OhMyPosh -s winget
|
||||
} else {
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))
|
||||
if ( -not Get-Command "oh-my-posh" -ErrorAction SilentlyContinue) {
|
||||
if ( -not Test-Path "$env:USERPROFILE\AppData\Local\Programs\oh-my-posh\bin\oh-my-posh.exe" -PathType Leaf) {
|
||||
if (Get-Command "winget" -ErrorAction SilentlyContinue) {
|
||||
winget install JanDeDobbeleer.OhMyPosh -s winget
|
||||
} else {
|
||||
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://ohmyposh.dev/install.ps1'))
|
||||
}
|
||||
}
|
||||
$env:Path += ";$env:USERPROFILE\AppData\Local\Programs\oh-my-posh\bin"
|
||||
}
|
||||
$env:Path += ";$env:USERPROFILE\AppData\Local\Programs\oh-my-posh\bin"
|
||||
& ([ScriptBlock]::Create((oh-my-posh init $(oh-my-posh get shell) --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" --print) -join "`n"))
|
||||
|
||||
Reference in New Issue
Block a user