Home Download Buy Blog Forum Support

From command line: create a buffer with specified text?

From command line: create a buffer with specified text?

Postby hthr on Mon Jun 25, 2012 2:07 pm

Using the command line, is it possible to create a new file with some pre-defined text?

E.g. something like...
Code: Select all
subl path/to/new/file.md "hello there!"


...which should open a sublime window corresponding to (an as of yet unsaved) file at path/to/new/file.md with the text from the command line inserted into the first line:
Code: Select all
hello there!
hthr
 
Posts: 4
Joined: Mon Jun 25, 2012 2:02 pm

Re: From command line: create a buffer with specified text?

Postby C0D312 on Mon Jun 25, 2012 2:18 pm

You might be able to do this using subl --command.

Just trigger the command 'insert_snippet'
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: From command line: create a buffer with specified text?

Postby hthr on Mon Jun 25, 2012 2:51 pm

Nice. Ok-- just tried it, but no luck. Perhaps I don't understand how to use --command (just discovered it this afternoon, and can't find much for docs on it).

I tried:
Code: Select all
subl --command 'insert_snippet{"woohoo"}' ~/Desktop/yay.md

and
Code: Select all
subl --command 'insert_snippet{"contents":"woohoo"}' ~/Desktop/yay.md


Both open a file called yay.md, but no snippet is inside of it. I also found that there's a sublime command called "insertSnippet" here: http://www.sublimetext.com/docs/commands, tried with "insertSnippet" instead of "insert_snippet" but still no dice.

Am I just misusing the --command argument?
hthr
 
Posts: 4
Joined: Mon Jun 25, 2012 2:02 pm

Re: From command line: create a buffer with specified text?

Postby hthr on Mon Jun 25, 2012 3:42 pm

Update...
It seems I'm using the --command argument properly, as I can set the color_scheme successfully this way:
Code: Select all
subl --command 'set_setting {"setting": "color_scheme", "value": "Packages/Color Scheme - Default/Solarized (Dark).tmTheme"}'

However, I've found two commands, both "insert" and "insert_snippet", neither of which work when used in the following way (the file is opened, but no string is present in the newly opened sublime tab):
Code: Select all
subl --command 'insert {"string" : "woohoo"}' ~/Desktop/yay.md
subl --command 'insert_snippet {"contents" : "woohoo"}' ~/Desktop/yay.md


Commands found at: http://docs.sublimetext.info/en/latest/reference/commands.html

Any insight very much appreciated! :)
hthr
 
Posts: 4
Joined: Mon Jun 25, 2012 2:02 pm

Re: From command line: create a buffer with specified text?

Postby C0D312 on Mon Jun 25, 2012 3:48 pm

Someone might generously write a plugin that creates a new file and inserts text as an argument. That way you can trigger it from the command line. I'm supposed to be working on something else at the moment, or else I would help. Sorry.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: From command line: create a buffer with specified text?

Postby quarnster on Mon Jun 25, 2012 3:53 pm

If you are starting it from the shell anyway, why not just use the shell functionality?
Code: Select all
echo "woohoo" > ~/Desktop/yay.md && subl ~/Desktop/yay.md
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: From command line: create a buffer with specified text?

Postby C0D312 on Mon Jun 25, 2012 4:33 pm

quarnster: there you go making me look bad again... Stop trying to make everything simpler :evil:
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: From command line: create a buffer with specified text?

Postby quarnster on Mon Jun 25, 2012 5:42 pm

It's not a competition mate..
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: From command line: create a buffer with specified text?

Postby hthr on Mon Jun 25, 2012 5:46 pm

quarnster wrote:If you are starting it from the shell anyway, why not just use the shell functionality?
CODE: SELECT ALL
echo "woohoo" > ~/Desktop/yay.md && subl ~/Desktop/yay.md


Jeez, of course. Thanks a lot for being the guiding light here, I wound up in a maze there, shell somehow eluded me. Thanks again.
hthr
 
Posts: 4
Joined: Mon Jun 25, 2012 2:02 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], Orlmente and 26 guests