add superpaste

This commit is contained in:
end-4
2025-08-31 17:21:55 +02:00
parent f1b1589a7d
commit 53b6f5d8e8
5 changed files with 74 additions and 22 deletions
+37 -4
View File
@@ -9,6 +9,10 @@ import Quickshell.Io
Singleton {
id: root
// property string cliphistBinary: FileUtils.trimFileProtocol(`${Directories.home}/.cargo/bin/stash`)
property string cliphistBinary: "cliphist"
property real pasteDelay: 0.05
property string pressPasteCommand: "ydotool key -d 1 29:1 47:1 47:0 29:0"
property bool sloppySearch: Config.options?.search.sloppy ?? false
property real scoreThreshold: 0.2
property list<string> entries: []
@@ -35,19 +39,48 @@ Singleton {
});
}
function entryIsImage(entry) {
return !!(/^\d+\t\[\[.*binary data.*\d+x\d+.*\]\]$/.test(entry))
}
function refresh() {
readProc.buffer = []
readProc.running = true
}
function copy(entry) {
Quickshell.execDetached(["bash", "-c", `echo '${StringUtils.shellSingleQuoteEscape(entry)}' | cliphist decode | wl-copy`]);
if (root.cliphistBinary.includes("cliphist")) // Classic cliphist
Quickshell.execDetached(["bash", "-c", `printf '${StringUtils.shellSingleQuoteEscape(entry)}' | ${root.cliphistBinary} decode | wl-copy`]);
else { // Stash
const entryNumber = entry.split("\t")[0];
Quickshell.execDetached(["bash", "-c", `${root.cliphistBinary} decode ${entryNumber} | wl-copy`]);
}
}
function paste(entry) {
if (root.cliphistBinary.includes("cliphist")) // Classic cliphist
Quickshell.execDetached(["bash", "-c", `printf '${StringUtils.shellSingleQuoteEscape(entry)}' | ${root.cliphistBinary} decode | wl-copy && wl-paste`]);
else { // Stash
const entryNumber = entry.split("\t")[0];
Quickshell.execDetached(["bash", "-c", `${root.cliphistBinary} decode ${entryNumber} | wl-copy; ${root.pressPasteCommand}`]);
}
}
function superpaste(count, isImage = false) {
// Find entries
const targetEntries = entries.filter(entry => {
if (!isImage) return true;
return entryIsImage(entry);
}).slice(0, count)
const pasteCommands = [...targetEntries].reverse().map(entry => `printf '${StringUtils.shellSingleQuoteEscape(entry)}' | ${root.cliphistBinary} decode | wl-copy && sleep ${root.pasteDelay} && ${root.pressPasteCommand}`)
// Act
Quickshell.execDetached(["bash", "-c", pasteCommands.join(` && sleep ${root.pasteDelay} && `)]);
}
Process {
id: deleteProc
property string entry: ""
command: ["bash", "-c", `echo '${StringUtils.shellSingleQuoteEscape(deleteProc.entry)}' | cliphist delete`]
command: ["bash", "-c", `echo '${StringUtils.shellSingleQuoteEscape(deleteProc.entry)}' | ${root.cliphistBinary} delete`]
function deleteEntry(entry) {
deleteProc.entry = entry;
deleteProc.running = true;
@@ -81,8 +114,8 @@ Singleton {
Process {
id: readProc
property list<string> buffer: []
command: ["cliphist", "list"]
command: [root.cliphistBinary, "list"]
stdout: SplitParser {
onRead: (line) => {