33 lines
919 B
Bash
33 lines
919 B
Bash
#!/usr/bin/env bash
|
|
|
|
# Displays a list of the tags
|
|
#
|
|
# $2 if "-n", tags will be sorted by number of posts
|
|
declare prefix_tags
|
|
declare template_tags_posts_singular
|
|
declare template_tags_posts
|
|
list_tags() {
|
|
if [[ $2 == -n ]]; then do_sort=1; else do_sort=0; fi
|
|
|
|
if ls "./${prefix_tags}"*.html > /dev/null; then
|
|
echo "No posts yet. Use '$0 post' to create one" && return
|
|
fi
|
|
|
|
lines=""
|
|
for i in "./${prefix_tags}"*.html; do
|
|
[[ -f "$i" ]] || break
|
|
nposts=$(grep -c "<\!-- text begin -->" "$i")
|
|
tagname=${i#"$prefix_tags"}
|
|
tagname=${tagname#.html}
|
|
((nposts > 1)) && word=$template_tags_posts || word=$template_tags_posts_singular
|
|
line="$tagname # $nposts # $word"
|
|
lines+=$line\\n
|
|
done
|
|
|
|
if ((do_sort == 1)); then
|
|
echo -e "$lines" | column -t -s "#" | sort -nrk 2
|
|
else
|
|
echo -e "$lines" | column -t -s "#"
|
|
fi
|
|
}
|