Last active
December 18, 2022 00:43
-
-
Save helloworld12321/d18356f5959781e818c77464e5c2846f to your computer and use it in GitHub Desktop.
A little gopher-menu-displayer program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -f | |
BEGIN { | |
RS = "\r\n" | |
FS = "\t" | |
csi = "\033[" | |
reset = csi 0 "m" | |
red = csi 31 "m" | |
green = csi 32 "m" | |
blue = csi 34 "m" | |
magenta = csi 35 "m" | |
gray = csi 90 "m" | |
} | |
function print_link(color, type, title, document, authority, port, url) { | |
type = substr($1, 1, 1) | |
title = substr($1, 2) | |
document = $2 | |
authority = $3 | |
port = $4 | |
if (document ~ /^URL:/) { | |
# Non-gopher link | |
url = substr(document, 5) | |
} else { | |
# Gopher link | |
url = "gopher://" authority ":" port "/" type document | |
} | |
print color title reset | |
print "\t" color url reset | |
} | |
{ | |
# Keep track of whether we've matched a pattern yet | |
matched = 0 | |
} | |
# Info | |
/^i/ && matched == 0 { | |
print substr($1, 2) | |
matched = 1 | |
} | |
# Text file | |
/^0/ && matched == 0 { | |
print_link(gray) | |
matched = 1 | |
} | |
# Link to gopher menu | |
/^1/ && matched == 0 { | |
print_link(blue) | |
matched = 1 | |
} | |
# Error | |
/^3/ && matched == 0 { | |
print red substr($1, 2) reset | |
matched = 1 | |
} | |
# Link to HTML file | |
/^h/ && matched == 0 { | |
print_link(green) | |
matched = 1 | |
} | |
# Blank line | |
/^\s*$/ && matched == 0 { | |
matched = 1 | |
} | |
# End of document | |
/^\.$/ && matched == 0 { | |
matched = 1 | |
} | |
# Something else | |
matched == 0 { | |
print_link(magenta) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment