diff --git a/.config/quickshell/ii/modules/common/Config.qml b/.config/quickshell/ii/modules/common/Config.qml index 0813e8899..7ae1c8b96 100644 --- a/.config/quickshell/ii/modules/common/Config.qml +++ b/.config/quickshell/ii/modules/common/Config.qml @@ -266,6 +266,9 @@ Singleton { property string action: "/" property string clipboard: ";" property string emojis: ":" + property string math: "=" + property string shellCommand: "$" + property string webSearch: "?" } } diff --git a/.config/quickshell/ii/modules/overview/SearchWidget.qml b/.config/quickshell/ii/modules/overview/SearchWidget.qml index 2f4cdfada..cb3ca41c4 100644 --- a/.config/quickshell/ii/modules/overview/SearchWidget.qml +++ b/.config/quickshell/ii/modules/overview/SearchWidget.qml @@ -83,7 +83,11 @@ Item { // Wrapper id: nonAppResultsTimer interval: Config.options.search.nonAppResultDelay onTriggered: { - mathProcess.calculateExpression(root.searchingText); + let expr = root.searchingText; + if (expr.startsWith(Config.options.search.prefix.math)) { + expr = expr.slice(Config.options.search.prefix.math.length); + } + mathProcess.calculateExpression(expr); } } @@ -310,7 +314,7 @@ Item { // Wrapper }; }).filter(Boolean); } - if (root.searchingText.startsWith(Config.options.search.prefix.emojis)) { + else if (root.searchingText.startsWith(Config.options.search.prefix.emojis)) { // Clipboard const searchString = root.searchingText.slice(Config.options.search.prefix.emojis.length); return Emojis.fuzzyQuery(searchString).map(entry => { @@ -346,10 +350,30 @@ Item { // Wrapper fontType: "monospace", materialSymbol: 'terminal', execute: () => { - const cleanedCommand = root.searchingText.replace("file://", ""); + let cleanedCommand = root.searchingText.replace("file://", ""); + if (cleanedCommand.startsWith(Config.options.search.prefix.shellCommand)) { + cleanedCommand = cleanedCommand.slice(Config.options.search.prefix.shellCommand.length); + } Quickshell.execDetached(["bash", "-c", searchingText.startsWith('sudo') ? `${Config.options.apps.terminal} fish -C '${cleanedCommand}'` : cleanedCommand]); } }; + const webSearchResultObject = { + name: root.searchingText, + clickActionName: Translation.tr("Search"), + type: Translation.tr("Search the web"), + materialSymbol: 'travel_explore', + execute: () => { + let query = root.searchingText; + if (query.startsWith(Config.options.search.prefix.webSearch)) { + query = query.slice(Config.options.search.prefix.webSearch.length); + } + let url = Config.options.search.engineBaseUrl + query; + for (let site of Config.options.search.excludedSites) { + url += ` -site:${site}`; + } + Qt.openUrlExternally(url); + } + } const launcherActionObjects = root.searchActions.map(action => { const actionString = `${Config.options.search.prefix.action}${action.action}`; if (actionString.startsWith(root.searchingText) || root.searchingText.startsWith(actionString)) { @@ -366,7 +390,19 @@ Item { // Wrapper return null; }).filter(Boolean); + //////// Prioritized by prefix ///////// let result = []; + const startsWithNumber = /^\d/.test(root.searchingText); + const startsWithMathPrefix = root.searchingText.startsWith(Config.options.search.prefix.math); + const startsWithShellCommandPrefix = root.searchingText.startsWith(Config.options.search.prefix.shellCommand); + const startsWithWebSearchPrefix = root.searchingText.startsWith(Config.options.search.prefix.webSearch); + if (startsWithNumber || startsWithMathPrefix) { + result.push(mathResultObject); + } else if (startsWithShellCommandPrefix) { + result.push(commandResultObject); + } else if (startsWithWebSearchPrefix) { + result.push(webSearchResultObject); + } //////////////// Apps ////////////////// result = result.concat(AppSearch.fuzzyQuery(root.searchingText).map(entry => { @@ -378,30 +414,10 @@ Item { // Wrapper ////////// Launcher actions //////////// result = result.concat(launcherActionObjects); - /////////// Math result & command ////////// - const startsWithNumber = /^\d/.test(root.searchingText); - if (startsWithNumber) { - result.push(mathResultObject); - result.push(commandResultObject); - } else { - result.push(commandResultObject); - result.push(mathResultObject); - } - - ///////////////// Web search //////////////// - result.push({ - name: root.searchingText, - clickActionName: Translation.tr("Search"), - type: Translation.tr("Search the web"), - materialSymbol: 'travel_explore', - execute: () => { - let url = Config.options.search.engineBaseUrl + root.searchingText; - for (let site of Config.options.search.excludedSites) { - url += ` -site:${site}`; - } - Qt.openUrlExternally(url); - } - }); + /// Math result, command, web search /// + if (!startsWithShellCommandPrefix) result.push(commandResultObject); + if (!startsWithNumber && !startsWithMathPrefix) result.push(mathResultObject); + if (!startsWithWebSearchPrefix) result.push(webSearchResultObject); return result; }