Skip to content

Commit

Permalink
Enhancement: Add setting to custom command to open in new buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
stoivo authored and divmain committed Mar 5, 2017
1 parent 40352a6 commit 1fffd01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions core/commands/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def run(self, **kwargs):

def run_async(self,
output_to_panel=False,
output_to_buffer=False,
args=None,
start_msg="Starting custom command...",
complete_msg="Completed custom command.",
syntax=None,
run_in_thread=False,
custom_argument=None,
custom_environ=None):
Expand All @@ -73,4 +75,11 @@ def run_async(self,

if output_to_panel:
util.log.panel(stdout.replace("\r", "\n"))
if output_to_buffer:
view = self.window.new_file()
view.set_scratch(True)
view.run_command("gs_replace_view_text", {"text": stdout.replace("\r", "\n"), "nuke_cursors": True})
if syntax:
view.set_syntax_file(syntax)

util.view.refresh_gitsavvy(self.window.active_view())
10 changes: 8 additions & 2 deletions docs/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ Adding new commands is as simple as creating/modifying `User.sublime-commands` f
Your custom command may be further customized by setting the following arguments:

* `output_to_panel` - send the command output to a panel when complete
* `output_to_buffer` - send the command output to a new buffer when complete
* `syntax` - If the output is printed to a buffer you can select syntax
on example:
"syntax": "Packages/GitSavvy/syntax/show_commit.sublime-syntax",
Other syntaxes comming with GitSavvy can be found in (syntax)[https://github.com/divmain/GitSavvy/tree/master/syntax]

* `args` - arguments to pass to the `git` command

GitSavvy also supports some basic interpolation when specifying your `args`. If one of these strings is provided as an element of your `args` array, the appropriate string will be substituted. The following strings are currently supported:

- `{FILE_PATH}` - the path to the currently opened file.
- `{REPO_PATH}` - the path to the currently opened file's repo path.
- `{PROMPT_ARG}` - prompt use to a custom argument
Expand All @@ -26,7 +32,7 @@ Your custom command may be further customized by setting the following arguments
* `custom_environ` - Can be used to set custom environment variables for this custom command, see example below

**:boom: Warning**

Take *extra* care when enabling `run_in_thread`; while it can be useful for long running `git` commands, if handled incorrectly, running such a background thread can have undesirable effects.


Expand Down

0 comments on commit 1fffd01

Please sign in to comment.