Skip to content

Instantly share code, notes, and snippets.

@hluk
Last active July 14, 2022 18:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hluk/c64f91454c6983fb5433 to your computer and use it in GitHub Desktop.
Save hluk/c64f91454c6983fb5433 to your computer and use it in GitHub Desktop.
CopyQ 2.3.0 user commands to move items to trash and undo the removal
[Commands]
1\Name=Move to Trash (Undoable)
1\Command="
copyq:
trash_tab = \"(trash)\"
tab_mime = \"application/x-copyq-user-tab\"
index_mime = \"application/x-copyq-user-index\"
time_mime = \"application/x-copyq-user-time\"
time = (new Date).toISOString()
source_tab = selectedtab()
tab(source_tab)
items = selecteditems()
if (source_tab != trash_tab) {
for (i in items) {
item = getitem(items[i])
item[tab_mime] = source_tab
item[index_mime] = items[i]
item[time_mime] = time
tab(trash_tab)
setitem(i, item)
tab(source_tab)
}
}
remove.apply(this, items)"
1\InMenu=true
1\Icon=\xf014
1\Shortcut=Del
2\Name=Undo Delete
2\Command="
copyq:
trash_tab = \"(trash)\"
tab_mime = \"application/x-copyq-user-tab\"
index_mime = \"application/x-copyq-user-index\"
time_mime = \"application/x-copyq-user-time\"
remove_mime = [tab_mime, index_mime, time_mime]
tab(trash_tab)
item = getitem(0)
time = str(item[time_mime])
select_items = []
remove_items = []
target_tab = str(item[tab_mime])
while (true) {
index = item[index_mime]
for (i in remove_mime)
delete item[remove_mime[i]]
tab(target_tab ? target_tab : selectedtab())
setitem(index, item)
select_items.push(index)
var i = remove_items.length
remove_items.push(i)
tab(trash_tab)
item = getitem(i + 1)
if ( !time || time !== str(item[time_mime]) )
break;
}
if (target_tab)
show(target_tab)
tab(selectedtab())
selectitems.apply(this, select_items)
tab(trash_tab)
remove.apply(this, remove_items)"
2\InMenu=true
2\Icon=\xf112
2\Shortcut=Ctrl+Z
size=2
@hluk
Copy link
Author

hluk commented Mar 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment