Small script fixes

This commit is contained in:
crschnick 2023-10-10 10:37:22 +00:00
parent bc5887537a
commit b507ed8a11
4 changed files with 45 additions and 9 deletions

View file

@ -108,6 +108,14 @@ public class StoreViewState {
.orElseThrow();
}
public StoreEntryWrapper getEntryWrapper(DataStoreEntry entry) {
return allEntries.stream()
.filter(storeCategoryWrapper ->
storeCategoryWrapper.getEntry().equals(entry))
.findFirst()
.orElseThrow();
}
public static void init() {
new StoreViewState();
}

View file

@ -14,8 +14,8 @@ import java.util.function.Supplier;
@Getter
public enum PredefinedScriptStore {
SETUP_CLINK(
"Setup Clink",
CLINK_SETUP(
"Clink Setup",
() -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.CLINK.getEntry())
.minimumDialect(ShellDialects.CMD)
@ -23,30 +23,51 @@ public enum PredefinedScriptStore {
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.build()),
CLINK_INJECT(
"Inject Clink",
"Clink Inject",
() -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.CLINK.getEntry())
.minimumDialect(ShellDialects.CMD)
.script(SETUP_CLINK.getEntry())
.script(CLINK_SETUP.getEntry())
.commands(
"""
clink inject --quiet
""")
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.build()),
STARSHIP_SETUP_UNIX("Starship Unix Setup", () -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.STARSHIP.getEntry())
.minimumDialect(ShellDialects.SH)
.commands(file("starship_setup.sh"))
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.build()),
STARSHIP_BASH("Starship Bash", () -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.STARSHIP.getEntry())
.minimumDialect(ShellDialects.BASH)
.commands(file("starship_bash.sh"))
.commands("eval \"$(starship init bash)\"")
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.script(STARSHIP_SETUP_UNIX.getEntry())
.build()),
STARSHIP_ZSH("Starship Zsh", () -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.STARSHIP.getEntry())
.minimumDialect(ShellDialects.ZSH)
.commands("eval \"$(starship init zsh)\"")
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.script(STARSHIP_SETUP_UNIX.getEntry())
.build()),
STARSHIP_FISH("Starship Fish", () -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.STARSHIP.getEntry())
.minimumDialect(ShellDialects.FISH)
.commands("starship init fish | source")
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.script(STARSHIP_SETUP_UNIX.getEntry())
.build()),
STARSHIP_CMD(
"Starship Cmd",
() -> SimpleScriptStore.builder()
.group(PredefinedScriptGroup.STARSHIP.getEntry())
.minimumDialect(ShellDialects.CMD)
.script(SETUP_CLINK.getEntry())
.commands(file("starship_cmd.bat"))
.script(CLINK_SETUP.getEntry())
.commands(file(("starship_cmd.bat")))
.executionType(SimpleScriptStore.ExecutionType.TERMINAL_ONLY)
.build()),
STARSHIP_POWERSHELL(

View file

@ -14,6 +14,7 @@ import io.xpipe.app.ext.GuiDialog;
import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.fxcomps.impl.DataStoreChoiceComp;
import io.xpipe.app.fxcomps.impl.DataStoreListChoiceComp;
import io.xpipe.app.fxcomps.util.BindingsHelper;
import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.storage.DataStoreCategory;
import io.xpipe.app.storage.DataStoreEntry;
@ -42,11 +43,18 @@ public class SimpleScriptStoreProvider implements DataStoreProvider {
@Override
public Comp<?> customEntryComp(StoreSection sec, boolean preferLarge) {
SimpleScriptStore s = sec.getWrapper().getEntry().getStore().asNeeded();
var groupWrapper = StoreViewState.get().getEntryWrapper(s.getGroup().getEntry());
var def = new StoreToggleComp("base.isDefault", sec, s.getState().isDefault(), aBoolean -> {
var state = s.getState();
state.setDefault(aBoolean);
s.setState(state);
});
// Disable selection if parent group is already made default
def.disable(BindingsHelper.map(groupWrapper.getPersistentState(), o -> {
ScriptStore.State state = (ScriptStore.State) o;
return state.isDefault();
}));
var dropdown = new DropdownComp(List.of(def));
return new DenseStoreEntryComp(sec.getWrapper(), true, dropdown);
}

View file

@ -5,4 +5,3 @@ if [ "$?" != 0 ]; then
mkdir -p "$dir"
sh <(curl -sS https://starship.rs/install.sh) -y --bin-dir "$dir" > /dev/null
fi
eval "$(starship init bash)"