From e691fdcc59747bee3886e386a7d13aa6fe3b8e15 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Fri, 25 Apr 2025 22:01:19 +0200 Subject: [PATCH] search: run command --- .../modules/overview/SearchWidget.qml | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/.config/quickshell/modules/overview/SearchWidget.qml b/.config/quickshell/modules/overview/SearchWidget.qml index 801a9208e..19cf5f459 100644 --- a/.config/quickshell/modules/overview/SearchWidget.qml +++ b/.config/quickshell/modules/overview/SearchWidget.qml @@ -19,6 +19,10 @@ Item { // Wrapper property string mathResult: "" + function focusFirstItemIfNeeded() { + if (searchInput.focus) appResults.currentIndex = 0; // Focus the first item + } + Timer { id: nonAppResultsTimer interval: ConfigOptions.search.nonAppResultDelay @@ -38,7 +42,7 @@ Item { // Wrapper stdout: SplitParser { onRead: data => { root.mathResult = data - if (searchInput.focus) appResults.currentIndex = 0; // Focus the first item + root.focusFirstItemIfNeeded() } } } @@ -67,6 +71,18 @@ Item { // Wrapper } } + Process { + id: executor + property list baseCommand: ["bash", "-c"] + function executeCommand(command) { + executor.running = false + executor.command = baseCommand.concat( + `${command} || ${ConfigOptions.apps.terminal} fish -C 'echo "${qsTr("Searching for package with that command")}..." && pacman -F ${command}'` + ) + executor.running = true + } + } + Keys.onPressed: (event) => { // Prevent Esc and Backspace from registering if (event.key === Qt.Key_Escape) return; @@ -148,12 +164,6 @@ Item { // Wrapper RowLayout { id: searchBar spacing: 5 - KeyNavigation.down: { - if (appResults.count > 1) { - appResults.currentIndex = 1; - appResults.forceActiveFocus(); - } - } MaterialSymbol { id: searchIcon Layout.leftMargin: 15 @@ -169,10 +179,17 @@ Item { // Wrapper padding: 15 color: activeFocus ? Appearance.m3colors.m3onSurface : Appearance.m3colors.m3onSurfaceVariant selectedTextColor: Appearance.m3colors.m3onSurface - placeholderText: qsTr("Search") + placeholderText: qsTr("Search, calculate or run") placeholderTextColor: Appearance.m3colors.m3outline implicitWidth: root.searchingText == "" ? Appearance.sizes.searchWidthCollapsed : Appearance.sizes.searchWidth + KeyNavigation.down: { + if (appResults.count > 1) { + appResults.focus = true; + appResults.currentIndex = 1; + } + } + Behavior on implicitWidth { NumberAnimation { duration: Appearance.animation.elementDecelFast.duration @@ -271,6 +288,16 @@ Item { // Wrapper copyText.copyTextToClipboard(root.mathResult); } }); + result.push({ + name: searchingText, + clickActionName: "Run", + type: qsTr("Run command"), + fontType: "monospace", + materialSymbol: 'terminal', + execute: () => { + executor.executeCommand(searchingText.startsWith('sudo') ? `${ConfigOptions.apps.terminal} fish -C '${root.searchingText}'` : root.searchingText); + } + }); result.push({ name: root.searchingText, clickActionName: "Search",