Sublime Text构建系统启动时添加自定义默认消息及时间需求
给Sublime Build添加带时间的启动提示
默认Sublime Build完成后会显示[Finished]消息,要在启动时自动输出[Started HH:MM:SS]格式的提示,有两种实用方案:
方案一:自定义构建系统(单语言/项目适配)
适合只需要给特定语言或项目的构建添加提示的场景:
- 点击顶部菜单
Tools > Build System > New Build System - 替换默认内容为下面的配置(以Python为例,可根据需求替换
cmd里的实际构建命令):
{ "cmd": ["python3", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", "pre_build": [ {"shell_cmd": "echo \"[Started $(date +'%H:%M:%S')]\""} ] }
- 保存为
CustomPython.sublime-build(文件名自定义),之后选择这个构建系统执行构建即可。
系统适配:
- Linux/macOS:上面的配置直接用,
date +'%H:%M:%S'会输出24小时制的时分秒。 - Windows:把
pre_build里的命令换成Windows cmd语法:"pre_build": [ {"shell_cmd": "echo [Started %time:~0,8%]"} ]
方案二:全局插件(所有构建生效)
如果希望所有构建系统都自动显示启动提示,写个轻量插件即可:
- 点击
Preferences > Browse Packages,进入User文件夹 - 创建
BuildStartMessage.py文件,写入以下代码:
import sublime import sublime_plugin import time class BuildStartListener(sublime_plugin.EventListener): def on_build_start(self, view): current_time = time.strftime("%H:%M:%S", time.localtime()) view.window().run_command("append", { "characters": f"[Started {current_time}]\n", "force": True, "scroll_to_end": True })
- 重启Sublime,之后任何构建启动时,控制台都会自动弹出带时间的启动提示。
内容的提问来源于stack exchange,提问作者User
相关产品推荐
相关产品推荐

