Skip to content

Instantly share code, notes, and snippets.

@Gumnos
Last active February 20, 2016 03:47
Show Gist options
  • Save Gumnos/e5d1cbc947387ad0d75e to your computer and use it in GitHub Desktop.
Save Gumnos/e5d1cbc947387ad0d75e to your computer and use it in GitHub Desktop.
A rough attempt at making a Python syntax colorizer in sed
#!/bin/sed -f
# operators
#s/\<\(in\|is\)\>\|[][{}():.*\/+-]/\x1b[30;1m&\x1b[0m/g
s/\<\(in\|is\)\>/\x1b[32;1m&\x1b[0m/g
# booleans
s/\<\(and\|not\|or\)\>/\x1b[32m&\x1b[0m/g
# strings
# 36;1 = bright cyan
s/'[^']*'/\x1b[36;1m&\x1b[0m/g
s/"[^"]*"/\x1b[36;1m&\x1b[0m/g
# importing/scoping/naming
# 31 = blue
s/\<\(as\|from\|import\)\>/\x1b[31m&\x1b[0m/g
# definitions
s/\<\(class\|def\|global\|lambda\)\>/\x1b[33;1m&\x1b[0m/g
# flow-control
s/\<\(break\|continue\|elif\|else\|except\|finally\|for\|if\|raise\|return\|try\|while\|with\|yield\)\>/\x1b[1m&\x1b[0m/g
# statements
s/\<\(assert\|del\|exec\|pass\|print\)\>/\x1b[1m&\x1b[0m/g
# comments
s/#.*/\x1b[30;1m&\x1b[0m/g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment