Pergunta

I'm trying to replace an editor command like "vim" with an equivalent command that strips color codes from the input file before invoking the editor command. The script is to be invoked by bash and must fit in the format command + ' ' + filename so the trailing ) is giving me trouble:

EDITOR <(sed -e "s/\x1B\[[0-9;]*[JKmsu]//g" < color.js)

Can you think of a way to do this without the trailing ), everything must come before the file name?

Foi útil?

Solução

If your current command works, simply rewrite it as a function:

edit() { $EDITOR <(sed -e "s/\x1B\[[0-9;]*[JKmsu]//g" < "$1"); }; edit

However, the better approach is to create a script that does what you want to do and invoke that. This allows other programs to invoke the editor without passing it through a shell, which not all of them do.

Outras dicas

Another approach:

bash -c 'EDITOR <(sed -e "s/\x1B\[[0-9;]*[JKmsu]//g" < "$0")' color.js
\.........................................................../ \....../
                   command                                    filename
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top