alias.php
<?php
define('USER_PATH', 'C:/Users/Mat/Shortcuts');
// Grab all the CLI args except the script just run.
// Loop over the args, fishing out any starting with a hyphen.
do {
// Does it start with a hyphen?
if ((bool) $alias_name AND $alias_name[0] == '-') {
$alias_args[] = $alias_name;
}
} while ($alias_name[0] == '-');
// Use the remaining args as the alias command.
$command = "@ECHO OFF\r\n".implode(' ', $args);
// Build the path we'll save to.
$alias_path = realpath(USER_PATH
).'/'.$alias_name.'.cmd';
// Check if the file exists.
// Warn unless they specified an override.
if ($alias_exists AND
! in_array('-f', $alias_args)) { echo 'Alias already exists. Use -f to overwrite.', "\n"; } else {
// Save the alias!
file_put_contents($alias_path, $command);
// Let them know what action was taken.
if ($alias_exists)
echo 'Updated alias', "\n"; else
echo 'Created new alias', "\n"; }