提前说明
本人sublime text build 3126
python 3.5.1
nodejs 6.0.2
首先谢谢我参考的环境配置同学的资料
https://my.oschina.net/ximidao/blog/413101
在该操作基础上
安装nodejs的插件后,环境配置成功后的两个文件内容
Nodejs.sublime-build
{
"cmd": ["node", "$file"],
//"cmd": ["node","--debug", "–use-strict", "–harmony","-p", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.js",
"shell":true,
"encoding": "utf8",
"windows":
{
//"cmd": ["call","killnodejs.bat $file"]
//"cmd": ["taskkill /F /IM node.exe & node $file"]
"cmd": ["node", "$file"]
},
"linux":
{
"cmd": ["killall node; node $file"]
},
"osx":
{
"cmd": ["killall node; node $file"]
}
}
然后是Nodejs.sublime-settings
{
// save before running commands
"save_first": true,
// if present, use this command instead of plain "node"
// e.g. "/usr/bin/node" or "C:\bin\node.exe"
"node_command": "C:\\Program Files\\nodejs\\node.exe",
// Same for NPM command
"npm_command": "C:\\Program Files\\nodejs\\npm.cmd",
// as 'NODE_PATH' environment variable for node runtime
//"node_path": false,
"expert_mode": true,
"ouput_to_new_tab": false
}
其中的路径为我本地的nodejs环境安装路径
现在开始新增kill node进程的菜单配置
在文件Main.sublime-menu内容
{ "id": "nodejsrun", "caption": "Run", "command": "node_run" },内容后新增一行以下内容
{ "id": "nodejsstop", "caption": "Stop", "command": "node_stop" },
{ "id": "nodejsstop", "caption": "Stop", "command": "node_stop" },
在Context.sublime-menu文件
{ "id": "nodejsrun", "caption": "Run", "command": "node_run" },后新增一行以下内容
{ "id": "nodejsstop", "caption": "Stop", "command": "node_stop" },
{ "id": "nodejsstop", "caption": "Stop", "command": "node_stop" },
在文件Default.sublime-commands内容为
{
"caption": "Nodejs::Run::Current File",
"command": "node_run"
},
"caption": "Nodejs::Run::Current File",
"command": "node_run"
},
的后面新增
{
"caption": "Nodejs::Stop::Current File",
"command": "node_stop"
},
{
"caption": "Nodejs::Stop::Current File",
"command": "node_stop"
},
在Nodejs.py文件
内容为
# Command to Run node
class NodeRunCommand(NodeTextCommand):
def run(self, edit):
command = """kill -9 `ps -ef | grep node | grep -v grep | awk '{print $2}'`"""
os.system(command)
command = ['node', self.view.file_name()]
self.run_command(command, self.command_done)
def command_done(self, result):
s = sublime.load_settings("Nodejs.sublime-settings")
if s.get('output_to_new_tab'):
self.scratch(result, title="Node Output", syntax="Packages/JavaScript/JavaScript.tmLanguage")
else:
self.panel(result)
的后面新增
# Command to Stop node
class NodeStopCommand(NodeTextCommand):
def run(self, edit):
command = """kill -9 `ps -ef | grep node | grep -v grep | awk '{print $2}'`"""
os.system(command)
command = 'taskkill /F /IM node.exe'#the command when os is win,then run cmd command
result = os.system(command)
s = sublime.load_settings("Nodejs.sublime-settings")
if s.get('output_to_new_tab'):
self.scratch(result, title="Node Output", syntax="Packages/JavaScript/JavaScript.tmLanguage")
else:
self.panel(result)
关键的是command = 'taskkill /F /IM node.exe'#the command when os is win,then run cmd command
根据具体系统环境杀死进程
后续我将打包该插件共享在github
公司外网无法上传到github
先放在百度网盘链接: http://pan.baidu.com/s/1pLzvGIv 密码: 9smx