Add .config/DankMaterialShell/plugin_settings.json Add .config/DankMaterialShell/plugins/calculator/CalculatorLauncher.qml Add .config/DankMaterialShell/plugins/calculator/CalculatorSettings.qml Add .config/DankMaterialShell/plugins/calculator/README.md Add .config/DankMaterialShell/plugins/calculator/calculator.js Add .config/DankMaterialShell/plugins/calculator/.git/HEAD Add .config/DankMaterialShell/plugins/calculator/.git/config Add .config/DankMaterialShell/plugins/calculator/.git/index Add .config/DankMaterialShell/plugins/calculator/.git/objects/info/.keep Add .config/DankMaterialShell/plugins/calculator/.git/objects/pack/pack-67f644835e660794f65c9273e46788b0c3da57cf.idx Add .config/DankMaterialShell/plugins/calculator/.git/objects/pack/pack-67f644835e660794f65c9273e46788b0c3da57cf.rev Add .config/DankMaterialShell/plugins/calculator/.git/objects/pack/pack-67f644835e660794f65c9273e46788b0c3da57cf.pack Add .config/DankMaterialShell/plugins/calculator/.git/refs/heads/main Add .config/DankMaterialShell/plugins/calculator/.git/refs/remotes/origin/main Add .config/DankMaterialShell/plugins/calculator/.git/refs/remotes/origin/qalc Add .config/DankMaterialShell/plugins/calculator/.git/refs/tags/.keep Add .config/DankMaterialShell/plugins/calculator/plugin.json Add .config/DankMaterialShell/plugins/calculator/screenshot.png Add .config/DankMaterialShell/plugins/calculator/test_precision.js Add .config/DankMaterialShell/plugins/calculator/test_single.js Add .config/DankMaterialShell/plugins/commandRunner/CommandRunner.qml Add .config/DankMaterialShell/plugins/commandRunner/CommandRunnerSettings.qml Add .config/DankMaterialShell/plugins/commandRunner/LICENSE Add .config/DankMaterialShell/plugins/commandRunner/README.md Add .config/DankMaterialShell/plugins/commandRunner/.git/HEAD Add .config/DankMaterialShell/plugins/commandRunner/.git/config Add .config/DankMaterialShell/plugins/commandRunner/.git/index Add .config/DankMaterialShell/plugins/commandRunner/.git/objects/info/.keep Add .config/DankMaterialShell/plugins/commandRunner/.git/objects/pack/pack-5a720f795fd2994ef506cd867d86ca7df8a25a31.idx Add .config/DankMaterialShell/plugins/commandRunner/.git/objects/pack/pack-5a720f795fd2994ef506cd867d86ca7df8a25a31.rev Add .config/DankMaterialShell/plugins/commandRunner/.git/objects/pack/pack-5a720f795fd2994ef506cd867d86ca7df8a25a31.pack Add .config/DankMaterialShell/plugins/commandRunner/.git/refs/heads/main Add .config/DankMaterialShell/plugins/commandRunner/.git/refs/remotes/origin/main Add .config/DankMaterialShell/plugins/commandRunner/.git/refs/tags/.keep Add .config/DankMaterialShell/plugins/commandRunner/plugin.json Add .config/DankMaterialShell/plugins/commandRunner/screenshot.png Add .config/DankMaterialShell/plugins/dankActions.meta Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankActions/DankActionsSettings.qml Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankActions/DankActionsWidget.qml Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankActions/plugin.json Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankBatteryAlerts/DankBatteryAlerts.qml Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankBatteryAlerts/DankBatteryAlertsSettings.qml Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankBatteryAlerts/plugin.json Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankHooks/DankHooks.qml Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankHooks/DankHooksSettings.qml Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankHooks/README.md Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankHooks/plugin.json Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankPomodoroTimer/DankPomodoroSettings.qml Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankPomodoroTimer/DankPomodoroWidget.qml Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/DankPomodoroTimer/plugin.json Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/LICENSE Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/README.md Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/HEAD Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/config Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/index Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/objects/info/.keep Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/objects/pack/pack-3221a15c022ef4a7bb6bf2c47e40068b66b3588b.idx Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/objects/pack/pack-3221a15c022ef4a7bb6bf2c47e40068b66b3588b.rev Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/objects/pack/pack-3221a15c022ef4a7bb6bf2c47e40068b66b3588b.pack Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/refs/heads/master Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/refs/remotes/origin/master Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.git/refs/tags/.keep Add .config/DankMaterialShell/plugins/.repos/0026f1eba8dedaec/.gitignore Add .config/DankMaterialShell/plugins/emojiLauncher/EmojiLauncher.qml Add .config/DankMaterialShell/plugins/emojiLauncher/EmojiLauncherSettings.qml Add .config/DankMaterialShell/plugins/emojiLauncher/LICENSE Add .config/DankMaterialShell/plugins/emojiLauncher/README.md Add .config/DankMaterialShell/plugins/emojiLauncher/catalog.js Add .config/DankMaterialShell/plugins/emojiLauncher/data/emojis.txt Add .config/DankMaterialShell/plugins/emojiLauncher/data/math.txt Add .config/DankMaterialShell/plugins/emojiLauncher/data/nerdfont.txt Add .config/DankMaterialShell/plugins/emojiLauncher/.git/HEAD Add .config/DankMaterialShell/plugins/emojiLauncher/.git/config Add .config/DankMaterialShell/plugins/emojiLauncher/.git/index Add .config/DankMaterialShell/plugins/emojiLauncher/.git/objects/info/.keep Add .config/DankMaterialShell/plugins/emojiLauncher/.git/objects/pack/pack-e04a5b1ea381dc3a792b8bf08cf70e735b195c0d.idx Add .config/DankMaterialShell/plugins/emojiLauncher/.git/objects/pack/pack-e04a5b1ea381dc3a792b8bf08cf70e735b195c0d.rev Add .config/DankMaterialShell/plugins/emojiLauncher/.git/objects/pack/pack-e04a5b1ea381dc3a792b8bf08cf70e735b195c0d.pack Add .config/DankMaterialShell/plugins/emojiLauncher/.git/refs/heads/main Add .config/DankMaterialShell/plugins/emojiLauncher/.git/refs/remotes/origin/main Add .config/DankMaterialShell/plugins/emojiLauncher/.git/refs/tags/.keep Add .config/DankMaterialShell/plugins/emojiLauncher/plugin.json Add .config/DankMaterialShell/plugins/emojiLauncher/screenshot.png Add .config/DankMaterialShell/plugins/emojiLauncher/scripts/generate_catalog.py Add .config/DankMaterialShell/plugins/dankActions Add .config/DankMaterialShell/plugins/webSearch/LICENSE Add .config/DankMaterialShell/plugins/webSearch/README.md Add .config/DankMaterialShell/plugins/webSearch/WebSearch.qml Add .config/DankMaterialShell/plugins/webSearch/WebSearchSettings.qml Add .config/DankMaterialShell/plugins/webSearch/.git/HEAD Add .config/DankMaterialShell/plugins/webSearch/.git/config Add .config/DankMaterialShell/plugins/webSearch/.git/index Add .config/DankMaterialShell/plugins/webSearch/.git/objects/info/.keep Add .config/DankMaterialShell/plugins/webSearch/.git/objects/pack/pack-6a60c736f418e5b4b1f0505f66c1e2a371d46fed.idx Add .config/DankMaterialShell/plugins/webSearch/.git/objects/pack/pack-6a60c736f418e5b4b1f0505f66c1e2a371d46fed.rev Add .config/DankMaterialShell/plugins/webSearch/.git/objects/pack/pack-6a60c736f418e5b4b1f0505f66c1e2a371d46fed.pack Add .config/DankMaterialShell/plugins/webSearch/.git/refs/heads/main Add .config/DankMaterialShell/plugins/webSearch/.git/refs/remotes/origin/main Add .config/DankMaterialShell/plugins/webSearch/.git/refs/tags/.keep Add .config/DankMaterialShell/plugins/webSearch/plugin.json Add .config/DankMaterialShell/plugins/webSearch/screenshot.png Add .config/DankMaterialShell/settings.json
173 lines
5.2 KiB
QML
173 lines
5.2 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
import qs.Services
|
|
|
|
Item {
|
|
id: root
|
|
|
|
property var pluginService: null
|
|
property string trigger: ">"
|
|
property var commandHistory: []
|
|
property int maxHistoryItems: 20
|
|
|
|
signal itemsChanged()
|
|
|
|
Component.onCompleted: {
|
|
console.log("CommandRunner: Plugin loaded")
|
|
|
|
if (pluginService) {
|
|
trigger = pluginService.loadPluginData("commandRunner", "trigger", ">")
|
|
commandHistory = pluginService.loadPluginData("commandRunner", "history", [])
|
|
maxHistoryItems = pluginService.loadPluginData("commandRunner", "maxHistoryItems", 20)
|
|
}
|
|
}
|
|
|
|
function getItems(query) {
|
|
const items = []
|
|
|
|
if (query && query.trim().length > 0) {
|
|
const command = query.trim()
|
|
|
|
items.push({
|
|
name: "Run: " + command,
|
|
icon: "material:terminal",
|
|
comment: "Execute command in terminal",
|
|
action: "run:" + command,
|
|
categories: ["Command Runner"]
|
|
})
|
|
|
|
items.push({
|
|
name: "Run in background: " + command,
|
|
icon: "material:step_over",
|
|
comment: "Execute command silently in background",
|
|
action: "background:" + command,
|
|
categories: ["Command Runner"]
|
|
})
|
|
|
|
items.push({
|
|
name: "Copy: " + command,
|
|
icon: "material:content_copy",
|
|
comment: "Copy command to clipboard",
|
|
action: "copy:" + command,
|
|
categories: ["Command Runner"]
|
|
})
|
|
}
|
|
|
|
if (commandHistory.length > 0) {
|
|
const filteredHistory = query
|
|
? commandHistory.filter(cmd => cmd.toLowerCase().includes(query.toLowerCase()))
|
|
: commandHistory
|
|
|
|
for (let i = 0; i < Math.min(10, filteredHistory.length); i++) {
|
|
const cmd = filteredHistory[i]
|
|
items.push({
|
|
name: cmd,
|
|
icon: "material:history",
|
|
comment: "Run from history",
|
|
action: "run:" + cmd,
|
|
categories: ["Command Runner"]
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return items
|
|
}
|
|
|
|
function executeItem(item) {
|
|
if (!item || !item.action) {
|
|
console.warn("CommandRunner: Invalid item or action")
|
|
return
|
|
}
|
|
|
|
console.log("CommandRunner: Executing item:", item.name, "with action:", item.action)
|
|
|
|
const actionParts = item.action.split(":")
|
|
const actionType = actionParts[0]
|
|
const command = actionParts.slice(1).join(":")
|
|
|
|
switch (actionType) {
|
|
case "noop":
|
|
return
|
|
case "copy":
|
|
copyToClipboard(command)
|
|
break
|
|
case "run":
|
|
runCommand(command)
|
|
break
|
|
case "background":
|
|
runBackground(command)
|
|
break
|
|
default:
|
|
console.warn("CommandRunner: Unknown action type:", actionType)
|
|
showToast("Unknown action: " + actionType)
|
|
}
|
|
}
|
|
|
|
function copyToClipboard(text) {
|
|
Quickshell.execDetached(["sh", "-c", "echo -n '" + text + "' | wl-copy"])
|
|
showToast("Copied to clipboard: " + text)
|
|
}
|
|
|
|
function runCommand(command) {
|
|
addToHistory(command)
|
|
const terminal = getTerminalCommand()
|
|
const wrappedCommand = command + "; echo '\nPress Enter to close...'; read"
|
|
Quickshell.execDetached([terminal.cmd, terminal.execFlag, "sh", "-c", wrappedCommand])
|
|
showToast("Running in " + terminal.cmd + ": " + command)
|
|
}
|
|
|
|
function runBackground(command) {
|
|
addToHistory(command)
|
|
Quickshell.execDetached(["sh", "-c", command])
|
|
showToast("Running in background: " + command)
|
|
}
|
|
|
|
function showToast(message) {
|
|
if (typeof ToastService !== "undefined") {
|
|
ToastService.showInfo("Command Runner", message)
|
|
} else {
|
|
console.log("CommandRunner Toast:", message)
|
|
}
|
|
}
|
|
|
|
function getTerminalCommand() {
|
|
if (pluginService) {
|
|
const terminal = pluginService.loadPluginData("commandRunner", "terminal", "kitty")
|
|
const execFlag = pluginService.loadPluginData("commandRunner", "execFlag", "-e")
|
|
if (terminal && execFlag) {
|
|
return {cmd: terminal, execFlag: execFlag}
|
|
}
|
|
}
|
|
|
|
return {cmd: "kitty", execFlag: "-e"}
|
|
}
|
|
|
|
function addToHistory(command) {
|
|
const index = commandHistory.indexOf(command)
|
|
if (index > -1) {
|
|
commandHistory.splice(index, 1)
|
|
}
|
|
|
|
commandHistory.unshift(command)
|
|
|
|
if (commandHistory.length > maxHistoryItems) {
|
|
commandHistory = commandHistory.slice(0, maxHistoryItems)
|
|
}
|
|
|
|
if (pluginService) {
|
|
pluginService.savePluginData("commandRunner", "history", commandHistory)
|
|
}
|
|
|
|
itemsChanged()
|
|
}
|
|
|
|
onTriggerChanged: {
|
|
if (pluginService) {
|
|
pluginService.savePluginData("commandRunner", "trigger", trigger)
|
|
}
|
|
itemsChanged()
|
|
}
|
|
}
|