Finally, I've rewritten a new script from scratch:
AutoRun.cmd
Its features are:
- Manage multiple independent AutoRun scripts, that all run when a new cmd.exe window starts.
- Define Unix-compatible installation variables.
To install AutoRun.cmd, copy it to your favorite cmd scripts directory (A directory that must be in your PATH); Then run as Administrator: AutoRun -i
If you first want to know what this installation would do, run: AutoRun -X -i
If another AutoRun script is already present, this installation will detect it, and refuse to run. It's possible to override that by using the -f option. In that case the previous AutoRun script is moved to one of the AutoRun.cmd.d extension directories. (See below)
Run 'AutoRun -l' to list AutoRun scripts currently installed.
Run 'AutoRun -?' to get a help screen with all options.
I'd appreciate if others can try this
AutoRun.cmd, and and give me their feedback.
-------------------------------------------------------------------------------
The first AutoRun.cmd feature (Managing multiple independent AutoRun scripts) is inspired from the way Linux login scripts work:
- Put in %ALLUSERSPROFILE%\AutoRun.cmd.d\ the AutoRun scripts that should be run for all users.
- Put in %USERPROFILE%\AutoRun.cmd.d\ the AutoRun scripts that should be run for you only.
Once AutoRun.cmd is installed, all the *.bat and *.cmd scripts in the above AutoRun.cmd.d directories will be run every time a new cmd.exe window is started.
The advantage is that any number of scripts can be put there, in any order, without having to deal with the command processor's AutoRun registry value.
For example, if you create an "%ALLUSERSPROFILE%\AutoRun.cmd.d\history.bat" file that just contains...
... Then all your new cmd.exe windows will support a new history command, with an output that
can be piped to another command. (See
this post for details.)
Likewise, if you put siberia-man's
setcmd.bat in "%ALLUSERSPROFILE%\AutoRun.cmd.d\", you end-up with a far more sophisticated version of the history command, and of several other Unix commands. (Be sure to first remove my own history.bat from above, as both scripts define the same history macro!)
I plan to use this AutoRun scheme to define a which macro, that will allow implementing a -i option for my
which.exe tool for Windows, similar to how "which -i" works in Unix.
Currently, my which.exe detects cmd.exe built-in commands by running a sub-shell with options "/c help". This works, but it's slow.
And extending this method to detect macros would not work at all, as a sub-shell does not have any. (Or actually did not have any before I defined this AutoRun scheme
)
That future which macro will pipe the
current shell macros to 'which.exe -i $*'. This will be very fast, and will ensure that which.exe reports macros for the
current shell, whatever they are
now.
Important: All these AutoRun scripts must NOT write anything to the screen, or change the current directory, or do anything that might surprise existing scripts when they start a sub-cmd shell. Basically they should only set new variables, or create doskey macros.
-------------------------------------------------------------------------------
The second AutoRun.cmd feature is the definition of a number of standard GNU
installation directory variables.
AutoRun.cmd defines reasonable defaults, closely matching the defaults required for Unix. But you're encouraged to create an AutoRun script, that defines your personal preferences.
The goal is that installation scripts, like jahwi's
Bget Package Manager, eventually use these variables, and store files in the right place for
you, without you having to specify anything by default.
The standard variables defined by AutoRun.cmd are: (There are many more in the GNU spec above, but these are the most relevant ones for Windows batch scripts.)
- prefix - Base name of a directory where to install everything below. Default: set "prefix=%ProgramFiles%"
- exec_prefix - Base name of a directory where to install all programs and scripts below. Default: set "exec_prefix=%prefix%"
- bindir - Name of the directory where to install programs and scripts. Default: set "bindir=%exec_prefix%\bin"
- libdir - Name of the directory where to install libraries and DLLs. Default: set "libdir=%exec_prefix%\lib"
- includedir - Name of the directory where to install include files. Default: set "includedir=%prefix%\include"
Then it also defines a set of non-standard variables, as in Windows we often deal with two sets of executables, that should be installed in different places.
- bindir_x86 - Name of the directory where to install 32-bits x86 *.exe programs. Default: Depends on %PROCESSOR_ARCHITECTURE%.
- bindir_AMD64 - Name of the directory where to install 64-bits AMD64 *.exe programs. Default: Depends on %PROCESSOR_ARCHITECTURE%.
- libdir_x86 - Name of the directory where to install 32-bits x86 libraries and DLLs. Default: Depends on %PROCESSOR_ARCHITECTURE%.
- libdir_AMD64 - Name of the directory where to install 64-bits AMD64 libraries and DLLs. Default: Depends on %PROCESSOR_ARCHITECTURE%.
For example, I created on my laptop a "%ALLUSERSPROFILE%\AutoRun.cmd.d\dirs.cmd" file containing:
Code: Select all
set "bindir=C:\JFL\Tools"
set "bindir_x86=C:\JFL\Tools\WIN32"
set "bindir_AMD64=C:\JFL\Tools\WIN64"
And the variables created are:
Code: Select all
C:\JFL\Temp>set | findstr dir
bindir=C:\JFL\Tools
bindir_AMD64=C:\JFL\Tools\WIN64
bindir_x86=C:\JFL\Tools\WIN32
includedir=C:\Program Files\include
libdir=C:\Program Files\lib
libdir_AMD64=C:\Program Files\lib
libdir_x86=C:\Program Files (x86)\lib
windir=C:\WINDOWS
C:\JFL\Temp>
Finally 'autorun -l' reports:
Code: Select all
C:\JFL\Temp>autorun -l
AutoRun scripts:
all users: C:\JFL\Tools\AutoRun.cmd
Extension scripts:
all users: C:\ProgramData\AutoRun.cmd.d\history.bat
all users: C:\ProgramData\AutoRun.cmd.d\dirs.cmd
C:\JFL\Temp>