Skip to content

Add support for embeded AWK syntax highlighting #212

@jpotter23

Description

@jpotter23

I frequently use bash with embed GAWK in my tools. In order to syntax highlight the awk sections, I have to toggle between shell and awk syntax, which gets tedious and makes it so that refactoring gets clunky as it cannot tell where bash ends and GAWK begins. Example:

Begin of FIle: Test.txt

<Ips>
    <Ip>192.168.0.1</Ip>
    <Ip>192.168.1.1</Ip>
    <Ip>192.168.3.7</Ip>
    <Ip>192.168.4.1</Ip>
    <Ip>192.168.5.1</Ip>
</Ips>

End of File: Test.txt

Begin BASH/AWK Script Example:

#!/usr/local/bin
  BASH_VAR1="BASH1"
  BASH_VAR2="BASH2"
  cat Test.txt | awk  \
      -v "BASH_VAR1=$BASH_VAR1"\
      -v "BASH_VAR2=$BASH_VAR2" '
      BEGIN {
          AWK_VAR1="AWK1";
          AWK_VAR2="AWK2";
          split("",safe_ips);
      }
  
      /<Ip>.*<\/Ip>/{
        ip=gensub("</?Ip>","","g",$1);
        safe_ips[ip]=ip;
      }
  
      END {
        for (e in safe_ips) {
          print "\t",BASH_VAR1,AWK_VAR1,e;
        }
      }
  '  |  column -t

I've seen embed awk syntax highlighting within VIM before (see answer here) was hoping to have that support after moving to a full IDE like PhpStorm.

Here's to hoping for better tomorrow :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions