Something went wrong. Try again.
Training wheels for the terminal
Something went wrong. Try again.
1.3 kB · 36 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637import { invoke } from "@tauri-apps/api/core";import { useEffect, useState } from "react";import { ShellFamily } from "./commandAssembly";
// Cache the (constant, per-session) lookup so every CommandBuilder mount shares// one invoke. PowerShell needs its own quoting; bash/zsh/fish are all POSIX.let cached: Promise<ShellFamily> | undefined;function loadShellFamily(): Promise<ShellFamily> { if (!cached) { cached = invoke<string>("get_shell_info") .then((s): ShellFamily => (s === "powershell" ? "powershell" : "posix")) // Not inside Tauri (bare `pnpm dev`) or command failed: POSIX is the safe // default (identical to PowerShell for values without embedded quotes). .catch((): ShellFamily => "posix"); } return cached;}
/** * The shell family the app spawns, used to quote assembled commands. Resolved * from the backend's `get_shell_info` (the shell `async_create_shell` actually * launched), defaulting to "posix" until it loads. */export function useShellFamily(): ShellFamily { const [shell, setShell] = useState<ShellFamily>("posix"); useEffect(() => { let active = true; loadShellFamily().then((family) => { if (active) setShell(family); }); return () => { active = false; }; }, []); return shell;}