If you still don't know what Total Commander is, please take several minutes and visit the site: http://www.totalcmd.com. Probably, it is the best file manager for Windows OS. Be careful though - if you start using Total Commander, you will never switch back to another file manager! ;-)
Inspired by AnyELF Total Commander plugin, an idea came - why limit yourself with a special file formats only. Why not permit to user define a custom dumper, text filter, lister or file viewer? After all, there are a lot of command line text processing utilities that already do this job. Definitely, you may use file associations or just use command line window for this purpose. But, would not be it is just great if you could do the job within Total Commander itself? I mean - do anything! You can sort lines of text, compile a program, launch your favorite Perl (really, Perl?) script, and so on.
That is how the idea came, and that is why the plugin was implemented. So, let's start:
Installation
Download the wlx_anycmd.zip file and save it in a temporary location. Open Total Commander, locate the file and double click on it (or just press "ENTER"). Total Commander will prompt you to install the plugin. Accept it. A list of installed plugins will appear. Just press "OK". That is all.
Detection and Command strings
By default, the plugin will work on any file with extension .TXT. When opened with the lister (F3 button), the plugin will show text file content sorted. You may switch between original and sorted text by pressing '1' and '4' correspondingly. If that it is what you want, you are done. But, how can you customize the default settings?
Init files
To change the default setting, you need to write new detection and command strings. You may modify them in the init file. Here is the procedure:
In wincmd.ini file, under "[ListerPlugins]" group, remove the current (cached) detection string. Initially it may look like this:
wincmd.ini
...
x=C:\totalcmd\plugins\wlx\anycmd\anycmd.wlx
x_detect="EXT=TXT"
Where 'x' is a number.
Remove the second ('x_detect') line.
anycmd.ini
DetectString=EXT=TXT
Command=sort.exe %s
Stream=3
anycmd.ini
Detection and Command Strings Examples
To get started, here go some examples of init files. Please note - %s is substituted by actual file name.
View file's attributes and full path for .INI files:
anycmd.ini - View file's attributes and full path for .INI files
DetectString=EXT=INI
Command=cmd.exe /c attrib %s
Show only the lines containing specific text. For example, find all procedures in TCL file.
anycmd.ini - Show the lines containing specific text
DetectString=EXT=TCL
Command=findstr /i "proc " %s
Compile .CPP file and show errors (if any):
anycmd.ini - Compile .CPP file and show errors
DetectString=EXT=CPP
Command=cl -c %s
Invoke a batch file:
anycmd.ini - Invoke a batch file
DetectString=EXT=CPP
Command=cmd.exe /c c:\mycomp.bat %s
If the content of c:\mycomp.bat file is like this:
c:\mycomp.bat
type temp.tmp
del temp.tmp
assembly listing for compiled .CPP file will be shown.
The only requirement to invoked programs is that they should print out their output to the standard output stream. Your needs, creativity and fantasy will help you continue from this point. Enjoy!
Please note - command line may contain environment variables:
Environment variables
DetectString=EXT=TXT
Command=%COMMANDER_PATH%\plugins\wlx\anycmd\myprog.exe %s
Stream=3
Standard output and standard error streams
By default, the plugin redirects both standard output and error streams to the lister window. You may change this behavior. Stream selection is controlled by "Stream" key in the initialization file. Value '1' selects standard output; value '2' - standard error and '3' (default) - both streams.
Appendix: Detection Strings Syntax
This section describes the detection string syntax. It is taken from "Lister Plugin Guide".
The syntax of the detection string
The syntax of the detection string is as follows. There are operands, operators and functions.
Operands:
EXT | The extension of the file to be loaded (always uppercase) |
SIZE | The size of the file to be loaded. |
FORCE | 1 if the user chose 'Image/Multimedia' from the menu, 0 otherwise. |
MULTIMEDIA | This detect string is special: It is always TRUE (also in older TC versions). If it is present in the string, this plugin overrides internal multimedia viewers in TC. If not, the internal viewers are used. Check the example below! |
[5] | The fifth byte in the file to be loaded. The first 8192 bytes can be checked for a match. |
12345 | The number 12345 |
"TEST" | The string "TEST" |
Operators
& | AND. The left AND the right expression must be true (!=0). |
| | OR: Either the left OR the right expression needs to be true (!=0). |
= | EQUAL: The left and right expression need to be equal. |
!= | UNEQUAL: The left and right expression must not be equal. |
< | SMALLER: The left expression is smaller than the right expression. Comparing a number and a string returns false (0). Booleans are stored as 0 (false) and 1 (true). |
> | LARGER: The left expression is larger than the right expression. |
Functions
() | Braces: The expression inside the braces is evaluated as a whole. |
!() | NOT: The expression inside the braces will be inverted. Note that the braces are necessary! |
FIND() | The text inside the braces is searched in the first 8192 bytes of the file. Returns 1 for success and 0 for failure. |
FINDI() | The text inside the braces is searched in the first 8192 bytes of the file. Upper/lowercase is ignored. |
Internal handling of variables
Varialbes can store numbers and strings. Operators can compare numbers with numbers and strings with strings, but not numbers with strings. Exception: A single char can also be compared with a number. Its value is its ANSI character code (e.g. "A"=65). Boolean values of comparisons are stored as 1 (true) and 0 (false).
Examples:
String | Interpretation |
---|---|
EXT="WAV" | EXT="AVI" | The file may be a Wave or AVI file. |
EXT="WAV" & [0]="R" & [1]="I" & [2]="F" & [3]="F" & FIND("WAVEfmt") | Also checks for Wave header "RIFF" and string "WAVEfmt" |
EXT="WAV" & (SIZE<1000000 | FORCE) | Load wave files smaller than 1000000 bytes at startup/file change, and all wave files if the user explictly chooses 'Image/Multimedia' from the menu. |
([0]="P" & [1]="K" & [2]=3 & [3]=4) | ([0]="P" & [1]="K" & [2]=7 & [3]=8) | Checks for the ZIP header PK#3#4 or PK#7#8 (the latter is used for multi-volume zip files). |
EXT="TXT" & !(FINDI("") | FINDI("")) | This plugin handles text files which aren't HTML files. A first detection is done with the and tags. If these are not found, a more thorough check may be done in the plugin itself. |
MULTIMEDIA & (EXT="WAV" | EXT="MP3") | Replace the internal player for WAV and MP3 files (which normally uses Windows Media Player as a plugin). Requires TC 6.0 or later! |
Operator precedence:
The strongest operators are =, != < and >, then comes &, and finally |. What does this mean? Example: expr1="a" & expr2 | expr3<5 & expr4!=b will be evaluated as ((expr1="a") & expr2) | ((expr3<5) & (expr4!="b"))
If in doubt, simply use braces to make the evaluation order clear.