From 05b0ba223335dfa01eefcd46f0498e6a93517048 Mon Sep 17 00:00:00 2001 From: merakor Date: Sun, 27 Dec 2020 13:38:41 +0000 Subject: cpt: print docstrings using awk instead of sed Using awk, we can achieve the following things: - Ignore the rest of the file (2 times faster than sed) - If the line doesn't match the docstring pattern, we can just print a newline instead. I am not exactly really familiar with awk scripting so there might be a better way of doing this. In that case please send a patch and I will apply it. FossilOrigin-Name: bf65db74ad6552bb374f3535ef2a5333bbc0dc3d20563ec37e821036e07f621f --- src/cpt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/cpt b/src/cpt index c72d39d..ee4a328 100755 --- a/src/cpt +++ b/src/cpt @@ -17,7 +17,8 @@ case "$arg" in for path; do printf "%b->%b %-${max}s " "$colorb" "$colre" "${path#*/cpt-}" - sed -n 's/^# *//;2p' "$(command -v "cpt-$path")" + awk 'NR==2{if(/^# /){sub(/^# */,"");print}else print "";exit}' \ + "$(command -v "cpt-$path")" done | sort -uk1 >&2 exit ;; -- cgit v1.2.3