Skip to content

Instantly share code, notes, and snippets.

@hluk
Created November 19, 2015 07:30
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hluk/95889230aeea2388dea5 to your computer and use it in GitHub Desktop.
Save hluk/95889230aeea2388dea5 to your computer and use it in GitHub Desktop.
CopyQ - Search All Tabs
[Command]
Name=Search All Tabs
Command="
copyq:
// Name for tab for storing matching items.
var search_tab_name = \"Search\"
// Returns true iff item at index matches regex.
function item_matches(item_index, re)
{
var text = str(read(j))
return text && re.test(text)
}
// Ask for search expression.
var match = dialog(\"Search\")
if (!match)
abort()
var re = new RegExp(match)
// Clear tab with results.
try {
removeTab(search_tab_name)
} catch (e) {}
// Search all tabs.
var tab_names = tab()
for (var i in tab_names) {
var tab_name = tab_names[i]
tab(tab_name)
var item_count = count()
// Search all items in tab.
for (var j = 0; j < item_count; ++j) {
// Add matching item to tab with results.
if (item_matches(j, re)) {
var item = getItem(j)
tab(search_tab_name)
setItem(j, item)
tab(tab_name)
}
}
}
show(search_tab_name)"
InMenu=true
Icon=\xf002
Shortcut=Ctrl+Shift+F
@hluk
Copy link
Author

hluk commented Mar 24, 2017

@NA0341
Copy link

NA0341 commented Jan 19, 2022

Found a little syntax error
line 8: 'iff' to 'if'

Thank you for this great little tool!
It's very useful for searches when you're in a hurry and don't remember the tab in your well - organized collection 😉.
As it copies all matching results, a WARNING text may be useful:

WARNING: This duplicates all results into a new tab named "Search". Use with caution if you have huge amounts of data in tabs!

@hluk
Copy link
Author

hluk commented Jan 19, 2022

@NA0341 Thanks for kind words! BTW, "iff" means "if and only if". 😉

@int-369
Copy link

int-369 commented Feb 3, 2023

First of all, all the praises of this world for such a good program. CopyQ saves a lot of my precious time!

What should be added or changed in the upper "Search All Tabs" command that would search case insensitive? For example, searching "hello world" would find "Hello Worl" and all their similarities like "HeLlo WoRld" and so on.

It is possible to find hits stored inside notes of the stored items (shift+F2)? There I have comments in a few keywords about specific code blocks and is more readable to me.

Thank you very much for your reply.

@hluk
Copy link
Author

hluk commented Feb 7, 2023

The search is already case-insensitive in the new repo: https://github.com/hluk/copyq-commands/tree/master/Application#search-all-tabs

@sudior
Copy link

sudior commented Oct 19, 2023

how to add this .ini file to application?
i have downloaded search all tabs how to add to application i am using windows .

@hluk
Copy link
Author

hluk commented Oct 19, 2023

how to add this .ini file to application?

See README.md for details on how to add the command.

@NA0341
Copy link

NA0341 commented Dec 17, 2023

@NA0341 Thanks for kind words! BTW, "iff" means "if and only if". 😉

You're very welcome!
Your application is so important in my digital life that I can't even imagine what it'd be like to not have it.
…and there are some features I'd like to see get implemented too. They're mostly rather easy to do - but can greatly enhance the scope in which CopyQ can convieniently be used for.

Since it's been a long time since I first had this idea - I took the time to create the according card: hluk/CopyQ#2577

@tjbiking
Copy link

tjbiking commented Jan 8, 2024

How to include tags in the search?

@NA0341
Copy link

NA0341 commented Jan 14, 2024

How to include tags in the search?

For that you'd need to specify the according variable in the script & let the search function include the tags. I guess that'd be line 36

@tjbiking
Copy link

tjbiking commented Jan 14, 2024 via email

@vysmaty
Copy link

vysmaty commented Apr 10, 2024

Would anyone know how to add the tag search? I can't figure out how to get that information. Thank you.

    var tag = str(item[mimeTag])
    return text && (re.test(text) || re.test(note) || re.test(tag))

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