#INTRO:
I’ve seen a few threads about capturing input in builds recently, so I decided to put together an easy way to manage builds from a central location.
The script requires a Windows PC with PowerShell.
( tested with: PowerShell: v5.0, build 10586, rev 122 )
Benefits of PowerShell & This Script:
- chain multiple commands
- run parallel builds
-
SublimeBuildfor output only and/or debugging -
PowerShellfor input - both builds are independent & can receive different commands
- define all of your build commands in one file
-
sublime-buildfiles follow a simple template - strong system integration
- customizable visual style
- select & copy text
- syntax is easier to work with than batch files
Script @ GitHub
#DEMO:
@ Java
@ Python
#INFO:
There are 3 main sections in the script:
USER SETTINGSFUNCTIONSSCRIPT
USER SETTINGS is the only part of the script that needs to be modified.
It has 2 sub-sections:
Variables
- default
PowerShell&SublimeBuildstates - header options (
file|fileName|fileBase|filePath|projectName)
Build Settings
- first build to run (
PowerShellorSublimeBuild) - commands to be run @
PowerShell - commands to be run @
SublimeBuild - [optional] disable
PowerShellorSublimeBuild - [optional] disable headers
#EXAMPLES:
@ SublimeText_Builds.ps1/BuildSettings
ElseIf ( $MODE -ieq "Java_Input" )
{
$firstBuild = $SUBLIME_BUILD
$sublimeBuild_Commands += `
"If ( Test-Path " + $sQuote + $filePathSlash + $fileBase + ".class" + $sQuote + " )" + `
"{ Remove-Item " + $sQuote + $filePathSlash + $fileBase + ".class" + $sQuote + " }"
$sublimeBuild_Commands += "cd " + $sQuote + $filePath + $sQuote
$sublimeBuild_Commands += "javac -encoding UTF-8 " + $sQuote + $fileName + $sQuote
$powerShell_Commands += "cd " + $pQuote + $filePath + $pQuote
$powerShell_Commands += "java " + $fileBase
}
ElseIf ( $MODE -ieq "Java_NoInput" )
{
$firstBuild = $SUBLIME_BUILD
$sublimeBuild_Commands += `
"If ( Test-Path " + $sQuote + $filePathSlash + $fileBase + ".class" + $sQuote + " )" + `
"{ Remove-Item " + $sQuote + $filePathSlash + $fileBase + ".class" + $sQuote + " }"
$sublimeBuild_Commands += "cd " + $sQuote + $filePath + $sQuote
$sublimeBuild_Commands += "javac -encoding UTF-8 " + $sQuote + $fileName + $sQuote
$sublimeBuild_Commands += "java " + $fileBase
$powerShell_Enabled = $FALSE
$bottomHeader_Enabled = $FALSE
}
@ JavaC.sublime-build
{
"selector": "source.java",
"cmd": [ "PowerShell", "SublimeText_Builds.ps1", "Java_NoInput", "\"$file\"", "\"$file_name\"", "\"$file_base_name\"", "\"$file_path\"", "\"$project_base_name\"" ],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"variants":
[
{
"name": "Input",
"cmd": [ "PowerShell", "SublimeText_Builds.ps1", "Java_Input", "\"$file\"", "\"$file_name\"", "\"$file_base_name\"", "\"$file_path\"", "\"$project_base_name\"" ],
},
]
}
The sublime-build template only requires 3 updates when creating a new build:
selectorfile_regex- the 3rd argument of each
"cmd" - ( must match @
SublimeText_Builds.ps1/BuildSettings)

