作者:caiyafang4376 | 来源:互联网 | 2023-05-30 01:59
Ihavevariousshellbuildscriptsforaprojectandwanttocreateonecentralizedbuildsystemwit
I have various shell build scripts for a project and want to create one centralized build system with options that will allow which shell script to run. For example, a user presses Cmd + B then the user is given the option:
我有一个项目的各种shell构建脚本,并希望创建一个集中构建系统,其中包含允许运行哪个shell脚本的选项。例如,用户按下Cmd + B,然后为用户提供选项:
1) shellscript1.sh
2) shellscript2.sh
3) shellscript3.sh
1)shellscript1.sh 2)shellscript2.sh 3)shellscript3.sh
The user presses 3 and Sublime Text runs 'sh shellscript3.sh'.
用户按3,Sublime Text运行'sh shellscript3.sh'。
I've been reading http://sublimetext.info/docs/en/reference/build_systems.html, but am unsure how to integrate this option in the JSON code for the Sublime Text build system.
我一直在阅读http://sublimetext.info/docs/en/reference/build_systems.html,但我不确定如何在Sublime Text构建系统的JSON代码中集成此选项。
How do you accomplish this in a build system in Sublime Text 2?
你如何在Sublime Text 2的构建系统中实现这一目标?
Thanks!
3 个解决方案
2
Actually, you do not need your own plugin. All you need are build variants. Here's simple example using your example commands:
实际上,您不需要自己的插件。您只需要构建变体。以下是使用示例命令的简单示例:
{
"name Script 1",
"cmd": ["shellscript1.sh", "$file"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${project_path:${folder:${file_path}}}",
"variants":
[
{
"name": "Script 2",
"cmd": ["shellscript2.sh", "$file"]
},
{
"name": "Script 3",
"cmd": ["shellscript3.sh", "$file"]
}
]
}
Save this in your User preferences folder as MyScript.sublime-build. You will then be able to select it from the build menu, turning off the automatic target.
将其作为MyScript.sublime-build保存在用户首选项文件夹中。然后,您可以从构建菜单中选择它,关闭自动目标。
Now, when you press Command+B (on Mac, Control+B on Windows and Linux), the default target executes Script 1, on your file, but you can also select either of the variants.
现在,当您按下Command + B(在Mac上,在Windows和Linux上为Control + B)时,默认目标会在您的文件上执行脚本1,但您也可以选择其中一个变体。
See this answer, also, for a build file that I personally use providing variants for different Make targets.
对于我个人使用的构建文件,请参阅此答案,为不同的Make目标提供变体。