forked from Shinonome/dots-hyprland
add superpaste
This commit is contained in:
@@ -53,7 +53,7 @@ Rectangle {
|
|||||||
Process {
|
Process {
|
||||||
id: decodeImageProcess
|
id: decodeImageProcess
|
||||||
command: ["bash", "-c",
|
command: ["bash", "-c",
|
||||||
`[ -f ${imageDecodeFilePath} ] || echo '${StringUtils.shellSingleQuoteEscape(root.entry)}' | cliphist decode > '${imageDecodeFilePath}'`
|
`[ -f ${imageDecodeFilePath} ] || echo '${StringUtils.shellSingleQuoteEscape(root.entry)}' | ${Cliphist.cliphistBinary} decode > '${imageDecodeFilePath}'`
|
||||||
]
|
]
|
||||||
onExited: (exitCode, exitStatus) => {
|
onExited: (exitCode, exitStatus) => {
|
||||||
if (exitCode === 0) {
|
if (exitCode === 0) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// pragma NativeMethodBehavior: AcceptThisObject
|
// pragma NativeMethodBehavior: AcceptThisObject
|
||||||
import qs
|
import qs
|
||||||
|
import qs.services
|
||||||
import qs.modules.common
|
import qs.modules.common
|
||||||
import qs.modules.common.widgets
|
import qs.modules.common.widgets
|
||||||
import qs.modules.common.functions
|
import qs.modules.common.functions
|
||||||
@@ -89,8 +90,8 @@ RippleButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
root.itemExecute()
|
|
||||||
GlobalStates.overviewOpen = false
|
GlobalStates.overviewOpen = false
|
||||||
|
root.itemExecute()
|
||||||
}
|
}
|
||||||
Keys.onPressed: (event) => {
|
Keys.onPressed: (event) => {
|
||||||
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
|
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
|
||||||
@@ -201,7 +202,7 @@ RippleButton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loader { // Clipboard image preview
|
Loader { // Clipboard image preview
|
||||||
active: root.cliphistRawString && /^\d+\t\[\[.*binary data.*\d+x\d+.*\]\]$/.test(root.cliphistRawString)
|
active: root.cliphistRawString && Cliphist.entryIsImage(root.cliphistRawString)
|
||||||
sourceComponent: CliphistImage {
|
sourceComponent: CliphistImage {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
entry: root.cliphistRawString
|
entry: root.cliphistRawString
|
||||||
|
|||||||
@@ -37,12 +37,24 @@ Item { // Wrapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
property var searchActions: [
|
property var searchActions: [
|
||||||
|
{
|
||||||
|
action: "accentcolor",
|
||||||
|
execute: args => {
|
||||||
|
Quickshell.execDetached([Directories.wallpaperSwitchScriptPath, "--noswitch", "--color", ...(args != '' ? [`${args}`] : [])]);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
action: "dark",
|
action: "dark",
|
||||||
execute: () => {
|
execute: () => {
|
||||||
Quickshell.execDetached([Directories.wallpaperSwitchScriptPath, "--mode", "dark", "--noswitch"]);
|
Quickshell.execDetached([Directories.wallpaperSwitchScriptPath, "--mode", "dark", "--noswitch"]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
action: "konachanwallpaper",
|
||||||
|
execute: () => {
|
||||||
|
Quickshell.execDetached([Quickshell.shellPath("scripts/colors/random_konachan_wall.sh")]);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
action: "light",
|
action: "light",
|
||||||
execute: () => {
|
execute: () => {
|
||||||
@@ -50,21 +62,21 @@ Item { // Wrapper
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: "wall",
|
action: "superpaste",
|
||||||
execute: () => {
|
|
||||||
Quickshell.execDetached([Directories.wallpaperSwitchScriptPath]);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
action: "konachanwall",
|
|
||||||
execute: () => {
|
|
||||||
Quickshell.execDetached([Quickshell.shellPath("scripts/colors/random_konachan_wall.sh")]);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
action: "accentcolor",
|
|
||||||
execute: args => {
|
execute: args => {
|
||||||
Quickshell.execDetached([Directories.wallpaperSwitchScriptPath, "--noswitch", "--color", ...(args != '' ? [`${args}`] : [])]);
|
if (!/^(\d+)/.test(args.trim())) { // Invalid if doesn't start with numbers
|
||||||
|
Quickshell.execDetached([
|
||||||
|
"notify-send",
|
||||||
|
Translation.tr("Superpaste"),
|
||||||
|
Translation.tr("Usage: <tt>%1superpaste NUM_OF_ENTRIES[i]</tt>\nSupply <tt>i</tt> when you want images\nExamples:\n<tt>%1superpaste 4i</tt> for the last 4 images\n<tt>%1superpaste 7</tt> for the last 7 entries").arg(Config.options.search.prefix.action),
|
||||||
|
"-a", "Shell"
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const syntaxMatch = /^(?:(\d+)(i)?)/.exec(args.trim());
|
||||||
|
const count = syntaxMatch[1] ? parseInt(syntaxMatch[1]) : 1;
|
||||||
|
const isImage = !!syntaxMatch[2];
|
||||||
|
Cliphist.superpaste(count, isImage);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -73,6 +85,12 @@ Item { // Wrapper
|
|||||||
Todo.addTask(args);
|
Todo.addTask(args);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
action: "wallpaper",
|
||||||
|
execute: () => {
|
||||||
|
GlobalStates.wallpaperSelectorOpen = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
function focusFirstItem() {
|
function focusFirstItem() {
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\)
|
|||||||
function handleEntry(entry: string) {
|
function handleEntry(entry: string) {
|
||||||
imageDecodeFileName = parseInt(entry.match(/^(\d+)\t/)[1])
|
imageDecodeFileName = parseInt(entry.match(/^(\d+)\t/)[1])
|
||||||
decodeImageAndAttachProc.exec(["bash", "-c",
|
decodeImageAndAttachProc.exec(["bash", "-c",
|
||||||
`[ -f ${imageDecodeFilePath} ] || echo '${StringUtils.shellSingleQuoteEscape(entry)}' | cliphist decode > '${imageDecodeFilePath}'`
|
`[ -f ${imageDecodeFilePath} ] || echo '${StringUtils.shellSingleQuoteEscape(entry)}' | ${Cliphist.cliphistBinary} decode > '${imageDecodeFilePath}'`
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
onExited: (exitCode, exitStatus) => {
|
onExited: (exitCode, exitStatus) => {
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ import Quickshell.Io
|
|||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
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 bool sloppySearch: Config.options?.search.sloppy ?? false
|
||||||
property real scoreThreshold: 0.2
|
property real scoreThreshold: 0.2
|
||||||
property list<string> entries: []
|
property list<string> entries: []
|
||||||
@@ -35,19 +39,48 @@ Singleton {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function entryIsImage(entry) {
|
||||||
|
return !!(/^\d+\t\[\[.*binary data.*\d+x\d+.*\]\]$/.test(entry))
|
||||||
|
}
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
readProc.buffer = []
|
readProc.buffer = []
|
||||||
readProc.running = true
|
readProc.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy(entry) {
|
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 {
|
Process {
|
||||||
id: deleteProc
|
id: deleteProc
|
||||||
property string entry: ""
|
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) {
|
function deleteEntry(entry) {
|
||||||
deleteProc.entry = entry;
|
deleteProc.entry = entry;
|
||||||
deleteProc.running = true;
|
deleteProc.running = true;
|
||||||
@@ -82,7 +115,7 @@ Singleton {
|
|||||||
id: readProc
|
id: readProc
|
||||||
property list<string> buffer: []
|
property list<string> buffer: []
|
||||||
|
|
||||||
command: ["cliphist", "list"]
|
command: [root.cliphistBinary, "list"]
|
||||||
|
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: (line) => {
|
onRead: (line) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user