Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

367
Vistas
How to pipe input to sublimetext on linux?

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?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

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.

over 4 years ago · Santiago Trujillo Denunciar

0

I don't know Sublime Text, but your problem should be generic in that it applies to any program that does accept a filename as argument, but refuses to read from stdin.

Fortunately, Bash allows you to pipe stdout from one process into some kind of temporary file, then pass the name of that file to another process.

From man bash:

Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of <(list) or >(list). The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to the current command as the result of the expansion. If the >(list) form is used, writing to the file will provide input for list. If the <(list) form is used, the file passed as an argument should be read to obtain the output of list.

Assuming SomeProcess produces output that you would like to capture in your editor:

sublimetext <(SomeProcess)

or:

SomeProcess | sublimetext <(cat)

If you think you will be typing this in by hand a lot, then you may want to put sublimetext <(cat) into a shell script or alias.

Just in case your OS does not support process substitution, then you can always specify a temporary file yourself of course:

SomeProcess > /tmp/myoutput
sublimetext /tmp/myoutput
over 4 years ago · Santiago Trujillo Denunciar

0

You might find vipe from moreutils useful. If you've set EDITOR='subl --wait', you can simply:

echo 'potato potato potato' | vipe
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda