AutoHashBang - HashBangs for AutoHotkey

Post your working scripts, libraries and tools
GeekDude
Posts: 853
Joined: 02 Oct 2013, 22:13

AutoHashBang - HashBangs for AutoHotkey

14 Feb 2015, 21:11

Wikipedia wrote:In computing, a shebang (also called a sha-bang, hashbang, pound-bang, hash-exclam, or hash-pling), is the character sequence consisting of the characters number sign and exclamation mark (that is, "#!") at the beginning of a script.
Specify which AHK to use with your script with an interpreter directive. Simply put ;#! C:\Path\To\AutoHotkey.exe at the top of your .ahk or .ahc file to switch interpreters.

To install or uninstall, just run the script file directly. If the script is moved while it is installed, the .ahk and .ahc shell associations will be broken, so it is recommended to uninstall before moving it.

When AutoHashBang is installed, it will create a second copy of AutoHotkey.exe called AutoHotConsole.exe. It will then set AutoHotConsole to be a console application, allowing scripts run through it to use StdIn/Out from a normal console.

AutoHashBang will override the shell extensions for .ahk and .ahc files with itself being run through AutoHotkey.exe and AutoHotConsole.exe, respectively. Because of how windows works, you can't choose whether to be a console app after execution starts, so that's why a separate shell association for it is necessary.

AutoHashBangs support a handful of variables, listed below:
  • A_ScriptDir
  • A_WorkingDir
  • A_AppData
  • A_AppDataCommon
  • A_LineFile
  • A_AhkPath
Note that A_AhkPath is the full path, so if you want to use the directory, use %A_AhkPath%\.. instead of just %A_AhkPath%.

Source
User avatar
joedf
Posts: 7247
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: AutoHashBang - HashBangs for AutoHotkey

15 Feb 2015, 04:58

Nice-o! ;)
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB DDR4 3143 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
guruglenn
Posts: 7
Joined: 31 Jul 2015, 04:36

Re: AutoHashBang - HashBangs for AutoHotkey

05 Nov 2015, 23:03

Sounds inteersting. But why does AutoHashBang change the .ahk file association? And if .ahc is invented for console, why do you need to interpret a she-bang line at all? Console apps could just use .ahc, and GUI apps .ahk...
GeekDude
Posts: 853
Joined: 02 Oct 2013, 22:13

Re: AutoHashBang - HashBangs for AutoHotkey

05 Nov 2015, 23:18

The main point of AutoHashBang is not to add console support, but to allow for easy version switching. For example, if you want to test a beta version of AHK v2, you could put ;#! %A_ScriptDir%\AhkBeta.exe and have it run through the beta executable in the script's directory. I also wanted it to support console versions of AutoHotkey, but because of restrictions in how Windows works as a whole I had to do the second file extension.
User avatar
evilC
Posts: 4730
Joined: 27 Feb 2014, 12:30

Re: AutoHashBang - HashBangs for AutoHotkey

24 Nov 2015, 16:44

I take it that there is no way to have this affect which interpreter scite uses? I am guessing probably not.

A couple of other suggestions:
Might I suggest allowing a space between the ; and the # ?
if RegExMatch(Script, "`a)^\s*`;\s*#!\s*(.+)", Match)
That's a mistake I won't be making again ;)

If the hashbang path does not contain a \ character, it is not specifying a path, so assume the AHK folder.
That way, you can just do ;#!SomeAhkExe.exe to run with SomeAhkExe.exe in your AHK folder.

I forked and submitted a pull request, should you wish to include these changes

[Edit] Hmm, thinking about it, my code breaks a hashbang of solely %A_AhkPath%. However, this would make no sense anyway, as that would be the same as no hashbang.
It would also break hashbangs of the other lone ahk vars, but without a \, these seem useless.
So more logic may be required, but I don't see it breaking any sane use-cases

Return to “Scripts and Functions”

Who is online

Users browsing this forum: JoeWinograd, TheBestPessimist and 58 guests