Sublime Forum

[ST2] subl --command?

#1

hi,

I naively thought that the argument following command could be any command valid on the console line. However the following,

~> subl --command ‘sublime.status_message(“It works!”)’

results in

Unable to parse command: sublime.status_message(“It works!”)

in ST2 console output.

This is with the latest version of ST2 on MacOS X.

Best wishes,

Luc J. Bourhis

0 Likes

#2

Trials and errors lead to the conclusion that subl --command accepts what commands, i.e. what run_command accepts. So for example,

~> subl --command ‘prompt_select_project’

works fine by opening the project chooser panel. But how to deal with commands taking argument, e.g. goto_line:

view.run_command(‘goto_line’, {‘line’: 10})

I have tried

~> subl --command ‘goto_line, {“line”:15}’

and variations around that but to no avail. Would anybody know the answer to this updated question?

0 Likes

#3

Remove the comma.subl --command 'goto_line {"line":15}'

0 Likes

#4

Thanks!

0 Likes

#5

I’m trying this stuff on ST3 (on OSX) and nothing seems to work. ST3 just opens a new empty window. Any ideas?

0 Likes

#6

subl --command 'goto_line {"line":15}' path/to/some/file

opens the file for me (I am also using an up-to-date ST3) but the cursor is not moved to the required line. So it seems --command does not work as it used to be when @quarnster answered my question. Note that for this particular application, this is not necessary since one can do

subl path/to/some/file:15

0 Likes

#7

The --command argument wants you to specify a single string that contains the command name followed by the arguments (if any are needed), all in one string. A gotcha here is that you may need to do some quoting of things to make the string valid.

Depending on where your commands are coming from, you may need to resort to quoting the quote characters so that they slowly get “quoted away” as they pass through the various layers until they eventually get to the command interpreter.

For example, directly from the shell, the following two commands will both toggle the state of the console in the active window.

subl --command 'show_panel {"panel": "console", "toggle": true}'
subl --command "show_panel {\"panel\": \"console\", \"toggle\": true}"

On the other hand, I have Sublimerge 3 set up to be a merge tool and a diff tool for command line git, where the ultimate configuration has to look something like this:


[difftool "sublimerge"]
    cmd = subl -n --wait \"$REMOTE\" \"$LOCAL\" --command \"sublimerge_diff_views {\\\"left_read_only\\\": false, \\\"right_read_only\\\": true}\"
0 Likes

Run in command line/bash: open/save with encoding multiple files
Subl --read-only flag
#8

@OdatNurd I see, I finally get a panel showing op :slightly_smiling:. Just to be clear, I suppose only ApplicationCommands are allowed?

EDIT: No, it seems even ViewCommands are allowed if you specify a filename too as indicated by @ljbo3’s example.

0 Likes