Improve tools support

This commit is contained in:
Shivam Mathur
2019-12-28 00:42:00 +05:30
parent 8e1cde2d0a
commit 6a70f864ec
6 changed files with 83 additions and 33 deletions

View File

@ -51,11 +51,15 @@ remove_extension() {
add_tool() {
url=$1
tool=$2
if [ ! -e /usr/local/bin/"$tool" ]; then
rm -rf /usr/local/bin/"${tool:?}"
if [ "$tool" = "composer" ]; then
brew install composer >/dev/null 2>&1
else
if [ ! -e /usr/local/bin/"$tool" ]; then
rm -rf /usr/local/bin/"${tool:?}"
fi
sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1
sudo chmod a+x /usr/local/bin/"$tool"
fi
sudo curl -o /usr/local/bin/"$tool" -L "$url" >/dev/null 2>&1
sudo chmod a+x /usr/local/bin/"$tool"
add_log "$tick" "$tool" "Added"
}

View File

@ -89,17 +89,22 @@ Function Add-Tool() {
[string]
$tool
)
if (Test-Path $php_dir\$tool) {
Remove-Item $php_dir\$tool
if($tool -eq "composer") {
Install-Composer -Scope System -Path $php_dir -PhpPath $php_dir
} else {
if (Test-Path $php_dir\$tool)
{
Remove-Item $php_dir\$tool
}
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool > $null 2>&1
$bat_content = @()
$bat_content += "@ECHO off"
$bat_content += "setlocal DISABLEDELAYEDEXPANSION"
$bat_content += "SET BIN_TARGET=%~dp0/" + $tool
$bat_content += "php %BIN_TARGET% %*"
Set-Content -Path $php_dir\$tool.bat -Value $bat_content
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat"
}
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool > $null 2>&1
$bat_content = @()
$bat_content += "@ECHO off"
$bat_content += "setlocal DISABLEDELAYEDEXPANSION"
$bat_content += "SET BIN_TARGET=%~dp0/" + $tool
$bat_content += "php %BIN_TARGET% %*"
Set-Content -Path $php_dir\$tool.bat -Value $bat_content
Add-Content -Path $PsHome\profile.ps1 -Value "New-Alias $tool $php_dir\$tool.bat"
Add-Log $tick $tool "Added"
}