Git Product home page Git Product logo

vscode-run-as's Introduction

Run As

Marketplace Installs Ratings

README in Other Languages

简体中文

Features

  1. Right Click a file, then
    • Run *.js in node
    • Run *.ts corresponding compiled *.js in node
    • Run *.bat, *.cmd, *.sh to start a task:
      • Run a watcher in a new integrated terminal in vscode
      • Run a server in a new terminal windows out of vscode
    • Open binary file in default application or the application you like
  2. Automatic switch working directory when run different file in a different folder in the workspace.
  3. New! More mode to control the behavior of terminal and panel.

Usage

After configuration, right Click a file, then select the menu item "Run As ...".

preview

Configuration

Open VSCode setting (Ctrl+Comma), search for "runas" to change configuration:

1. Globs-to-command mapping

An array of globs-to-cmd.

"RunAs.globsMapToCommand": [...]

globs-to-cmd structure:

{
    "globs": "*.*",
    "mode": "silent",
    "command": {
        "win32": "start ${rPath}",
        "linux": "see ${rPath}",
        "darwin": "open ${rPath}"
    },
    "exceptions": [...] // An array of `globs-to-cmd`.
}

1.1 globs-to-cmd.globs

A pattern to match file's path name.

{
    "globs": "\\[*\\]*.cmd",
    // ...
}

PS: you need to use \\ instead of \ to escape character in Globs.

1.2 globs-to-cmd.command

The command runs in shell after selecting the menu item "Run as ...".

1.2.1 command template(s)

  • A general command, example:

    {
        // ...
        "command": "node ${rPath}"
    }
  • Or a platform-to-command map, example:

    {
        // ...
        "command": {
            "win32": "start ${rPath}",
            "linux": "see ${rPath}",
            "darwin": "open ${rPath}"
        }
    }

1.2.2 command argument - path: ${...}

A javascript code snippet, it looks like ${/* javascript */}. It can be:

  1. A variable, example: ${rPath}
  2. A template string, example: ${`out/${dir}/${sFile}.js`}
  3. A javascript code snippet, example: ${file.replace(/(\\/(?:src|test)\\/)/, '/out$1').replace(/ts$/, 'js')}, this code snippet in default configuration means right click to run *.ts but actually execute the *.js in folder out.
    • PS: you need to use \\ instead of \ to escape character in RegExp literal.

1.2.3 command prefix: @ + terminal mode

A quick way to set terminal mode for one command.

{
    // ...
    "command": "@silent start ${rPath}"
}

1.3 globs-to-cmd.mode

{
    // ...
    "mode": "silent",
}

Set terminal mode for commands on different platforms, it decides the behaviors of the terminal and the panel. Default value is equal to "RunAs.runInNewTerminalWindows.enable".

Available terminal mode:

  1. silent: Execute a command in the integrated terminal, but don't show the panel if you had not opened it.
  2. in: Execute a command in the integrated terminal, and show the panel for printing the results.
  3. block: Execute a command in a new integrated terminal for a task which will block the terminal.
  4. out: Execute a command in a new terminal window out of vscode.

1.4 globs-to-cmd.exceptions

A array of globs-to-command mapping, files matched one of them will execute itself command instead of its parent's command.

{
    // ...
    "exceptions": [{
        "globs": "*.@(bat|cmd|exe)",
        "command": ".\\${rPath}"
    }]
}

Table: Variable Meaning

Variable Meaning Example
file full path of the file which you right clicked D:\projects\project\src\common\module.ts
root the folder opened in vscode D:\projects\project
rPath the relative path from root to file src\common\module.ts
dir the relative path from root to file's directory src\common
lFile the file's name with extension module.ts
sFile the file's name without extension module
ext the file's extension ts

2. Execute command in a new terminal windows

"RunAs.runInNewTerminalWindows": {
    "enable": false,
    "globs": "New Terminal Window",
    "command": {
        "win32": "Start-Process cmd -ArgumentList '/c ${command}'",
        "linux": "gnome-terminal -x bash -c '${command}'"
    }
}

In "RunAs.runInNewTerminalWindows.commands",

  • The key is platform string in VSCode:
    • Windows: "win32",
    • Linux: "linux"
    • Mac OS: "darwin"
  • The value is the command to execute a command in a new terminal windows in this platform, e.g. "start ${command}".
    • ${command} will be replaced by the command in globs-to-command mapping.

You can run the command in a new terminal windows in default by changing "RunAs.runInNewTerminalWindows.enable" to true, or you can use the prefix @out in the command to use it alone.

Install

Press F1 in VSCode, type ext install and then look for "Run as ..." .

Known Issue

  • I do not know how to pass a command to a new terminal to execute it in Mac OS, but you can configure it by yourself.

Issues

Submit the issues if you find any bug or have any suggestion.

Contribution

Fork the repository and submit pull requests.

About

Author:plylrnsdy

Github:vscode-run-as

vscode-run-as's People

Contributors

plylrnsdy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

kapete23

vscode-run-as's Issues

New external terminal without using internal terminal

When launching an external terminal, the command is issued from the internal terminal. So even if the internal terminal is hidden, it is still there and still needs to be closed at some point.

Is it possible not to use the internal terminal at all?

ubuntu 18.10
vscode 1.33.0

does not work anymore

Hello for some time run as has not worked, I can't explain it to myself,

What do you need as information to debug me?

Tip: run sh on macOS.

Try to add following option to your config file.

  "RunAs.globsMapToCommand": [
    {
      ...
      "exceptions": [
        ...
        {
          "globs": "*.sh",
          "command": "sh ${rPath}"
        }
      ]
    }
  ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.