-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 39e4f05
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Setaliases | ||
|
||
Sets your Windows CLI aliases from a given URL in linux format. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
/** | ||
* Manually runs "alias" command for each line in the content. | ||
* | ||
*/ | ||
|
||
function tell($var) { | ||
echo $var . PHP_EOL; | ||
} | ||
|
||
if (!isset($argv[1])) { | ||
exit('Error: Link needed.'); | ||
} | ||
|
||
tell('Running...'); | ||
tell('Link: ' . $argv[1]); | ||
|
||
$content = file_get_contents($argv[1]); | ||
|
||
$separator = "\r\n"; | ||
$lines = explode("\n", $content); | ||
|
||
foreach ($lines as $line) { | ||
$line = str_replace(["'", "sudo "], "", trim($line)); | ||
$line = str_replace('&&', '$t', $line); | ||
|
||
if (empty($line)) { | ||
// Dont handle empty lines. | ||
continue; | ||
} | ||
|
||
$alias = str_replace('alias ', '', explode('=', $line)[0]); | ||
if (strpos($alias, '..') !== false) { | ||
// Skip dots. Because they bug and delete other aliases in Cmder. | ||
continue; | ||
} | ||
|
||
// Append "$*" if it's not already there. | ||
// To allow arguments. | ||
// This is only needed on Windows, not linux. | ||
if (substr($line, -2) != '$*') { | ||
$line .= ' $*'; | ||
} | ||
|
||
|
||
// Set new alias | ||
passthru($line); | ||
// tell('Running: ' . $line) | ||
|
||
} | ||
|
||
tell('Done.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "xy2z/setaliases", | ||
"description": "Set windows aliases from a given URL", | ||
"type": "project", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "xy2z", | ||
"email": "xy2z@pm.me" | ||
} | ||
], | ||
"require": {}, | ||
"bin": [ | ||
"bin/setaliases" | ||
] | ||
} |