diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3da9cd9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,10 @@ +name: CI +on: + pull_request: +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: jdx/mise-action@v4 + - run: mise run test diff --git a/Panel.qml b/Panel.qml new file mode 100644 index 0000000..40a3a7b --- /dev/null +++ b/Panel.qml @@ -0,0 +1,415 @@ +import QtQuick +import Quickshell +import Quickshell.Io +import qs.Commons +import qs.Ui +import "TimberModel.js" as TimberModel + +// Bar-widget frontend to `timber` (managed Git worktrees), following the +// agents panel: a bar icon plus an anchored popup. Toggle with the icon +// or `omarchy-shell io.github.nnutter.omarchy-timber toggle`. +Panel { + id: root + moduleName: "io.github.nnutter.omarchy-timber" + ipcTarget: "io.github.nnutter.omarchy-timber" + property string omarchyPath: Quickshell.env("OMARCHY_PATH") + + readonly property color foreground: bar ? bar.foreground : Color.foreground + readonly property string fontFamily: bar ? bar.fontFamily : Style.font.family + + property var repos: [] + property var worktrees: [] + property string filterText: "" + property int selectedIndex: 0 + property bool cursorActive: false + property string pendingPath: "" + + property int headerHeight: Math.max(Style.space(34), Style.font.title + Style.spacing.controlPaddingY * 2) + property int contentSpacing: Style.spacing.md + property int rowHeight: Math.max(Style.space(44), Style.font.body + Style.spacing.rowPaddingX * 2) + property int maxVisibleRows: 8 + readonly property int visibleRows: Math.max(1, Math.min(displayModel.count, root.maxVisibleRows)) + readonly property int listHeight: root.visibleRows * root.rowHeight + (root.visibleRows - 1) * Style.space(4) + + // Same enumeration timber's own zsh completion uses: registered repo + // names plus a scan of the worktree root. `timber list` is avoided on + // purpose — its styled two-per-row table still emits ANSI under + // NO_COLOR and it enriches every row with git status, so one missing + // worktree directory fails the whole listing. + readonly property string listScript: [ + 'data_home=${XDG_DATA_HOME:-$HOME/.local/share};', + 'root=${TIMBER_WORKTREE_ROOT:-$HOME/worktrees};', + 'repos=$(timber repo list -q 2>/dev/null);', + 'if [ -z "$repos" ]; then', + ' repos=$(for d in "$data_home"/timber/repos/*.git; do [ -d "$d" ] || continue; b=${d##*/}; echo "${b%.git}"; done);', + 'fi;', + 'printf "%s\\n" "$repos" | while IFS= read -r repo; do [ -n "$repo" ] || continue; printf "R\\t%s\\n" "$repo"; done;', + 'shopt -s globstar nullglob;', + 'printf "%s\\n" "$repos" | while IFS= read -r repo; do [ -n "$repo" ] || continue;', + ' for d in "$root/$repo"/**/"$repo"; do [ -e "$d/.git" ] || continue;', + ' parent=${d%/*}; name=${parent#"$root/$repo"/}; [ -n "$name" ] || continue;', + ' printf "W\\t%s@%s\\t%s\\n" "$name" "$repo" "$d";', + ' done;', + 'done' + ].join("\n") + + function refresh() { + root.pendingPath = "" + root.filterText = "" + root.selectedIndex = 0 + root.cursorActive = false + listProc.running = true + } + + function setFilter(nextFilter) { + root.filterText = nextFilter + root.selectedIndex = 0 + root.cursorActive = true + root.rebuildDisplay() + } + + function select(delta) { + if (displayModel.count === 0) return + if (!root.cursorActive) { + root.cursorActive = true + root.selectedIndex = delta < 0 ? displayModel.count - 1 : 0 + } else { + root.selectedIndex = (root.selectedIndex + delta + displayModel.count) % displayModel.count + } + resultList.positionViewAtIndex(root.selectedIndex, ListView.Contain) + } + + function selectAbsolute(index) { + if (displayModel.count === 0) return + root.cursorActive = true + root.selectedIndex = Math.max(0, Math.min(index, displayModel.count - 1)) + resultList.positionViewAtIndex(root.selectedIndex, ListView.Contain) + } + + function applyListOutput(text) { + var repos = [] + var worktrees = [] + var lines = String(text || "").split("\n") + for (var i = 0; i < lines.length; i++) { + var line = lines[i] + if (!line) continue + var parts = line.split("\t") + if (parts[0] === "R" && parts[1]) repos.push({ name: parts[1] }) + else if (parts[0] === "W" && parts[1] && parts[2]) { + var split = TimberModel.splitValue(parts[1]) + if (split) worktrees.push({ name: split.name, repo: split.repo, path: parts[2] }) + } + } + root.repos = repos + root.worktrees = worktrees + root.rebuildDisplay() + } + + function rebuildDisplay() { + var items = TimberModel.itemsForTerm(root.repos, root.worktrees, root.filterText) + displayModel.clear() + for (var i = 0; i < items.length; i++) { + var path = "" + if (items[i].kind === "open") { + for (var j = 0; j < root.worktrees.length; j++) { + if (root.worktrees[j].name === items[i].name && root.worktrees[j].repo === items[i].repo) { + path = root.worktrees[j].path + break + } + } + } + displayModel.append({ kind: items[i].kind, name: items[i].name, repo: items[i].repo, value: items[i].value, path: path }) + } + if (displayModel.count === 0) root.selectedIndex = 0 + else if (root.selectedIndex >= displayModel.count) root.selectedIndex = displayModel.count - 1 + else if (root.selectedIndex < 0) root.selectedIndex = 0 + Qt.callLater(function() { + if (displayModel.count > 0) resultList.positionViewAtIndex(root.selectedIndex, ListView.Contain) + }) + } + + // Failures surface only here, never in the widget itself. + function notifyFailure(op, detail) { + Util.execArgv([root.omarchyPath + "/bin/omarchy-notification-send", "-u", "critical", "--app-name", "Timber", "Timber worktree " + op + " failed", detail]) + } + + function openPath(path) { + if (!path) return + root.close() + Util.execArgv(["zed", "--new", path]) + } + + function removeIndex(index) { + if (index < 0 || index >= displayModel.count) return + var row = displayModel.get(index) + if (row.kind !== "open") return + if (removeProc.running) return + removeProc.command = ["timber", "remove", row.value] + removeProc.running = true + } + + function activateIndex(index) { + if (index < 0 || index >= displayModel.count) return + var row = displayModel.get(index) + if (row.kind === "open") { + root.openPath(row.path) + } else { + if (createProc.running) return + createProc.command = ["timber", "create", "--no-herdr", row.value] + createProc.running = true + } + } + + implicitWidth: button.implicitWidth + implicitHeight: button.implicitHeight + + onOpenedChanged: if (opened) { + root.refresh() + Qt.callLater(function() { keyCatcher.forceActiveFocus() }) + } + + ListModel { id: displayModel } + + Process { + id: createProc + stdout: StdioCollector { + id: createStdout + waitForEnd: true + } + stderr: StdioCollector { + id: createStderr + waitForEnd: true + } + onExited: function(code) { + if (code === 0) { + var path = String(createStdout.text || "").trim().split("\n").pop() || "" + if (path) root.openPath(path) + else root.notifyFailure("create", "reported no path") + } else { + var detail = String(createStderr.text || "").trim().split("\n").pop() || ("exit " + code) + root.notifyFailure("create", detail) + } + } + } + + Process { + id: removeProc + stdout: StdioCollector { + id: removeStdout + waitForEnd: true + } + stderr: StdioCollector { + id: removeStderr + waitForEnd: true + } + onExited: function(code) { + if (code === 0) { + root.refresh() + } else { + var detail = String(removeStderr.text || "").trim().split("\n").pop() || ("exit " + code) + root.notifyFailure("remove", detail) + } + } + } + + Process { + id: listProc + command: ["bash", "-lc", root.listScript] + stdout: StdioCollector { + waitForEnd: true + onStreamFinished: root.applyListOutput(text) + } + onExited: function(code) { + if (code !== 0 && displayModel.count === 0) + root.notifyFailure("list", "timber repo list exited " + code) + } + } + + BarIconButton { + id: button + anchors.fill: parent + bar: root.bar + text: "" + onPressed: function(buttonCode) { + if (buttonCode === Qt.RightButton) return + root.toggle() + } + } + + KeyboardPanel { + id: panel + anchorItem: button + owner: root + bar: root.bar + open: root.opened + focusTarget: keyCatcher + contentWidth: panel.fittedContentWidth(Style.space(400)) + contentHeight: panel.fittedContentHeight(panelColumn.implicitHeight, Style.space(560)) + + // Raw key handling instead of PanelKeyCatcher: this panel filters as + // you type, so every printable character (including j/k/h/l, which the + // catcher reserves for movement) must reach the filter. Tab keeps the + // platform meaning of switching to the next panel. + Item { + id: keyCatcher + anchors.fill: parent + focus: true + + Keys.priority: Keys.BeforeItem + Keys.onPressed: function(event) { + if (event.key === Qt.Key_Escape) { + if (root.filterText) root.setFilter("") + else root.close() + event.accepted = true + } else if (Util.editsFilter(event, root.filterText)) { + root.setFilter(Util.editedFilter(event, root.filterText)) + event.accepted = true + } else if (event.key === Qt.Key_Up) { + root.select(-1) + event.accepted = true + } else if (event.key === Qt.Key_Down) { + root.select(1) + event.accepted = true + } else if (event.key === Qt.Key_Tab || event.key === Qt.Key_Backtab) { + root.switchPanel((event.modifiers & Qt.ShiftModifier) || event.key === Qt.Key_Backtab ? -1 : 1) + event.accepted = true + } else if (event.key === Qt.Key_PageUp) { + root.select(-6) + event.accepted = true + } else if (event.key === Qt.Key_PageDown) { + root.select(6) + event.accepted = true + } else if (event.key === Qt.Key_Home) { + root.selectAbsolute(0) + event.accepted = true + } else if (event.key === Qt.Key_End) { + root.selectAbsolute(displayModel.count - 1) + event.accepted = true + } else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { + if (root.cursorActive) root.activateIndex(root.selectedIndex) + else if (displayModel.count > 0) root.cursorActive = true + event.accepted = true + } else if (event.text && event.text.length === 1 && event.text.charCodeAt(0) >= 32 && event.text.charCodeAt(0) !== 127) { + root.setFilter(root.filterText + event.text) + event.accepted = true + } + } + + Column { + id: panelColumn + width: parent.width + spacing: root.contentSpacing + + Text { + textFormat: Text.PlainText + width: parent.width + height: root.headerHeight + verticalAlignment: Text.AlignVCenter + text: root.filterText || "type worktree@repo" + color: root.foreground + opacity: root.filterText ? 1 : 0.58 + font.family: root.fontFamily + font.pixelSize: Style.font.heading + elide: Text.ElideRight + } + + ListView { + id: resultList + width: parent.width + height: root.listHeight + model: displayModel + clip: true + spacing: Style.space(4) + boundsBehavior: Flickable.StopAtBounds + + delegate: CursorSurface { + id: row + required property int index + required property string kind + required property string value + required property string path + + hasCursor: root.cursorActive && index === root.selectedIndex + foreground: root.foreground + width: ListView.view.width + implicitHeight: root.rowHeight + + Text { + textFormat: Text.PlainText + anchors.fill: parent + anchors.leftMargin: Style.space(12) + anchors.rightMargin: Style.space(40) + verticalAlignment: Text.AlignVCenter + text: (row.kind === "create" ? "+ " : "") + row.value + color: root.foreground + opacity: row.kind === "create" && !row.hasCursor ? 0.72 : 1.0 + font.family: root.fontFamily + font.pixelSize: Style.font.title + elide: Text.ElideRight + } + + MouseArea { + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onPositionChanged: { + root.cursorActive = true + root.selectedIndex = row.index + } + onClicked: { + root.cursorActive = true + root.selectedIndex = row.index + root.activateIndex(row.index) + } + } + + // Stacked after the row MouseArea so its press wins and the + // row does not also activate (open in Zed) underneath it. + Item { + visible: row.hasCursor && row.kind === "open" + anchors.right: parent.right + anchors.top: parent.top + anchors.bottom: parent.bottom + width: Style.space(36) + + Text { + textFormat: Text.PlainText + anchors.centerIn: parent + text: "×" + color: Color.urgent + font.family: root.fontFamily + font.pixelSize: Style.font.title + } + + MouseArea { + id: removeMouse + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: root.removeIndex(row.index) + } + + PanelToolTip { + visible: removeMouse.containsMouse + text: "Remove " + row.value + fontFamily: root.fontFamily + } + } + } + } + + Text { + textFormat: Text.PlainText + visible: displayModel.count === 0 + width: parent.width + text: root.worktrees.length === 0 ? "No worktrees yet — type name@repo to create one" : "No matches" + color: root.foreground + opacity: 0.7 + font.family: root.fontFamily + font.pixelSize: Style.font.body + horizontalAlignment: Text.AlignHCenter + wrapMode: Text.WordWrap + } + } + } + } +} diff --git a/README.md b/README.md index 07a42ad..a03cb6a 100644 --- a/README.md +++ b/README.md @@ -1 +1,67 @@ -# omarchy-timber \ No newline at end of file +# omarchy-timber + +Omarchy overlay plugin that fronts [`timber`](https://github.com/nnutter/timber) +managed Git worktrees, mirroring `timber tui`: fuzzy-filter the existing +worktrees, type `name@repo` to create, `enter` to open in Zed. + +## Requirements + +- `timber` on `PATH` +- `zed` on `PATH` (opening runs `zed --new `) + +## Install + +```bash +omarchy plugin add https://github.com/nnutter/omarchy-timber.git --enable --yes +``` + +By hand: copy this repo to +`~/.config/omarchy/plugins/io.github.nnutter.omarchy-timber/`, then +`omarchy-shell shell rescanPlugins` and +`omarchy plugin enable io.github.nnutter.omarchy-timber`. + +Enabling drops the Timber icon on the bar (center when no section is +declared); move it with `omarchy bar move`. If you installed an older +overlay revision, disable and re-enable once so the entry moves from +`plugins[]` to the bar layout. + +## Use + +Click the bar icon or run: + +```bash +omarchy-shell io.github.nnutter.omarchy-timber toggle +``` + +Keys: type to filter (`@` narrows to repos), `↓` / `↑` move, +`enter` open or create, `esc` clear then close. `tab` keeps the +platform meaning of switching to the next panel. Creating runs +`timber create --no-herdr name@repo` and opens the reported path in +Zed. Hover a worktree row for its `×`, which runs `timber remove` +(no `--force`); failures arrive only as a critical desktop +notification titled `Timber worktree failed`. + +Suggested Hyprland binding: + +```ini +bind = SUPER, T, exec, omarchy-shell io.github.nnutter.omarchy-timber toggle +``` + +## Development + +```bash +mise install # dev tools (node; qmllint is unavailable via mise, see below) +mise run test # TimberModel unit tests (runs check first) +mise run install # test, then copy into ~/.config/omarchy/plugins and rescan +``` + +`qmllint` cannot come from mise (Qt is not in the registry) and +quickshell ships as a system package, so validate `Timber.qml` by +summoning the installed plugin on a live Omarchy machine. + +## Notes + +Worktrees are enumerated the way timber's own zsh completion does +(`timber repo list -q` plus a scan of `$TIMBER_WORKTREE_ROOT`) rather +than parsing `timber list`, whose styled table still emits ANSI under +`NO_COLOR` and fails as a whole when one worktree directory is missing. diff --git a/TimberModel.js b/TimberModel.js new file mode 100644 index 0000000..73bc441 --- /dev/null +++ b/TimberModel.js @@ -0,0 +1,127 @@ +// Pure filter logic for the timber overlay, ported from timber's +// tui_create_wizard.go (wizardItemsForTerm, filterWizardWorktrees). +// No QML dependencies so the matching stays testable in isolation. +// +// repos: [{ name: "timber" }] +// worktrees:[{ name: "feature/login", repo: "timber" }] +// items: [{ kind: "open"|"create", name, repo, value: "name@repo" }] + +// Case-insensitive fuzzy match: every char of term appears in order. +function fuzzyMatch(term, target) { + var t = String(term || "").toLowerCase() + var s = String(target || "").toLowerCase() + if (!t) return { matched: true, indexes: [] } + var indexes = [] + var pos = 0 + for (var i = 0; i < t.length; i++) { + var found = s.indexOf(t[i], pos) + if (found === -1) return { matched: false, indexes: [] } + indexes.push(found) + pos = found + 1 + } + return { matched: true, indexes: indexes } +} + +function filterTerm(term, targets) { + var out = [] + if (!term) { + for (var i = 0; i < targets.length; i++) out.push({ index: i, matchedIndexes: [] }) + return out + } + for (var j = 0; j < targets.length; j++) { + var m = fuzzyMatch(term, targets[j]) + if (m.matched) out.push({ index: j, matchedIndexes: m.indexes }) + } + return out +} + +function cutLast(value, sep) { + var s = String(value || "") + var i = s.lastIndexOf(sep) + if (i === -1) return { before: s, after: "", qualified: false } + return { before: s.slice(0, i), after: s.slice(i + 1), qualified: true } +} + +function worktreeValue(worktree) { + return worktree.name + "@" + worktree.repo +} + +function hasWorktree(worktrees, name, repo) { + for (var i = 0; i < worktrees.length; i++) { + if (worktrees[i].name === name && worktrees[i].repo === repo) return true + } + return false +} + +function hasRepository(repos, name) { + for (var i = 0; i < repos.length; i++) { + if (repos[i].name === name) return true + } + return false +} + +// Mirror filterWizardWorktrees: filter on the worktree half, then when the +// term holds `@`, intersect with the repo-half matches. +function filterWorktrees(term, worktrees) { + var values = [] + for (var i = 0; i < worktrees.length; i++) values.push(worktreeValue(worktrees[i])) + + var worktreeTargets = [] + var repoTargets = [] + for (var j = 0; j < values.length; j++) { + var parts = cutLast(values[j], "@") + worktreeTargets.push(parts.before) + repoTargets.push(parts.after) + } + + var termParts = cutLast(term, "@") + var worktreeRanks = filterTerm(termParts.before, worktreeTargets) + if (!termParts.qualified) return worktreeRanks + + var repoRanks = filterTerm(termParts.after, repoTargets) + var repoMatch = {} + for (var k = 0; k < repoRanks.length; k++) repoMatch[repoRanks[k].index] = repoRanks[k] + + var out = [] + for (var r = 0; r < worktreeRanks.length; r++) { + var rank = worktreeRanks[r] + var repoRank = repoMatch[rank.index] + if (!repoRank) continue + var offset = worktreeTargets[rank.index].length + 1 + var shifted = [] + for (var m = 0; m < repoRank.matchedIndexes.length; m++) shifted.push(repoRank.matchedIndexes[m] + offset) + out.push({ index: rank.index, matchedIndexes: rank.matchedIndexes.concat(shifted) }) + } + return out +} + +// Mirror wizardItemsForTerm: existing worktrees first, then one `create` +// row per matching repo when the term is a qualified `name@repo`. +function itemsForTerm(repos, worktrees, term) { + var t = String(term || "") + var items = [] + var ranks = filterWorktrees(t, worktrees || []) + for (var i = 0; i < ranks.length; i++) { + var w = (worktrees || [])[ranks[i].index] + items.push({ kind: "open", name: w.name, repo: w.repo, value: worktreeValue(w) }) + } + + var termParts = cutLast(t, "@") + if (!termParts.qualified || !termParts.before || termParts.before.indexOf("@") !== -1) return items + + var repoNames = [] + for (var j = 0; j < (repos || []).length; j++) repoNames.push(repos[j].name) + var repoRanks = filterTerm(termParts.after, repoNames) + for (var k = 0; k < repoRanks.length; k++) { + var repo = (repos || [])[repoRanks[k].index] + if (hasWorktree(worktrees || [], termParts.before, repo.name)) continue + items.push({ kind: "create", name: termParts.before, repo: repo.name, value: termParts.before + "@" + repo.name }) + } + return items +} + +function splitValue(value) { + var parts = cutLast(value, "@") + if (!parts.qualified || !parts.before || !parts.after) return null + return { name: parts.before, repo: parts.after } +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..98c2c63 --- /dev/null +++ b/manifest.json @@ -0,0 +1,20 @@ +{ + "schemaVersion": 1, + "id": "io.github.nnutter.omarchy-timber", + "name": "Timber worktrees", + "version": "0.1.0", + "author": "nnutter", + "description": "List, filter, create, and open timber-managed Git worktrees", + "kinds": [ + "bar-widget" + ], + "entryPoints": { + "barWidget": "Panel.qml" + }, + "barWidget": { + "displayName": "Timber", + "description": "List, filter, create, and open timber-managed Git worktrees", + "category": "Files", + "allowMultiple": false + } +} diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..a5779a4 --- /dev/null +++ b/mise.toml @@ -0,0 +1,34 @@ +[tools] +node = "24" + +# qmllint/quickshell are intentionally absent: Qt is not in the mise +# registry and quickshell ships as a system package, so the overlay QML +# itself is validated by summoning it on a live Omarchy machine. + +[tasks.check] +description = "Syntax-check the plugin JavaScript and lint the QML" +run = "node --check TimberModel.js && node --check tests/model.test.mjs && bash tests/qml_lint.sh Panel.qml" + +[tasks.test] +description = "Run TimberModel unit tests" +depends = ["check"] +run = "node --test tests/model.test.mjs" + +[tasks.install] +description = "Install the plugin into ~/.config/omarchy/plugins and rescan" +depends = ["test"] +run = ''' +#!/usr/bin/env bash +set -euo pipefail +id="io.github.nnutter.omarchy-timber" +dest="${HOME}/.config/omarchy/plugins/${id}" +mkdir -p "$dest" +cp manifest.json Panel.qml TimberModel.js "$dest/" +if command -v omarchy-shell >/dev/null 2>&1; then + omarchy-shell shell rescanPlugins || echo "rescan failed: is omarchy-shell running?" >&2 + omarchy restart shell +else + echo "omarchy-shell not on PATH; skipping rescan" >&2 +fi +echo "installed to $dest" +''' diff --git a/tests/model.test.mjs b/tests/model.test.mjs new file mode 100644 index 0000000..ee59948 --- /dev/null +++ b/tests/model.test.mjs @@ -0,0 +1,86 @@ +import { readFileSync } from "node:fs"; +import vm from "node:vm"; +import { describe, it } from "node:test"; +import assert from "node:assert/strict"; + +const src = readFileSync(new URL("../TimberModel.js", import.meta.url), "utf8"); +const sandbox = {}; +vm.createContext(sandbox); +// TimberModel.js declares bare functions (QML import style), so export +// them explicitly for the test context. +vm.runInContext( + src + "\n;globalThis.__timberModel = { itemsForTerm, splitValue };", + sandbox, +); +const { itemsForTerm, splitValue } = sandbox.__timberModel; + +const repos = [{ name: "timber" }, { name: "persona" }]; +const worktrees = [ + { name: "alpha", repo: "timber" }, + { name: "beta", repo: "persona" }, + { name: "alpha", repo: "persona" }, +]; + +// Array.from re-roots the results in this realm: itemsForTerm returns +// vm-context arrays, whose prototype deepStrictEqual would reject. +const values = (items) => Array.from(items, (item) => item.value); +const kinds = (items) => Array.from(items, (item) => item.kind); + +describe("itemsForTerm", () => { + it("lists every worktree on an empty term", () => { + assert.deepEqual(values(itemsForTerm(repos, worktrees, "")), [ + "alpha@timber", + "beta@persona", + "alpha@persona", + ]); + }); + + it("fuzzy-filters on the worktree half", () => { + assert.deepEqual(values(itemsForTerm(repos, worktrees, "alp")), [ + "alpha@timber", + "alpha@persona", + ]); + }); + + it("keeps every repo while the repo half is empty", () => { + assert.deepEqual(values(itemsForTerm(repos, worktrees, "alpha@")), [ + "alpha@timber", + "alpha@persona", + ]); + }); + + it("narrows to one repo once @ is qualified", () => { + assert.deepEqual(values(itemsForTerm(repos, worktrees, "alpha@timber")), [ + "alpha@timber", + ]); + }); + + it("offers one create row per matching repo", () => { + const items = itemsForTerm(repos, worktrees, "newfeat@"); + assert.deepEqual(kinds(items), ["create", "create"]); + assert.deepEqual(values(items), ["newfeat@timber", "newfeat@persona"]); + }); + + it("filters create rows by the repo half", () => { + assert.deepEqual(values(itemsForTerm(repos, worktrees, "newfeat@per")), [ + "newfeat@persona", + ]); + }); + + it("opens instead of creating when the worktree exists", () => { + const items = itemsForTerm(repos, worktrees, "beta@persona"); + assert.deepEqual(kinds(items), ["open"]); + assert.deepEqual(values(items), ["beta@persona"]); + }); +}); + +describe("splitValue", () => { + it("splits on the last @ so slashes survive in names", () => { + // Spread into this realm: splitValue returns a vm-context object. + assert.deepEqual({ ...splitValue("a/b@c") }, { name: "a/b", repo: "c" }); + }); + + it("rejects unqualified values", () => { + assert.equal(splitValue("nope"), null); + }); +}); diff --git a/tests/qml_lint.sh b/tests/qml_lint.sh new file mode 100755 index 0000000..89b12d0 --- /dev/null +++ b/tests/qml_lint.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Lint plugin QML with qmllint. Exits non-zero on parse errors (255); +# the missing-property/signal-handler warnings qmllint emits for +# host-injected members (bar, Style singletons) also appear for +# first-party panels and do not fail the run. Without qmllint +# installed the lint skips so the task stays runnable off-machine. +set -u + +file="${1:-Panel.qml}" + +qmllint="" +for candidate in qmllint /usr/lib/qt6/bin/qmllint /lib64/qt6/bin/qmllint /lib/qt6/bin/qmllint; do + if command -v "$candidate" >/dev/null 2>&1; then + qmllint="$candidate" + break + fi +done + +if [[ -z $qmllint ]]; then + echo "qml_lint: qmllint not found; skipping QML lint" >&2 + exit 0 +fi + +args=() +shell_dir="${OMARCHY_PATH:-/usr/share/omarchy}/shell" +if [[ -f $shell_dir/Commons/qmldir && -f $shell_dir/Ui/qmldir ]]; then + mapdir=$(mktemp -d) + trap 'rm -rf "$mapdir"' EXIT + mkdir -p "$mapdir/qs" + ln -s "$shell_dir/Commons" "$mapdir/qs/Commons" + ln -s "$shell_dir/Ui" "$mapdir/qs/Ui" + args+=(-I "$mapdir") +fi + +exec "$qmllint" "${args[@]}" "$file"