Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xy2z committed Sep 28, 2020
0 parents commit 39e4f05
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
3 changes: 3 additions & 0 deletions README.md
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.
54 changes: 54 additions & 0 deletions bin/setalias
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.');
16 changes: 16 additions & 0 deletions composer.json
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"
]
}

0 comments on commit 39e4f05

Please sign in to comment.