diff options
author | merakor <cem@ckyln.com> | 2020-12-27 13:38:41 +0000 |
---|---|---|
committer | merakor <cem@ckyln.com> | 2020-12-27 13:38:41 +0000 |
commit | 05b0ba223335dfa01eefcd46f0498e6a93517048 (patch) | |
tree | 91616dfad2864ec333420b7867b573875d17fc9e | |
parent | a16e20a9084843fbb8c153576420ce6ee645614e (diff) | |
download | cpt-05b0ba223335dfa01eefcd46f0498e6a93517048.tar.gz |
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
-rwxr-xr-x | src/cpt | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -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 ;; |