Skip to content

Instantly share code, notes, and snippets.

@martinhbramwell
Last active February 20, 2022 23:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinhbramwell/f3cbbe66d730e9e63093 to your computer and use it in GitHub Desktop.
Save martinhbramwell/f3cbbe66d730e9e63093 to your computer and use it in GitHub Desktop.
A liittle toolkit for testing AWK scripts
#!/bin/bash
#
declare -a FILENAMES=("Create_remote_GitHub_repository_B.md");
# echo Passing "ls -l" to $1 through awk;
cat ${1} | awk -f ${2};
echo ­"------------------ \n";
#
#!/usr/bin/awk -f
#
function blue(s) {
return "\033[1;34m" s "\033[0m"
}
function green(s) {
return "\033[1;32m" s "\033[0m"
}
function lightRed(s) {
return "\033[1;91m" s "\033[0m"
}
function lightGreen(s) {
return "\033[1;92m" s "\033[0m"
}
function inverted(s) {
return "\033[7m" s "\033[27m"
}
function underline(s) {
return "\033[4m" s "\033[24m"
}
function boldZone(count) {
if (count%2 > 0) return "\033[1m";
return "\033[21m";
}
function paleZone(count) {
if (count%2 > 0) return "\033[2m";
return "\033[22m";
}
function invertedZone(count) {
if (count%2 > 0) return "\033[7m";
return "\033[27m";
}
function lightGreenZone(count) {
if (count%2 > 0) return "\033[1;92m";
return "\033[0m";
}
function magentaZone(count) {
if (count%2 > 0) return "\033[1;35m";
return "\033[0m";
}
function greenZone(count) {
if (count%2 > 0) return "\033[1;32m";
return "\033[0m";
}
function blueZone(count) {
if (count%2 > 0) return "\033[1;34m";
return "\033[0m";
}
function lightBlueZone(count) {
if (count%2 > 0) return "\033[1;94m";
return "\033[0m";
}
function italicsZone(count) {
if (count%2 > 0) return "\033[1;94m";
return "\033[0m";
}
function terminalSyntaxHighlight(count, line) {
if (count%2 > 0) return "»»»"line;
return line;
}
BEGIN {
print lightRed("\n -- start --");
blueOn=1;
invertedOn=1;
lightBlueOn=1;
lightGreenOn=1;
magentaOn=1;
greenOn=1;
boldOn=1;
italicsOn=1;
terminalSyntaxOn=1;
}
{
if (match($0,"^`{2,}")) {
terminalSyntaxOn++;
print "+------------------------------------------------------------+";
} else {
if ( terminalSyntaxOn % 2 < 1 ) {
# print "Line is :: "$0;
command = "./qtst.sh '"$0"'";
if ( (command | getline var) > 0) { print " "var; };
close(command);
} else {
while (match($0,"<a[^>]*href=[^>]*>")) {
before = substr($0,1,RSTART-1);
after = substr($0,RSTART+RLENGTH);
sub(/<\/a>/, "", after);
$0=before after;
}
while (match($0,"`{3,}")) {
before = substr($0,1,RSTART-1);
after = substr($0,RSTART+RLENGTH);
$0=before invertedZone(invertedOn++) after;
}
while (match($0,"a{2,}")) {
before = substr($0,1,RSTART-1);
after = substr($0,RSTART+RLENGTH);
$0=before lightGreenZone(lightGreenOn++) after;
}
# Double asterisk is markdown syntax for bold
while (match($0,"\\*{2,}")) {
before = substr($0,1,RSTART-1);
after = substr($0,RSTART+RLENGTH);
$0=before boldZone(boldOn++) after;
}
# Single asterisk is markdown syntax for italics
while (match($0,"\\*")) {
before = substr($0,1,RSTART-1);
after = substr($0,RSTART+RLENGTH);
$0=before italicsZone(italicsOn++) after;
}
if (match($0,"^#{2,} *")) {
after = substr($0,RSTART+RLENGTH);
$0= " " underline(after);
}
print $0;
}
}
}
END {
print lightRed(" -- done --");
}
#!/bin/bash
#
echo $1 > temp.sh;
pygmentize temp.sh;
# cat temp.sh;
#!/bin/bash
file="$1" # Name of file
command="${*:2}" # Command to run on change (takes rest of line)
t1="$(ls --full-time $file | awk '{ print $7 }')" # Get latest save time
while true
do
t2="$(ls --full-time $file | awk '{ print $7 }')" # Compare to new save time
if [ "$t1" != "$t2" ];then t1="$t2"; $command; fi # If different, run command
sleep 0.5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment