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?

有帮助吗?

解决方案

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.

其他提示

Another approach:

bash -c 'EDITOR <(sed -e "s/\x1B\[[0-9;]*[JKmsu]//g" < "$0")' color.js
\.........................................................../ \....../
                   command                                    filename
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top