feat: SublimeHelpers.ps1 -- add support for ST3

- package control must now be git cloned manually
This commit is contained in:
Iristyle
2013-07-23 16:47:07 -04:00
parent 7491fb77d1
commit 3a0d9b6251

View File

@@ -1,17 +1,41 @@
# uses functions in JsonHelpers.ps1 # uses functions in JsonHelpers.ps1
function Get-SublimeInstallPath function Get-SublimeInstallPath
{ {
Join-Path $Env:ProgramFiles 'Sublime Text 2' [CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[ValidateRange(2,3)]
[int]
$Version = 2
)
Join-Path $Env:ProgramFiles "Sublime Text $Version"
} }
function Get-SublimeSettingsPath function Get-SublimeSettingsPath
{ {
Join-Path ([Environment]::GetFolderPath('ApplicationData')) 'Sublime Text 2' [CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[ValidateRange(2,3)]
[int]
$Version = 2
)
Join-Path ([Environment]::GetFolderPath('ApplicationData')) "Sublime Text $Version"
} }
function Get-SublimePackagesPath function Get-SublimePackagesPath
{ {
$packagesPath = Join-Path (Get-SublimeSettingsPath) 'Packages' [CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[ValidateRange(2,3)]
[int]
$Version = 2
)
$packagesPath = Join-Path (Get-SublimeSettingsPath -Version $Version) 'Packages'
if (!(Test-Path $packagesPath)) if (!(Test-Path $packagesPath))
{ {
New-Item $packagesPath -Type Directory | Out-Null New-Item $packagesPath -Type Directory | Out-Null
@@ -22,7 +46,15 @@ function Get-SublimePackagesPath
function Get-SublimeUserPath function Get-SublimeUserPath
{ {
$path = Join-Path (Get-SublimePackagesPath) 'User' [CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[ValidateRange(2,3)]
[int]
$Version = 2
)
$path = Join-Path (Get-SublimePackagesPath -Version $Version) 'User'
if (!(Test-Path $path)) if (!(Test-Path $path))
{ {
New-Item $path -Type Directory | Out-Null New-Item $path -Type Directory | Out-Null
@@ -39,7 +71,7 @@ function Install-SublimePackagesFromCache
$Directory $Directory
) )
$packagesPath = Get-SublimePackagesPath $packagesPath = Get-SublimePackagesPath -Version $Version
Get-ChildItem $Directory | Get-ChildItem $Directory |
? { $_.PsIsContainer } | ? { $_.PsIsContainer } |
% { @{Path = $_.FullName; Destination = Join-Path $packagesPath $_.Name }} | % { @{Path = $_.FullName; Destination = Join-Path $packagesPath $_.Name }} |
@@ -56,9 +88,23 @@ function Install-SublimePackagesFromCache
function Install-SublimePackageControl function Install-SublimePackageControl
{ {
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[ValidateRange(2,3)]
[int]
$Version = 2
)
# install package control # install package control
$packagesPath = Join-Path (Get-SublimeSettingsPath) 'Installed Packages' $packageFolder = if ($Version -eq 2) { 'Installed Packages' } else { 'Packages' }
$packagesPath = Join-Path (Get-SublimeSettingsPath -Version $Version) $packageFolder
if (!(Test-Path $packagesPath)) { New-Item $packagesPath -Type Directory } if (!(Test-Path $packagesPath)) { New-Item $packagesPath -Type Directory }
switch ($Version)
{
2 {
$packageControl = Join-Path $packagesPath 'Package Control.sublime-package' $packageControl = Join-Path $packagesPath 'Package Control.sublime-package'
if (!(Test-Path $packageControl)) if (!(Test-Path $packageControl))
@@ -67,6 +113,14 @@ function Install-SublimePackageControl
$packageUrl = 'http://sublime.wbond.net/Package%20Control.sublime-package' $packageUrl = 'http://sublime.wbond.net/Package%20Control.sublime-package'
Get-ChocolateyWebFile -url $packageUrl -fileFullPath $packageControl Get-ChocolateyWebFile -url $packageUrl -fileFullPath $packageControl
} }
}
3 {
Push-Location $packagesPath
git clone -b python3 https://github.com/wbond/sublime_package_control.git "Package Control"
Pop-Location
}
}
} }
function Merge-PackageControlSettings function Merge-PackageControlSettings
@@ -75,10 +129,15 @@ function Merge-PackageControlSettings
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string] [string]
$FilePath $FilePath,
[Parameter(Mandatory = $false)]
[ValidateRange(2,3)]
[int]
$Version = 2
) )
$root = Get-SublimeUserPath $root = Get-SublimeUserPath -Version $Version
$existingPath = Join-Path $root 'Package Control.sublime-settings' $existingPath = Join-Path $root 'Package Control.sublime-settings'
if (!(Test-Path $existingPath)) if (!(Test-Path $existingPath))
{ {
@@ -113,10 +172,15 @@ function Merge-Preferences
param( param(
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[String] [String]
$FilePath $FilePath,
[Parameter(Mandatory = $false)]
[ValidateRange(2,3)]
[int]
$Version = 2
) )
$root = Get-SublimeUserPath $root = Get-SublimeUserPath -Version $Version
$existingPath = Join-Path $root 'Preferences.sublime-settings' $existingPath = Join-Path $root 'Preferences.sublime-settings'
if (!(Test-Path $existingPath)) if (!(Test-Path $existingPath))
{ {