Improve colorizing the makelinux.zsh command and add completions
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
parent
730d42ee7f
commit
f3f1ed1709
21
colorize.py
21
colorize.py
|
@ -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="")
|
|
@ -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="")
|
|
@ -0,0 +1,7 @@
|
|||
#compdef makelinux.zsh
|
||||
|
||||
function _makelinux.zsh() {
|
||||
_arguments '*: :_make'
|
||||
}
|
||||
|
||||
_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
|
||||
|
|
Loading…
Reference in New Issue