ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Shell Exec

by gbaptista ST3

Run shell commands like git, rvm, rspec, ls, etc. with Bash, Zsh and others inside your Sublime Text 3.

Details

Installs

  • Total 14K
  • Win 5K
  • OS X 5K
  • Linux 4K
Aug 18 Aug 17 Aug 16 Aug 15 Aug 14 Aug 13 Aug 12 Aug 11 Aug 10 Aug 9 Aug 8 Aug 7 Aug 6 Aug 5 Aug 4 Aug 3 Aug 2 Aug 1 Jul 31 Jul 30 Jul 29 Jul 28 Jul 27 Jul 26 Jul 25 Jul 24 Jul 23 Jul 22 Jul 21 Jul 20 Jul 19 Jul 18 Jul 17 Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6 Jul 5 Jul 4
Windows 4 9 8 9 7 6 4 4 5 8 11 7 7 3 2 8 5 5 4 6 4 2 8 8 10 8 3 4 2 2 6 8 10 4 1 2 2 6 5 5 5 2 2 3 8 7
OS X 3 1 2 8 2 4 1 4 4 6 4 3 2 3 1 8 3 6 4 3 0 6 7 4 6 9 4 4 1 4 3 6 5 4 2 4 8 6 6 6 3 2 2 3 3 6
Linux 3 5 6 7 6 1 4 1 6 3 3 3 4 3 1 2 4 6 3 3 6 3 6 5 2 2 2 1 3 4 3 7 0 1 1 2 5 3 1 3 4 1 1 3 6 5

Readme

Source
raw.​githubusercontent.​com

Shell Exec

Run shell commands like git, rvm, rspec, ls, etc. with Bash, Zsh and others inside your Sublime Text 3.

Demo: RSpec inside Sublime

Command Palette

Shell Exec: Open shell_exec_open

Default Shortcuts

  • Linux: ctrl + shift + c
  • Mac: shift + super + c
  • Windows: ctrl + shift + c

Settings

User/Preferences.sublime-settings:

// You can use this file to load RVM, ~/.bashrc, custom shell functions...
// "shell_exec_load_sh_file": "your-sh-file-to-load-before-commands.sh",

// Shell executable: "/bin/bash", "/bin/sh", "/usr/bin/zsh"...
"shell_exec_executable": "/bin/bash",

// Shell executable option: --login # Run as login load your ~/.bashrc or other user settings.
"shell_exec_executable_option": "--login", // ["-l"] ["--login"]

// The output of the command can be shown on the Panel or in a New File: "panel", "file" or "none".
"shell_exec_output": "file",

// Set the Output File Syntax. Default is Ruby, because Ruby looks nice. =)
"shell_exec_output_syntax": "Ruby",

// Enable or Disable the  word wrap at the Output File.
"shell_exec_output_word_wrap": true,

// Enable or Disable the Debug infos (for plugin developers).
"shell_exec_debug": false,

// Name of the Shell Exec command box.
"shell_exec_title": "Shell Exec",

// Defines where the command should be executed: false, "project_folder" or "file_folder".
// If "project_folder" is set, will execute: cd project_folder && your_commnad.
"shell_exec_context": "project_folder",

Custom Shortcuts

shell_exec_open: Open Shell Exec box to input some command.

shell_exec_run: Runs a predefined command.

User/Default (Linux).sublime-keymap:

{
  // (ctrl+shift+c+o) key binding
  "keys": ["ctrl+shift+c", "ctrl+shift+o"],

  // "shell_exec_open": Open Shell Exec box to input some command.
  // "shell_exec_run": Runs a predefined command.
  "command": "shell_exec_open",

  "args": {
    // Title of the Shell Exec box.
    "title": "Shell Exec",

    // Predefined command.
    "command": "git status",

    // Format the command with variables.
    "format": "git ${input}",

    // You can use this file to load RVM, ~/.bashrc, custom shell functions...
    // "load_sh_file": "your-sh-file-to-load-before-commands.sh",

    // Shell executable: "/bin/bash", "/bin/sh", "/usr/bin/zsh"...
    "executable": "/bin/bash",

    // Shell executable option: --login # Run as login load your ~/.bashrc or other user settings.
    "executable_option": "--login", // ["-l"] ["--login"]

    // The output of the command can be shown on the Panel or in a New File: "panel", "file".
    "output": "file",

    // Set the Output File Syntax. Default is Ruby, because Ruby looks nice. =)
    "output_syntax": "Ruby",

    // Enable or Disable the  word wrap at the Output File.
    "output_word_wrap": true,

    // Enable or Disable the Debug infos (for plugin developers).
    "debug": false,

    // Name of the Shell Exec command box.
    "title": "Shell Exec",

    // Defines where the command should be executed: false, "project_folder" or "file_folder".
    // If "project_folder" is set, will execute: cd project_folder && your_commnad.
    "context": "project_folder",
  }
}

Command Format Syntax

// (ctrl+shift+c+f) key binding
"keys": ["ctrl+shift+c", "ctrl+shift+f"],

// "shell_exec_open": Open Shell Exec box to input some command.
// "shell_exec_run": Runs a predefined command.
"command": "shell_exec_exec",

"args": {
    // Format the command with variables.
    "format": "rspec '${file}:${row}'"
}

Available variables: * ${input}: Input from Shell Exec box. * ${region}: Selected text. * ${row}: Selected row number or the cursor position at file. * ${file_name}: ShellExec.py * ${file}: /home/user/.config/sublime-text-3/Packages/shell-exec/ShellExec.py * ${packages}: /home/user/.config/sublime-text-3/Packages * ${file_base_name}: ShellExec * ${platform}: Linux * ${file_extension}: py * ${file_path}: /home/user/.config/sublime-text-3/Packages/shell-exec * ${folder}: /home/user/.config/sublime-text-3/Packages/shell-exec

Common Problems

RVM Command, ~/.bashrc, ~/.bash_profile, ~/.zshrc…

You can load RVM and profile files with login mode:

// Shell executable: "/bin/bash", "/bin/sh", "/usr/bin/zsh"...
"shell_exec_executable": "/bin/bash",

// Shell executable option: --login # Run as login load your ~/.bashrc or other user settings.
"shell_exec_executable_option": "--login", // ["-l"] ["--login"]

Or… You can load a custom sh file:

"shell_exec_load_sh_file": "my-config-loader-file.sh"

my-config-loader-file.sh: Loading ~/.bashrc simulating interactive shell:

PS1=true # Simulate Interactive Shell
source ~/.bashrc

my-config-loader-file.sh: Loading RVM command:

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Debugging

Just enable the debug to see panel outputs: User/Preferences.sublime-settings:

// Enable or Disable the Debug infos (for plugin developers).
"shell_exec_debug": true,

Some Cool Demos

Git

{
  "keys": ["ctrl+shift+g", "ctrl+shift+g"],
  "command": "shell_exec_open",
  "args": { "title": "Git Command:", "format": "git ${input}" }
},
{
  "keys": ["ctrl+shift+g", "ctrl+shift+c"],
  "command": "shell_exec_open",
  "args": {
    "title": "Git Checkout:",
    "format": "git checkout ${input}",
    "command": "'${file}'"
  }
},
{
  "keys": ["ctrl+shift+g", "ctrl+shift+s"],
  "command": "shell_exec_run",
  "args": { "command": "git status" }
},
{
  "keys": ["ctrl+shift+g", "ctrl+shift+d", "ctrl+shift+a"],
  "command": "shell_exec_run",
  "args": { "command": "git diff", "output_syntax": "Diff" }
},
{
  "keys": ["ctrl+shift+g", "ctrl+shift+d", "ctrl+shift+f"],
  "command": "shell_exec_run",
  "args": { "command": "git diff '${file}'", "output_syntax": "Diff" }
},
{
  "keys": ["ctrl+shift+g", "ctrl+shift+b"],
  "command": "shell_exec_run",
  "args": { "command": "git blame '${file}'", "output_syntax": "Git Blame" }
}

RSpec

{
  "keys": ["ctrl+shift+r", "ctrl+shift+r"],
  "command": "shell_exec_open",
  "args": {
    "title": "RSpec Command:", "format": "rspec ${input} --require spec_helper"
  }
},
{
  "keys": ["ctrl+shift+r", "ctrl+shift+o"],
  "command": "shell_exec_open",
  "args": {
    "title": "RSpec Command:",
    "command": "'${file}:${row}'",
    "format": "rspec ${input} --require spec_helper"
  }
},
{
  "keys": ["ctrl+shift+r", "ctrl+shift+a"],
  "command": "shell_exec_run",
  "args": { "command": "rspec spec --require spec_helper" }
},
{
  "keys": ["ctrl+shift+r", "ctrl+shift+f"],
  "command": "shell_exec_run",
  "args": { "command": "rspec '${file}' --require spec_helper" }
},
{
  "keys": ["ctrl+shift+r", "ctrl+shift+l"],
  "command": "shell_exec_run",
  "args": { "command": "rspec '${file}:${row}' --require spec_helper" }
},
{
  "keys": ["ctrl+shift+r", "ctrl+shift+s"],
  "command": "shell_exec_run",
  "args": { "command": "rspec '${region}' --require spec_helper" }
}

Unix

{
  "keys": ["ctrl+shift+u", "ctrl+shift+p"],
  "command": "shell_exec_open",
  "args": {
    "title": "Find Process",
    "format": "ps aux | grep ${input}"
  }
}