SwapArgs plugin for Take Command / TCC / TCC/LE

beta version 0.95.1     2023-10-13

Charles Dye

Purpose:

This plugin provides a hotkey to exchange two arguments on the command line.

Installation:

To use this plugin, copy SwapArgs.dll to some known location on your hard drive. (If you are still using the 32-bit version of Take Command, take SwapArgs-x86.dll instead of SwapArgs.dll.) Load the .DLL file with a PLUGIN /L command, for example:

plugin /l c:\bin\tcmd\test\swapargs.dll

If you copy the .DLL file to a subdirectory named PlugIns within your Take Command program directory, it will be loaded automatically when TCC starts.

Plugin Features:

New command: SWAPARGS

New hotkey: Alt-X

Syntax Note:

The syntax definitions in the following text use these conventions for clarity:

BOLD CODEindicates text which must be typed exactly as shown.
CODEindicates optional text, which may be typed as shown or omitted.
Bold italicnames a required argument; a value must be supplied.
Regular italicnames an optional argument.
ellipsis…after an argument means that more than one may be given.

New Command:

SWAPARGS — Display or change SwapArgs plugin settings.

Syntax:
SWAPARGS /B:yn /C:yn /D /E:yn /F:yn /I:yn /K:key /L /N:n /Q /R /S

/B:ynbreak on equals signNo
/C:ynskip over the commandYes
/Drestore default plugin settings
/E:ynplay sound on errorsYes
/F:ynscan forwardYes
/I:ynexchange inner argumentsYes
/K:keyset the hotkeyAlt-X
/Llist all supported hotkeys
/N:nnumber of flashes0
/Qquietly
/Rrestore saved settings from the registry
/Ssave the current settings to the registry

SWAPARGS with no options displays the plugin’s current settings.


/K:key allows you to change the plugin’s hotkey. To see a list of all supported hotkeys, use /L. (The list can vary between versions of Take Command, because the plugin hotkey interface changed in version 24.) Note that some key combinations may not work for you — they might be intercepted by the console, by a keystroke alias, or by Take Command itself. If your hotkey doesn’t work, try changing it back to its default value, Alt-X.

swapargs /k:ctrl-q


/I:yn controls whether or not the hotkey may exchange arguments inside square brackets: function arguments and array indices. The default is Yes.


/F:yn controls whether the hotkey may exchange arguments after the cursor. The default is Yes. If you change this value to No, the hotkey will only ever exchange arguments before the cursor. /F:No may give surprising results if the cursor is on a function’s first argument. I recommend leaving this option set to Yes.


/B:yn controls whether the hotkey breaks arguments at equals signs. If this option is set to Yes, equals signs are treated like whitespace. The default is No. Note that this option only affects parsing the outer command line; it has no effect inside functions, array indices, etc.


/C:yn: By default, the hotkey skips over the first word on the command line — the command. Only arguments after the first word will be exchanged. You can disable this feature with /C:N. I can’t imagine why you would want to, but the option is there if you find a use for it.


/E:key controls whether the hotkey plays a sound when it encounters an error; the default is Yes. The most common error is being unable to find two arguments to exchange.


/D restores the original plugin default settings (shown in the third column of the table above). /R restores the settings saved to the registry, if any. You cannot combine the two.

/S saves the current settings to the registry. They will be loaded automatically the next time you load this plugin.



New Hotkey:

Alt-X — Exchanges two arguments on the command line.


If the plugin finds two arguments before the cursor, it will exchange them.

If there are not two arguments before the cursor, then the key’s behavior is determined by the ScanForward option. If ScanForward is enabled (the default), then the hotkey will exchange the argument before the cursor with the argument after it — or, if there is no argument before the cursor, exchange the first two arguments after the cursor.

If ScanForward is disabled, then the hotkey will only ever exchange arguments before the cursor.

(Why do I prefer args before the cursor? Because I imagine this hotkey being useful mainly with command lines recalled from the command history; and, most often, with the final two arguments on the line. When you recall an old command line from the history, the cursor is positioned at the end of the line.)


You can change the default key assignment with SWAPARGS /K.



Startup Message:

This plugin displays an informational line when it initializes. The message will be suppressed in transient or pipe shells. You can disable it for all shells by defining an environment variable named NOLOADMSG, for example:

set /e /u noloadmsg=1

Status and Licensing:

Consider this beta software. It may well have issues. Try it at your own risk. If you find a problem, you can report it in the JP Software support forum.

SwapArgs is currently licensed only for testing purposes. I may make binaries and source code available under some free license once I consider it ready for use.

Download:

You can download the current version of the plugin from http://charlesdye.net/dl/swapargs.zip.