FileURI plugin for Take Command / TCC / TCC/LE

Version 1.1.1     2024-10-17

Charles Dye

Purpose:

This plugin implements functions to convert local filenames to the file:// representation and vice versa.

Installation:

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

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

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

Plugin Features:

New functions: @FILE2URI, @FILE2URIS, @ISURL, @URI2FILE

New hotkey: Ctrl-Alt-U

New command: FILEURIKEY

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 Functions:

@FILE2URI — Converts a local filename to a file:// URI.

Syntax:
@FILE2URI[filename]

The filename will be canonicalized before conversion; relative pathnames and directory aliases are okay. The file need not actually exist. Note that the string returned by this function may contain percent signs — handle with care!

This function uses UrlCreateFromPath().



@FILE2URIS — Converts a local filename to a file:// URI.

Syntax:
@FILE2URIS[filename]

The filename will be canonicalized before conversion; relative pathnames and directory aliases are okay. The file need not actually exist. Any percent signs in the resulting URI will be replaced with “safe” percent signs, Unicode character 0xFF05. (These may or may not look like regular percent signs, depending on the font(s) in use.)

This function uses UrlCreateFromPath().



@ISURL — Returns nonzero if a string represents an internet URL.

Syntax:
@ISURL[string]

This function returns nonzero if string represents an internet URL:

0not a URL (no protocol specifier)
1HTTP://
2HTTPS://
3FTP://
4IFTP session (a filename beginning with FTP:)
5TFTP://
6FTPS://
8SFTP://
10other Internet URLs (gopher, mailto, etc.)

This function simply exposes TCC’s internal QueryIsURL() function. The operation of this function may differ from version to version of TCC. For example, TCC/LE does not support the IFTP command, and so this function won’t return a value of 4 under TCC/LE. Very old versions of TCC which don’t support SFTP may return a value of 8 for unknown protocols, and so on.



@URI2FILE — Converts a file:// URI to a local filename.

Syntax:
@URI2FILE[string]

If the string contains percent signs, you will need to double them or protect them with strong quotes, escapes, or whatever. Alternatively, you can use %@CHAR[0xFF05] as a substitute for the percent sign; the plugin will automatically replace this character with a percent sign before converting the string.

This function calls PathCreateFromUrl().



New Hotkey:

Ctrl-Alt-U: Toggles the word at the cursor from a filename to a file:// URI, or vice versa.

This hotkey attempts to change the space-delimited word at the cursor. It knows nothing about function arguments, commas, or other argument separators. If you want to use it on an filename inside a function, you must supply spaces around the filename.

Ctrl-Alt-U is the default assignment. You can use the FILEURIKEY command to change or disable it.



New Command:

FILEURIKEY — View and change the hotkey assignment.

Syntax:
FILEURIKEY /D /L /Q /R /S key

/Drestore the default plugin settings
/Llist all supported hotkeys
/Qquietly
/Rrestore the saved settings from the registry
/Ssave the current settings to the registry
keythe new hotkey, or NONE to disable it

This command displays and changes plugin settings. At present, the only setting you can change is the hotkey assignment. The default is Ctrl-Alt-U, but you can select a different key, or disable the hotkey altogether. 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 the the default value.

If you save the current settings to the registry with /S, they will be reloaded automatically the next time you load this plugin.

FILEURIKEY with no options displays the current settings.



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

Changes:

Version:Date:Changes:
1.1.1.12024-10-17Updated the web address in the PLUGININFO structure.
1.1.12023-07-26Updated to the current versions of ParseArgs.cpp and HotKeys.cpp.
1.1.02021-10-01Added a hotkey, and a command to set it. Changed the .dll names; now FileURI.dll is the 64-bit build. Tweaks to the version info structure. Miscellaneous code cleanup.
1.0.02016-08-23First release.

Status and Licensing:

This plugin is © Copyright 2024, Charles Dye. Unaltered copies of the binary and documentation files may be freely distributed without restriction. I make no guarantee and give no warranty for its operation. If you find a problem, you can report it in the JP Software support forum.

Download:

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