sublime text 3 下的nodejs环境配置以及新增nodejs的操作按钮实现杀死node进程,待优化

提前说明

本人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" },


在Context.sublime-menu文件
{ "id": "nodejsrun", "caption": "Run", "command": "node_run" },后新增一行以下内容
   { "id": "nodejsstop", "caption": "Stop", "command": "node_stop" },

在文件Default.sublime-commands内容为

{
  "caption": "Nodejs::Run::Current File",
  "command": "node_run"
},
的后面新增
{
  "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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值