diff --git a/packages/opencode/src/cli/cmd/tui/app.tsx b/packages/opencode/src/cli/cmd/tui/app.tsx index ce509415a5..c8fd4b9b81 100644 --- a/packages/opencode/src/cli/cmd/tui/app.tsx +++ b/packages/opencode/src/cli/cmd/tui/app.tsx @@ -27,6 +27,7 @@ import { ExitProvider, useExit } from "./context/exit" import { Session as SessionApi } from "@/session" import { TuiEvent } from "./event" import { KVProvider, useKV } from "./context/kv" +import { StatusBar } from "./component/status-bar" import { Provider } from "@/provider/provider" import { ArgsProvider, useArgs, type Args } from "./context/args" @@ -432,36 +433,7 @@ function App() { - - - - open - - code{" "} - - v{Installation.VERSION} - - - {process.cwd().replace(Global.Path.home, "~")} - - - - - tab - - {""} - - {local.agent.current().name.toUpperCase()} - AGENT - - - + ) } diff --git a/packages/opencode/src/cli/cmd/tui/component/status-bar.tsx b/packages/opencode/src/cli/cmd/tui/component/status-bar.tsx new file mode 100644 index 0000000000..1aa943e5ce --- /dev/null +++ b/packages/opencode/src/cli/cmd/tui/component/status-bar.tsx @@ -0,0 +1,48 @@ +import { useTheme } from "@tui/context/theme" +import { useLocal } from "@tui/context/local" +import { Installation } from "@/installation" +import { Global } from "@/global" +import { TextAttributes } from "@opentui/core" +import { useGitBranch } from "./status-bar/git" + +export function StatusBar() { + const { theme } = useTheme() + const local = useLocal() + const { branch } = useGitBranch() + + return ( + + + + open + + code{" "} + + v{Installation.VERSION} + + + + {process.cwd().replace(Global.Path.home, "~")} + {branch() ? `:${branch()}` : ""} + + + + + + tab + + {""} + + {local.agent.current().name.toUpperCase()} + AGENT + + + + ) +} diff --git a/packages/opencode/src/cli/cmd/tui/component/status-bar/git.tsx b/packages/opencode/src/cli/cmd/tui/component/status-bar/git.tsx new file mode 100644 index 0000000000..f16713eb2c --- /dev/null +++ b/packages/opencode/src/cli/cmd/tui/component/status-bar/git.tsx @@ -0,0 +1,25 @@ +import { createSignal, createEffect, onCleanup } from "solid-js" +import { $ } from "bun" +import { watch } from "fs" + +export function useGitBranch() { + const [branch, setBranch] = createSignal("") + + createEffect(async () => { + const gitCheck = await $`git rev-parse --is-inside-work-tree`.cwd(process.cwd()).quiet().nothrow() + if (gitCheck.exitCode === 0) { + const b = await $`git branch --show-current`.cwd(process.cwd()).quiet().nothrow().text() + setBranch(b.trim()) + + // Set up watcher for .git/HEAD + const gitHeadPath = `${process.cwd()}/.git/HEAD` + const watcher = watch(gitHeadPath, { persistent: false }, async () => { + const newBranch = await $`git branch --show-current`.cwd(process.cwd()).quiet().nothrow().text() + setBranch(newBranch.trim()) + }) + onCleanup(() => watcher.close()) + } + }) + + return { branch } +}