/*EVERYTHING IN XYPLORER — Rev. 0.94 / 2014/07/09.################################################# The code is divided into logical sections, each one identified by a line in the form "/*TITLE.###…" . Below that line a comment section like this one is found, which summarizes what happens below. -------------------------------------------------------------------------------------------------*/ /*ES.EXE SYNTAX.################################################################################### -r Search the database using a basic POSIX regular expression. -i Does a case sensitive search. -w Does a whole word search. -p Does a full path search. -h --help Display this help. -n Limit the amount of results shown to . -s Sort by full path. Note: a query containing a minus preceded by a blank (or in first position) and not followed by any of the letters above always produces the help, and no search results. -------------------------------------------------------------------------------------------------*/ /*CUSTOMIZATIONS.################################################################################## Here three parameters can be customized: $path: the path of the folder containing the es.exe executable, with a final slash. The default assumes - reasonably - that XYplorer and Everything, being both portable, reside in the same root folder; $paper: the name of the paper folder containing the search results; $mode: controls how the minus sign, which introduces switches in es.exe, is treated/escaped. Three modes are available. Total: Everything in Xyplorer will behave as if it was a window of Everything. The minus sign will ALWAYS be escaped with double quotes, thus the functionality provided by es.exe switches won't be available, however the search syntax will absolutely be the same of that of the graphical user interface of Everything; Smart: Everything in Xyplorer will behave as an "advanced" interface to es.exe. The minus sign will be escaped with double quotes AS LONG AS it is not introducing a switch, EXCEPT for -h, --help and -n when NOT followed by a blank and one or more digits. This mode allows the use of switches, keeping at the same time the syntax of search queries involving actual hypens identical to the one used by Everything. In order for it to work properly, non-ambiguous syntax must be entered, i.e. if you really want to look for an item named "-p" (without quotes) then you must quote it. The odds of such kind of queries are low so the attention required for such corner cases is a more than acceptable tradeoff for the smartness provided by this mode. Also known as "The best of the two worlds…™"; None: the minus sign will NEVER be escaped, giving full control on how each minus is passed to the command line. Remember: proper escaping consists of double quotes for a "text" minus, while a "switch" minus shall not be modified. Whatever mode is entered that doesn't match "Total" or "Smart" is treated as "None". -------------------------------------------------------------------------------------------------*/ $path = "\..\Everything\"; //"\..\Everything\" $paper = "Everything in XYplorer.txt"; //"Everything in XYplorer.txt" $mode = "Smart"; //"Smart" /*GO!############################################################################################## Despite being the core part, the following code is quite simple. First of all, the user is asked to enter the search query. Then the minus sign is escaped according to the mode set above. Susbsequently, other special characters are escaped, namely the ones that can be used as search modifiers in Everything or in a normal regular expression and that are known to be "problematic" in a command line. Further info on http://forum.voidtools.com/viewtopic.php?f=5&t=1970&sid=2590f752481d94429e91191e55b6a261 and http://www.robvanderwoude.com/escapechars.php Once a "command line-friendly" query is obtained, the proper command can be run. In order to deal with Unicode the codepage of the console must be changed to 65001 (UTF-8) with the chcp command. Fortunately this change is temporary, so this is a portable/stealth solution that doesn't alter the system. The call to es.exe can simply be concatenated ( && ). Unfortunately though, the console still won't be able to display CJK characters, so runret() isn't a border-less solution, and the old-school redirection (appending, actually) to an output file ( >> ) is the only way. The console will write to disk a list of matches encoded in UTF-8 without BOM. For some unknown reasons (read: bug?) currently under investigation, XYplorer can preview correctly a BOM-less UTF-8 text file but, as soon as it processes it as a paper folder, it will generate gibberish in place of CJK characters. Therefore a little trick is required: the BOM of the future paper folder file is written beforehand. In order to be immune to variations in system encoding/locale/codepage, the BOM is provided to the writefile() function as a conversion from hex values (0xEF 0xBB 0xBF). After the invisible console window has done its job (synchronously) XYplorer will open the paper folder with the desired search results in a new tab, unless the current tab is already browsing a paper folder of Everything in XYplorer: then the current tab is used. Also, the status bar will show the search query. And that's all, folks. -------------------------------------------------------------------------------------------------*/ $query = input("Everything in XYplorer", "Type your search query as you would in Everything", "Everything is awesome… [it's a movie quote ツ]", "s"); if ("$mode" == "Smart") { $cl = regexreplace("$query", '\B-(?!([riwps]|n (?!\D))\b)', '"-"'); } elseif ("$mode" == "Total") { $cl = replace("$query", '-', '"-"'); }; $cl = replacelist("$cl", '< > & | ^ "', '^< ^> ^& ^| ^^ \"', " "); writefile("\$paper", hexdump("EFBBBF", , "ri"), , "b"); run "cmd /c chcp 65001 && es $cl >> ""\$paper""", "$path", 2, 0; tab((tab("get", "path") == "paper:\$paper")?"relocate":"new", "paper:\$paper"); status "Everything in XYplorer: $query";