topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday December 10, 2024, 9:06 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Request: enhanced dosearch command that customizes results lines  (Read 7219 times)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
The FARR command dosearch lets an alias perform a new search and display the results. We can use search folder modifier keys and trigger long search patterns from a short alias. Great! But dosearch has no options to adjust the results line for each search match.

This request is an enhanced dosearch command, call it dosearchformatresults, that lets us format the search result lines.

One idea for the syntax is to put result formatting at the end after a frontslash and keyword, like for the FARR window options and /icon=... instructions. Like this
dosearchformatresults <regular dosearch syntax here> /result=<result formatting here>

The result formatting part would have the syntax we can use for results in aliases plus special variables related to each search match file. Example:
%filename% | showfilehtml %filepath%
In this example FARR would perform a dosearch for .html files and then for each match show a result line that when triggered shows the .html files inside FARR, rather than open it in the default .html application (external browser).

Probably some more complex escaping of characters and other ways to avoid weird conflicts/loops would be needed (recursive dosearchformatresults might cause weird issues for example  :D).

We can already achieve something like what I'm requesting via external scripts and appcapresults. But that is complex and FARR could probably do it quicker. The external workflow steps goes like this:
- FARR alias that passes a regex match from the typed string in FARR to an external script via dolaunch and appcapresult
dolaunch appcapresult C:\externalscript.exe $$2
- external script that searches some folder for e.g. .html files with filenames that match the passed string(s)
- for each match prepare a result line with the showfilehtml command
- result lines are passed back to FARR via stdout when the script exits
- FARR's appcapresult reads the results and displays them
- the user selects a result and presses Enter to view the HTML page inside FARR
In this external workflow FARR starts an external process and waits for it to finish for each typed character, which I've seen can cause some slowdowns.

This animation illustrates how it looks.
https://i.imgur.com/6LEOsFM.mp4

The .html files in the illustration are derived from the TLDR project - a neat collection of short usage examples for CLI commands in Linux/Windows -  that I've converted from Markdown (previous post related to that).
« Last Edit: October 28, 2020, 03:20 PM by Nod5 »

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Request: enhanced dosearch command that customizes results lines
« Reply #1 on: October 26, 2020, 11:55 AM »
I thought of another way to accomplish similar effects via hotkeys. A quick brainstorm on that.

We can already create FARR hotkeys that takes the selected file result (or first file result if no selection) from the previous search and makes a new search. That can be combined with an alias that when triggered immediately shows a filepath as HTML in FARR.

For example in FARR set up the hotkey Ctrl+H with option "Set Search text ..." enabled and this string
html_alias %CURRENTRESULTNB%

Then create the alias
name: html_alias
regex: ^(html_alias) (.+)$
result: dolaunch showfilehtml $$2

Now Ctrl+H will try to show the currently selected (or first) FARR file search result as HTML inside FARR.

A problem with this, though, is that FARR creates global hotkeys so pressing Ctrl+H in other windows will open FARR.

That problem could be solved if FARR got an option to choose if a custom hotkey should be global or local. Another solution is to create the hotkey in AutoHotkey instead, and have it mimic what the FARR hotkey above does.

A more advanced idea along these hotkey lines is to let the effect of a hotkey be conditional on the contents of the FARR search box. For example if the search box starts with "tl " (my example alias in the first post) then Enter would open the selected file result as HTML in FARR. In other cases Enter would work like usual (open file in default application). This could be done by enhancing the FARR hotkeys features. Or again as an external AutoHotkey script.

edit:
We can skip the extra alias step by using FARR's command line options. Simple AutoHotkey example for a local hotkey to show the selected (or first) FARR result as HTML.

Code: Autohotkey [Select]
  1.  
  2. ; hotkey Control + H when FARR window is active to show selected (or first) FARR result file as HTML
  3. ; 2020-10-27
  4. ; note: using this hotkey on non-HTML files is unpredictable, may freeze/crash FARR
  5.  
  6. #IfWinActive, ahk_exe FindAndRunRobot.exe
  7. ^h:: RunWait "C:\Program Files (x86)\FindAndRunRobot\FindAndRunRobot.exe" -launch "showfilehtml `%CURRENTRESULTNB`%"
  8.  
  9. ; references:
  10. ; https://www.donationcoder.com/Software/Mouser/findrun/help/commnadline_options.htm
  11. ;   "-launch = start FARR (or invoke in a running copy) and launch a command (can use any normal FARR launch strings ..."
  12. ; https://www.donationcoder.com/Software/Mouser/findrun/help/virtual_launch_strings.htm
  13. ;   "showfilehtml FILENAME - show a file in html mode"
  14. ; https://www.donationcoder.com/Software/Mouser/findrun/help/virtual_folder_names.htm
  15. ;   "%CURRENTRESULT% - currently selected result; useful for creating hotkeys that use it, etc.; blank if nothing selected"
  16. ;   "%CURRENTRESULTNB% - same as above, but = first result if nothing selected"

This can also be expanded to use the command line to first read the FARR result to clipboard (-launch "copyclip %CURRENTRESULTNB%"), add code steps to verify that it is a .html (or do some other checks) and only the file passes those tests show it as HTML. But every roundtrip via the command line to FARR takes ~150ms in my tests.

@mouser: it would be neat if we could do anything the FARR CLI "-launch" syntax lets us do but through SendMessage, to save the time currently wasted by starting/closing the command line process.

« Last Edit: October 27, 2020, 08:37 AM by Nod5 »

skajfes

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 267
    • View Profile
    • Donate to Member
Re: Request: enhanced dosearch command that customizes results lines
« Reply #2 on: October 28, 2020, 03:28 AM »
You can do this thing now, with this set of aliases:

1000>>>html>->showfilehtml $$1
1000>>>search for html>->dosearch $$1 -\ C:\path\here +html>+>^hh (.*)

The first one is a helper alias, you can use to show any file as html by appending +html to the search.

The second one uses the helper, but restricting the search and providing a short alias for it. It is triggered by typing "hh " and filtering the results down. You can add additional filters to the alias, to remove the folders (-\), to search in a specific folder (C:\path\here), or event a set of search folders each with own rules (+myfoldergroup).

I actually use this setup to help searching for code on my pc, and opening a console window in the project folders etc, works beautifully.

Relevant docs:
https://www.donation..._action_keywords.htm
https://www.donation...rch_to_files_or_.htm
It is impossible to make anything foolproof because fools are so ingenious.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Request: enhanced dosearch command that customizes results lines
« Reply #3 on: October 28, 2020, 02:03 PM »
You can do this thing now, with this set of aliases

Thanks skajfes! I forgot about alias action keywords when I wrote the previous posts  :-[
I also now realize that I wasn't clearly separating two distinct goals  :-[

Goal 1. customization of how the results look while we type and FARR narrows down the search for files and folders
Goal 2. custom actions for search results once we press Enter (or another keyboard shortcut), e.g. show results as HTML in FARR.

My first post mixed goals 1 and 2 and my second post shifted only to only cover goal 2.
Your suggestion with alias action keywords is great for goal 2. Simpler and faster than my AutoHotkey script workarounds.

Here is my variant of the two alias method you describe to make Enter perform the action show result as HTML in FARR.

alias1: html_alias
regex: <nothing>
result: showfilehtml $$1

alias2: tldr
regex: ^tl (.*)
result: dosearch +html_modifier $$1 +html_alias -alias

In FARR options create a search folder with the location of the .html files and the keyword "html_modifier".
I added -alias in the regex above since otherwise the search also matched other aliases at the top of the results list.
I put the +html_modifier before the $$1 variable because otherwise dosearch triggered another alias I had whose regex reacts to a space at the start of a FARR search.


So far goal 1. Now let us talk about goal 2
Do you know any way for alias action keywords to customize how the search results list looks while we search for files in a folder? I can right now only think of this possibility: If we change the helper alias (my alias1 above) result to

regex: HTML: $$1 | showfilehtml $$1 /icon=C:\folder\icon.ico

then once we trigger alias2 and type enough characters to get a single unique match FARR will automatically (without Enter press) transform that single result line to show "HTML: C:\folder\uniquefile.html" and the custom icon.

But there are two limitations here:
  • The custom search result format shows only when we have typed enough to filter in a single result. Before that the results looks like in a regular FARR file search
  • We can only use the full file path variable $$1 in the custom format. There is no variable for e.g. filename, filename without extension or other filepath fragments we might want to use.

Compare with my animation from the first post: https://i.imgur.com/6LEOsFM.mp4 . There the live search results lines have the format
<filename without extension> | showfilehtml <full file path>
I could also have added custom icon(s), for example one that would signal that the action has switched to show the HTML file in FARR. I like that simpler look and think it would be nice to have that possibility built into FARR.

So, I think my now hopefully more clearly stated goal 2 is still something that FARR cannot currently do by itself. Or?


edit:
As a sidenote the FARR help page on Using Alias Action Keywords is a bit unclear (just like me then! ;D) in this sentence.
When an alias name is specified in this way, anywhere on the search string, it does not effect search, but it will cause the alias results to be displayed AFTER the result file is selected, with the selected file name as argument $$1 in the alias.
Does this rewrite more accurately describe FARR's current behaviour?
When an alias name is specified in this way, anywhere on the search string, it does not affect which file results are shown nor how each result line looks. With one exception: When the search string matches only one unique file then the action keyword alias determines how that result line looks.
However once you press Enter the action keyword alias comes into effect: FARR passes the selected result file path as variable $$1 to the action alias. The action you have set up in the action alias is then performed by FARR.
« Last Edit: October 28, 2020, 03:23 PM by Nod5 »

skajfes

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 267
    • View Profile
    • Donate to Member
Re: Request: enhanced dosearch command that customizes results lines
« Reply #4 on: October 30, 2020, 02:18 PM »
From what I can tell, there is no way for the alias action keyword to modify the search results appearance. IMHO, that is not something I would need, but it might be cool/beneficial to have the option. Usually my action modifiers are some small programs and scripts, which would just make all my alias results look like default autohotkey or exe icon.

You could maybe achieve this with some combination of appcapresult and external scripts that returns preformatted results, leveraging the showfilehtml action modifier, but I haven't used appcapresult so I can't say.
It is impossible to make anything foolproof because fools are so ingenious.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: Request: enhanced dosearch command that customizes results lines
« Reply #5 on: October 31, 2020, 06:28 AM »
You could maybe achieve this with some combination of appcapresult and external scripts that returns preformatted results, leveraging the showfilehtml action modifier
I already do that - that's what the mp4 recording illustrates. But as noted there are sometimes slowdowns, from the roundtrip to the external script and back.