Custom commands: make an executable for any command.
The alias application maintains an assignment of alias names to commands in a configuration file alias.conf
.
When alias runs, it looks up its file name and runs the assigned command if any.
Otherwise, if no assignment to that name exists, it runs in configuration mode, providing an alternative interface to edit the configuration file.
The user may also directly edit alias.conf
by following the JSON reference.
Some Windows applications are, to put kindly, limited.
You might need to fool them into thinking that script you want it to run is actually an exe
file.
Or maybe you want that Linux executable under WSL to look like a native application.
Do we really want to write another exe
to run a single command?
Do we really want to track down these developers, tell them to write better code, and hope they will?
No?
Here’s a workaround.
.NET Core 3.0 runtime
Save the application to a directory in your PATH
.
New-Item -Type Directory -Path ~\path | Set-Location
Start-BitsTransfer -Source https://github.com/lmmarsano/alias/releases/latest/download/alias-win-x64.zip
Expand-Archive -Path alias-win-x64.zip
Remove-Item -Path alias-win-x64.zip
[System.Environment]::SetEnvironmentVariable(
'PATH',
(('%USERPROFILE%\path', [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::User) -split ';' | Select-Object -Unique -join ';'),
[System.EnvironmentVariableTarget]::User
)
x86-64 binaries are also released for Linux and MacOS.
In a directory containing the alias
executable
New-Item -Type HardLink -Name test.exe -Value alias.exe
alias set test cmd /c echo
.\test hello world
# hello world
By convention, this guide assumes the alias application has the unassigned name alias
, though the user can rename the application to any unassigned name.
In the same directory as the the alias executable, link or copy the executable to name (name.exe
on Windows), configure name,
alias set
name command initial-argument*
and run
name argument*
If name is configured, then this runs the configured command and initial arguments with the additional arguments.
command initial-argument* argument*
alias set
name command argument*
Add or change named alias’ configuration.
To pass -
prefixed arguments, first include --
to disable option processing.
--
will be excluded from the saved command.
To save --
, too, repeat it.
alias unset
name
Remove the alias.
alias reset
Remove all configured aliases.
Located in the same directory as the alias
executable, alias.conf
is a plain JSON file with a root object containing the "binding"
property.
{"binding": bindings}
{(alias: commandEntry)*}
An object with any number of mappings between alias keys commandEntry values. Each alias must be unique.
unique string
A plain string naming an alias.
The name must include executable file name extension (exe
on Windows) if the operating system requires it.
{"command": command, "arguments"?: arguments}
An object with "command"
and optional "arguments"
properties.
string
A string naming an executable.
The full path is only required as your system requires (eg, directory not in the environment PATH
variable).
string
A single string containing arguments as you would enter them in the console.
Escape "
as \"
and \
as \\
.
The command will be called with these arguments and any additional arguments passed through invocation.
Install at least .NET Core 3.0, clone the repository, change into the directory, and build.
git clone https://github.com/lmmarsano/alias.git
Set-Location -Path alias
dotnet build
Edit sources in source\Alias
.
For Visual Studio Code
code source\Alias
An executable is built under source\Alias\bin\Debug\netcoreapp3.0
.
Set-Location -Path source\Alias\bin\Debug\netcoreapp3.0
.\Alias
Try it out by running the demo script
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
.\Demo.ps1
.\Alias list
# alias-set
# alias-unset
# mklink
and running the generated executables.
mklink.exe
calls the link creation command from thecmd.exe
environmentalias-set.exe
callsalias set
and hardlinks an executable aliasalias-unset.exe
callsalias unset
and removes the executable alias
Include file system operations to link/copy/remove the alias executable as configuration mode edits alias.conf
.