diff --git a/colorize.py b/colorize.py deleted file mode 100644 index 5f95399..0000000 --- a/colorize.py +++ /dev/null @@ -1,21 +0,0 @@ -import sys -import termcolor -import re - -def colorize(line, pattern, color=None, attrs=None): - if (match := re.search(f"({pattern})", line)): - return re.sub(pattern, termcolor.colored(match[0], color, attrs=attrs), line) - return line - -for line in sys.stdin: - line = colorize(line, "^ C[\w]*", "green") - line = colorize(line, "^ ZSTD", "green") - line = colorize(line, "^ SIGN", "cyan") - line = colorize(line, "^ INSTALL", "yellow") - line = colorize(line, "^ LD", "yellow") - line = colorize(line, " \[M\] ", "magenta") - line = colorize(line, "[\w/-]+\.k?o", attrs=["bold"]) - line = colorize(line, "^#(.*)", "cyan") - line = colorize(line, "^Kernel(.*)$", attrs=["bold"]) - - print(line, end="") diff --git a/colors/make.py b/colors/make.py new file mode 100644 index 0000000..224ed12 --- /dev/null +++ b/colors/make.py @@ -0,0 +1,34 @@ +import sys +import os +import termcolor +import re + +make_colors = dict() +make_attrs = dict() + +def add_color_attr(field, color, *attrs): + make_colors[field] = color + make_attrs[field] = attrs + +add_color_attr("Kernel:", "blue", "bold") +add_color_attr("is", "blue", "bold") +add_color_attr("ready", "blue", "bold") +add_color_attr("CC", "cyan", "bold") +add_color_attr("[M]", "magenta", "bold") +add_color_attr("MODPOST", "magenta", "bold") +add_color_attr("DESCEND", "white", "dark") +add_color_attr("objtool", "yellow", "dark", "bold") +add_color_attr("LD", "yellow") + +for line in sys.stdin: + if line[0] == "#": + termcolor.cprint(line, "blue", attrs=["dark", "bold"], end="") + else: + for part in re.split(r'(\s+)', line): + if "/" in part or "(#" in part or os.path.exists(part): + color = "magenta" if re.match("module", part, re.I) else "white" + attrs = ["bold"] + else: + color = make_colors.get(part, "green") + attrs = make_attrs.get(part, []) + termcolor.cprint(part, color, attrs=attrs, end="") diff --git a/completions/_makelinux.zsh b/completions/_makelinux.zsh new file mode 100644 index 0000000..2cab7fc --- /dev/null +++ b/completions/_makelinux.zsh @@ -0,0 +1,7 @@ +#compdef makelinux.zsh + +function _makelinux.zsh() { + _arguments '*: :_make' +} + +_makelinux.zsh "$@" diff --git a/makelinux.zsh b/makelinux.zsh index b2d1db0..f0d4310 100755 --- a/makelinux.zsh +++ b/makelinux.zsh @@ -2,4 +2,4 @@ set -eo pipefail let jobs=$(nproc)-2 -make -j$jobs $* | python /home/anna/bin/colorize.py +make -j$jobs $* | python /home/anna/bin/colors/make.py