Giter Site home page Giter Site logo

sublime-commando's Introduction

What is Commando?

Commando is a command builder plugin for Sublime Text 3.

How do I use it?

(Coming soon: Bundles!)

A Commando command looks like this:

"command": "commando",
"args": {
  "commands": [
    ["commando_exec", {"cmd": ["git", "diff", "$file"]}],
    ["commando_new_file", {"syntax": "Diff", "scratch": true, "readonly": true, "name": "Git Diff"}]
  ]
}

This opens a thread that calls git diff on the file you currently have open and sends the output of that to a new tab called "Git Diff" with "Diff" syntax. Pretty neat.

Now you can put this anywhere commands can be configured in Sublime. Let's add this command everywhere.

Menus

In your Packages/User/ directory create these files:

Main.sublime-menu

[
  {
    "caption": "Tools",
    "id": "tools",
    "children": [
      {
        "caption": "My Commands",
        "id": "my-commands",
        "children": [
          {
            "caption": "Diff File",
            "command": "commando",
            "args": {
                "commands": [
                  ["commando_exec", {"cmd": ["git", "diff", "$file"]}],
                  ["commando_new_file", {"syntax": "Diff", "scratch": true, "readonly": true, "name": "Git Diff"}]
                ]
            }
          }
        ]
      }
    ]
  }
]

Context.sublime-menu

[
  {
    "caption": "My Commands",
    "id": "my-commands",
    "children": [
      {
        "caption": "Diff File",
        "command": "commando",
        "args": {
            "commands": [
              ["commando_exec", {"cmd": ["git", "diff", "$file"]}],
              ["commando_new_file", {"syntax": "Diff", "scratch": true, "readonly": true, "name": "Git Diff"}]
            ]
          }
      }
    ]
  }
]

And now you have your own Tools > My Commands menu, as well as a context menu called My Commands (right click on any file).

Command Palette

Create another file in Packages/User/ named My Commands.sublime-commands and put this in it:

[
  {
    "caption": "Diff File",
    "command": "commando",
    "args": {
      "commands": [
        ["commando_exec", {"cmd": ["git", "diff", "$file"]}],
        ["commando_new_file", {"syntax": "Diff", "scratch": true, "readonly": true, "name": "Git Diff"}]
      ]
    }
  }
]

Now open up the command pallet and type "Diff File".

Keymaps

Finally, open up your Packages/User/Default (<Your OS>).sublime-keymap file and add this to your other keymaps:

[
...
  {
    "keys": ["ctrl+shift+d"],
    "command": "commando",
    "args": {
      "commands": [
        ["commando_exec", {"cmd": ["git", "diff", "$file"]}],
        ["commando_new_file", {"syntax": "Diff", "scratch": true, "readonly": true, "name": "Git Diff"}]
      ]
    }
  }
...
]

Now hit ctrl+shift+d to do the diff as well.

And that's it, now you can do a diff on the current file from anywhere!

Plugin

However, if you're like me, copy-pasting the same command in several places can get annoying. If you want to take this a step further you can create your own named commands through a plugin. Select Tools > New Plugin..., make the file look like this:

from Commando.plugin import CommandoRun

class GitDiffFileCommand(CommandoRun):
  def commands(self):
    return [
      ["commando_exec", {"cmd": ["git", "diff", "$file"]}],
      ["commando_new_file", {"syntax": "Diff", "scratch": True, "readonly": True, "name": "Git Diff"}]
    ]

and save it as My Commands.py. Now you have a new Sublime command called git_diff_file that you can use everywhere in place of commando. So this:

{
  "keys": ["ctrl+shift+d"],
  "command": "commando",
  "args": {
    "commands": [
      ["commando_exec", {"cmd": ["git", "diff", "$file"]}],
      ["commando_new_file", {"syntax": "Diff", "scratch": true, "readonly": true, "name": "Git Diff"}]
    ]
  }
}

becomes this:

{ "keys": ["ctrl+shift+d"], "command": "git_diff_file" },

But wait, there's more! There are already several useful commando commands you can use to build your own command, but if you need to you can also create your own if you want to. Documentation coming soon! For now, check out commands.py.

Installation

Package Control

The package is registered in Package Control under the name Commando.

Manual

Clone this repository as a subdirectory of your Sublime Text 3 Packages directory with the name Commando. So, for instance:

cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages
git clone https://github.com/ericpridham/sublime-commando.git Commando

Get Into It

Check out the wiki for full documentation.

sublime-commando's People

Contributors

ericpridham avatar

Stargazers

check avatar Simon Christmann avatar justthefracts avatar Armin avatar Lyle Moffitt avatar Petr Marek avatar Fabian Morón Zirfas avatar Dominique Wahli avatar Jérémy Romey avatar

Watchers

 avatar

Forkers

mreq

sublime-commando's Issues

$input crashes command

Whenever I use $input in a command, it crashes.

[
  {
    "caption": "Git: Checkout Branch",
    "command": "commando",
    "args": {
      "commands": [
       ["commando_input_panel", {
          "caption": "Branch name: ",
          "initial_text": "master",
          "on_done": [
            ["commando_exec", {"cmd": ["git", "checkout", "$input"]}]
          ]
        }]
      ]
    }
  }
]

I would expect this command to check out a new branch. Instead it fails:

Exception in thread Thread-12:
Traceback (most recent call last):
  File "./threading.py", line 901, in _bootstrap_inner
  File "commands in /Users/dannistjernegard/Library/Application Support/Sublime Text 3/Installed Packages/Commando.sublime-package", line 274, in run
  File "./subprocess.py", line 824, in __init__
  File "./subprocess.py", line 1386, in _execute_child
TypeError: Can't convert 'NoneType' object to str implicitly

Traceback (most recent call last):
  File "commands in /Users/dannistjernegard/Library/Application Support/Sublime Text 3/Installed Packages/Commando.sublime-package", line 86, in watch_proc
  File "commands in /Users/dannistjernegard/Library/Application Support/Sublime Text 3/Installed Packages/Commando.sublime-package", line 308, in poll
AttributeError: 'NoneType' object has no attribute 'poll'

Add ST2 Support

I've only worked on ST3 so far, but there's no reason this shouldn't have ST2 support.

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.