Last active
March 11, 2018 23:48
-
-
Save hluk/de52be0fb01024dd8f7b to your computer and use it in GitHub Desktop.
CopyQ 2.3.0 user commands to add frequent items to special tab and to show frequent items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Commands] | |
1\Name=Activate and Add to Frequent | |
1\Command=" | |
copyq: | |
tab_name = \"Frequent\" | |
source = selectedtab() | |
tab(source) | |
items = selecteditems() | |
p = \"application/x-copyq-\" | |
freq_mime = p + \"user-frequency\" | |
ignored = [ | |
freq_mime, | |
p + \"owner\", | |
p + \"owner-window-title\", | |
] | |
function items_equal(item, i) { | |
for (var mime in item) { | |
if ( str(read(mime, i)) !== str(item[mime]) ) | |
return false | |
} | |
return true | |
} | |
function index_of_item(item) { | |
for (var i = 0; i < size(); ++i) { | |
if (items_equal(item, i)) | |
return i | |
} | |
return -1 | |
} | |
function get_freq(i) { | |
return parseInt(str(read(freq_mime, i))) || 0 | |
} | |
function find_index_for_frequency(freq) { | |
for (var i = 0; i < size(); ++i) { | |
if (freq >= get_freq(i)) | |
return i | |
} | |
return size() | |
} | |
for (i in items) { | |
item = getitem(items[i]) | |
for (j in ignored) | |
delete item[ignored[j]]; | |
tab(tab_name) | |
j = index_of_item(item) | |
if (j !== -1) { | |
item[freq_mime] = freq = get_freq(j) + 1 | |
remove(j) | |
j = find_index_for_frequency(freq) | |
} else { | |
j = size() | |
} | |
setitem(j, item) | |
tab(source) | |
} | |
select(items) | |
tab(tab_name) | |
selectitems([0]) | |
if ( config(\"activate_closes\") == \"true\" ) hide() | |
if ( config(\"activate_pastes\") == \"true\" ) paste()" | |
1\InMenu=true | |
1\Icon=\xf004 | |
1\Shortcut=Return, Enter | |
2\Name=Show Frequent | |
2\Command=copyq menu \"Frequent\" | |
2\Icon=\xf004 | |
2\GlobalShortcut=Meta+Shift+F | |
size=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moved to copyq-commands repository.