-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPassLauncher.qml
More file actions
163 lines (136 loc) · 4.62 KB
/
PassLauncher.qml
File metadata and controls
163 lines (136 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Services
import qs.Common
import "fuzzy.js" as Fuzzy
Item {
id: root
// Required properties
property var pluginService: null
property string pluginId: "dmsPass"
property string trigger: "pass"
// Internal properties
property var _entries: []
property bool _indexing: false
// Required signal
signal itemsChanged()
Component.onCompleted: {
if (pluginService) {
trigger = pluginService.loadPluginData(pluginId, "trigger", "pass")
}
reloadEntries()
}
onTriggerChanged: {
if (pluginService) {
pluginService.savePluginData(pluginId, "trigger", trigger)
}
}
function reloadEntries() {
if (_indexing) return
_indexing = true
_entries = []
indexProcessComp.createObject(root).running = true
}
function getItems(query) {
const results = []
if (!_entries.length) {
return results
}
// If no query, just return everything (or a subset)
if (!query || query.trim().length === 0) {
// Just show first 50 alphabetically
for (let i = 0; i < Math.min(50, _entries.length); i++) {
results.push(formatEntry(_entries[i]))
}
return results
}
const scored = []
for (let i = 0; i < _entries.length; i++) {
const entry = _entries[i]
const score = Fuzzy.fuzzyScore(query, entry)
if (score !== null) {
scored.push({ entry: entry, score: score })
}
}
// Sort by score (descending)
scored.sort((a, b) => b.score - a.score)
const limit = 50
for (let i = 0; i < Math.min(limit, scored.length); i++) {
results.push(formatEntry(scored[i].entry))
}
return results
}
function formatEntry(entry) {
// Example entry: "social/facebook/myuser"
// Title: "social/facebook"
// Comment: "myuser"
// If it's just "facebook", Title="facebook", Comment=""
const lastSlash = entry.lastIndexOf('/')
let name = entry
let comment = ""
if (lastSlash !== -1) {
name = entry.substring(0, lastSlash)
comment = entry.substring(lastSlash + 1)
} else {
// If no folder, usually it's "service" or "service.com"
// Often people do "service/username".
// If just "service", name="service", comment=""
}
return {
name: name,
icon: "material:vpn_key",
comment: comment,
action: "pass:" + entry,
categories: ["Pass"],
keywords: ["pass", entry]
}
}
function executeItem(item) {
if (!item || !item.action) return
const action = item.action
if (action.startsWith("pass:")) {
const entry = action.substring(5)
const cmd = "pass -c " + shellQuote(entry)
Quickshell.execDetached(["sh", "-c", cmd])
if (typeof ToastService !== "undefined") {
ToastService.showInfo("Pass: " + entry + " copied to clipboard")
}
}
}
function getContextMenuActions(item) {
if (!item) return []
return [
{
icon: "content_copy",
text: "Copy Password",
action: () => executeItem(item)
}
]
}
function shellQuote(s) {
return "'" + s.replace(/'/g, "'\\''") + "'"
}
property Component indexProcessComp: Component {
Process {
command: ["sh", "-c", "cd \"${PASSWORD_STORE_DIR:-$HOME/.password-store}\" && find . -name '*.gpg' -type f"]
stdout: SplitParser {
onRead: function(line) {
let s = line.trim()
if (!s) return
if (s.startsWith("./")) s = s.substring(2)
if (s.endsWith(".gpg")) s = s.substring(0, s.length - 4)
root._entries.push(s)
}
}
onExited: function(code) {
console.info("[dms-pass] Indexing finished with code " + code + ". Found " + root._entries.length + " entries.")
// Initial sort is nice for the "no query" state
root._entries.sort()
root._indexing = false
root.itemsChanged()
destroy()
}
}
}
}