mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-24 16:40:58 -04:00
Script fixes
This commit is contained in:
@@ -34,16 +34,11 @@ public abstract class ScriptStore extends JacksonizedValue implements DataStore,
|
||||
|
||||
public static ShellControl controlWithScripts(ShellControl pc, List<DataStoreEntryRef<ScriptStore>> initScripts, List<DataStoreEntryRef<ScriptStore>> bringScripts) {
|
||||
var initFlattened = flatten(initScripts);
|
||||
initFlattened.forEach(simpleScriptStore -> {
|
||||
if (pc.getInitCommands().contains(simpleScriptStore)) {
|
||||
return;
|
||||
}
|
||||
|
||||
pc.initWith(simpleScriptStore);
|
||||
});
|
||||
var bringFlattened = flatten(bringScripts);
|
||||
|
||||
pc.onInit(shellControl -> {
|
||||
var bringFlattened = flatten(bringScripts);
|
||||
passInitScripts(pc, initFlattened);
|
||||
|
||||
var dir = initScriptsDirectory(shellControl, bringFlattened);
|
||||
if (dir != null) {
|
||||
shellControl.initWith(new SimpleScriptSnippet(shellControl.getShellDialect().appendToPathVariableCommand(dir), ScriptSnippet.ExecutionType.TERMINAL_ONLY));
|
||||
@@ -52,12 +47,30 @@ public abstract class ScriptStore extends JacksonizedValue implements DataStore,
|
||||
return pc;
|
||||
}
|
||||
|
||||
private static void passInitScripts(ShellControl pc, List<SimpleScriptStore> scriptStores) throws Exception {
|
||||
scriptStores.forEach(simpleScriptStore -> {
|
||||
if (pc.getInitCommands().contains(simpleScriptStore)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!simpleScriptStore.getMinimumDialect().isCompatibleTo(pc.getShellDialect())) {
|
||||
return;
|
||||
}
|
||||
|
||||
pc.initWith(simpleScriptStore);
|
||||
});
|
||||
}
|
||||
|
||||
private static String initScriptsDirectory(ShellControl proc, List<SimpleScriptStore> scriptStores) throws Exception {
|
||||
if (scriptStores.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var applicable = scriptStores.stream().filter(simpleScriptStore -> simpleScriptStore.getMinimumDialect().isCompatibleTo(proc.getShellDialect())).toList();
|
||||
if (applicable.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var refs = applicable.stream().map(scriptStore -> {
|
||||
return DataStorage.get().getStoreEntries().stream().filter(dataStoreEntry -> dataStoreEntry.getStore() == scriptStore).findFirst().orElseThrow().<SimpleScriptStore>ref();
|
||||
}).toList();
|
||||
|
||||
@@ -13,6 +13,7 @@ import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuperBuilder
|
||||
@@ -43,17 +44,20 @@ public class SimpleScriptStore extends ScriptStore implements ScriptSnippet {
|
||||
@Override
|
||||
public List<DataStoreEntryRef<ScriptStore>> getEffectiveScripts() {
|
||||
return scripts != null
|
||||
? scripts.stream().filter(scriptStore -> scriptStore != null).toList()
|
||||
? scripts.stream().filter(Objects::nonNull).toList()
|
||||
: List.of();
|
||||
}
|
||||
|
||||
public void queryFlattenedScripts(LinkedHashSet<SimpleScriptStore> all) {
|
||||
// Prevent loop
|
||||
all.add(this);
|
||||
getEffectiveScripts().stream()
|
||||
.filter(scriptStoreDataStoreEntryRef -> !all.contains(scriptStoreDataStoreEntryRef.getStore()))
|
||||
.forEach(scriptStoreDataStoreEntryRef -> {
|
||||
scriptStoreDataStoreEntryRef.getStore().queryFlattenedScripts(all);
|
||||
});
|
||||
all.remove(this);
|
||||
all.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,7 +74,7 @@ snippetsDescription=Other scripts to run first
|
||||
snippetsDependenciesDescription=All possible scripts that should be run if applicable
|
||||
isDefault=Run on init in all compatible shells
|
||||
bringToShells=Bring to all compatible shells
|
||||
isDefaultGroup=Enable all group scripts
|
||||
isDefaultGroup=Run all group scripts on shell init
|
||||
executionType=Execution type
|
||||
executionTypeDescription=When to run this snippet
|
||||
minimumShellDialect=Shell type
|
||||
|
||||
Reference in New Issue
Block a user