forked from Shinonome/dots-hyprland
search: add math, shell command, and web search prefixes (#1795)
This commit is contained in:
@@ -266,6 +266,9 @@ Singleton {
|
|||||||
property string action: "/"
|
property string action: "/"
|
||||||
property string clipboard: ";"
|
property string clipboard: ";"
|
||||||
property string emojis: ":"
|
property string emojis: ":"
|
||||||
|
property string math: "="
|
||||||
|
property string shellCommand: "$"
|
||||||
|
property string webSearch: "?"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,11 @@ Item { // Wrapper
|
|||||||
id: nonAppResultsTimer
|
id: nonAppResultsTimer
|
||||||
interval: Config.options.search.nonAppResultDelay
|
interval: Config.options.search.nonAppResultDelay
|
||||||
onTriggered: {
|
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);
|
}).filter(Boolean);
|
||||||
}
|
}
|
||||||
if (root.searchingText.startsWith(Config.options.search.prefix.emojis)) {
|
else if (root.searchingText.startsWith(Config.options.search.prefix.emojis)) {
|
||||||
// Clipboard
|
// Clipboard
|
||||||
const searchString = root.searchingText.slice(Config.options.search.prefix.emojis.length);
|
const searchString = root.searchingText.slice(Config.options.search.prefix.emojis.length);
|
||||||
return Emojis.fuzzyQuery(searchString).map(entry => {
|
return Emojis.fuzzyQuery(searchString).map(entry => {
|
||||||
@@ -346,10 +350,30 @@ Item { // Wrapper
|
|||||||
fontType: "monospace",
|
fontType: "monospace",
|
||||||
materialSymbol: 'terminal',
|
materialSymbol: 'terminal',
|
||||||
execute: () => {
|
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]);
|
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 launcherActionObjects = root.searchActions.map(action => {
|
||||||
const actionString = `${Config.options.search.prefix.action}${action.action}`;
|
const actionString = `${Config.options.search.prefix.action}${action.action}`;
|
||||||
if (actionString.startsWith(root.searchingText) || root.searchingText.startsWith(actionString)) {
|
if (actionString.startsWith(root.searchingText) || root.searchingText.startsWith(actionString)) {
|
||||||
@@ -366,7 +390,19 @@ Item { // Wrapper
|
|||||||
return null;
|
return null;
|
||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
|
|
||||||
|
//////// Prioritized by prefix /////////
|
||||||
let result = [];
|
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 //////////////////
|
//////////////// Apps //////////////////
|
||||||
result = result.concat(AppSearch.fuzzyQuery(root.searchingText).map(entry => {
|
result = result.concat(AppSearch.fuzzyQuery(root.searchingText).map(entry => {
|
||||||
@@ -378,30 +414,10 @@ Item { // Wrapper
|
|||||||
////////// Launcher actions ////////////
|
////////// Launcher actions ////////////
|
||||||
result = result.concat(launcherActionObjects);
|
result = result.concat(launcherActionObjects);
|
||||||
|
|
||||||
/////////// Math result & command //////////
|
/// Math result, command, web search ///
|
||||||
const startsWithNumber = /^\d/.test(root.searchingText);
|
if (!startsWithShellCommandPrefix) result.push(commandResultObject);
|
||||||
if (startsWithNumber) {
|
if (!startsWithNumber && !startsWithMathPrefix) result.push(mathResultObject);
|
||||||
result.push(mathResultObject);
|
if (!startsWithWebSearchPrefix) result.push(webSearchResultObject);
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user