How do I receive text from stdin into sublimetext editor? With vim it works like this:
echo "potato potato potato" | vim -
The same thing works with gedit, creating a new document with the contents.
Sublimetext seems to just start editing a file called "-" in a new tab, is there some other shell trick which could work?
To install Package Control, click Tools > Install Package Control. Sublime Text will now take a few seconds and automatically install it for you. Bring up Command Palette by pressing Ctrl + Shift + P, and then search "package control" in the search window.
Type : subl in terminal to launch Sublime Text 3 from terminal.
Type 'Terminus' and select it. Wait for it to Complete installation and Restart sublime text. And save it. Note: The above code is for Linux users for Windows users you have to enter “cmd.exe” in place of “bash”, also here we kept the shortcut key as “alt+1” you can use your own key.
Assuming Sublime still doesn't support opening STDIN, a straightforward solution is to dump the output to a temporary file, open the file in sublime, and then delete the file. Say you create a script called tosubl
in your bin directory as follows:
#!/bin/bash TMPDIR=${TMPDIR:-/tmp} # default to /tmp if TMPDIR isn't set F=$(mktemp $TMPDIR/tosubl-XXXXXXXX) cat >| $F # use >| instead of > if you set noclobber in bash subl $F sleep .3 # give subl a little time to open the file rm -f $F # file will be deleted as soon as subl closes it
Then you could use it by doing something like this:
$ ps | tosubl
But a more efficient and reliable solution would be to use to use Process Substitution if your shell supports it (it probably does). This does away with the temporary files. Here it is with bash:
tosubl() { subl <(cat) } echo "foo" | tosubl
I'm pretty sure you can somehow remove the use of cat
in that function where it's redundantly shoveling bits from stdin to stdout, but the syntax to do so in that context eludes me at the moment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With