Sublime Text: FilterPipes: how to process selected text through multiple commands in bash shell

I recently added the FilterPipes package in ST to allow me to pass a text selection to shell and execute commands on it. For example:

    {    /* FIGlet: convert selected text to multiline banner */
        "caption": "FilterPipes: FIGlet banner",
        "command": "filter_pipes_process",
        "args": {
            "command": ["figlet", "-f", "banner", "-w", "400"]

This will pass the text selection to shell's stdin in the background, and execute the figlet command with the arguments -f banner -w 400, returning a multiline text banner of the selected text in ST using figlet's banner font. The command along with each argument & parameter have to be in double quotes, and separated by commas.

The problem arises when I want to pipe the stdout of the command passed through to shell into some other command(s). e.g., if I want the shell command line to be figlet -f banner -w 400 | tr '# ' '@.' There doesn't seem to be any way to handle passing more than one command. If I add the pipe or any other commands/arguments delimited like the first command and its args, it only seems to process the first command. I've also tried adding the additional commands in the JSON file/syntax, but then only the last command listed is processed.

Is there some way – maybe using awk – that I could send the text to shell's stdin and have it (or some other multi-command processor) receive any of the other commands & arguments/parameters to process the text selection through as arguments to the awk command?

I've never used awk before, & it's pretty overwhelming. But if it can do this sort of thing, I'm hoping to get some guidance on how to process the stdin through several commands using awk – for instance, what the syntax needs to look like for proper escaping, where that's necessary, etc.

I read through the man page for awk already. But with my disability, it's very difficult to take in all the info & parse out just the stuff I need to know pertaining to this particular use case.

The file type containing the FilterPipes commands is .sublime-commands, and it's JSON syntax. The commands/args and selected text are being passed through bash shell via a python script containing the filter_pipes_process function.

Author: Subham

Leave a Reply

Your email address will not be published. Required fields are marked *