aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-12-27 13:38:41 +0000
committermerakor <cem@ckyln.com>2020-12-27 13:38:41 +0000
commit05b0ba223335dfa01eefcd46f0498e6a93517048 (patch)
tree91616dfad2864ec333420b7867b573875d17fc9e
parenta16e20a9084843fbb8c153576420ce6ee645614e (diff)
downloadcpt-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-xsrc/cpt3
1 files changed, 2 insertions, 1 deletions
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
;;