alexkarle.com

Source for alexkarle.com
git clone git://git.alexkarle.com/alexkarle.com.git
Log | Files | Refs | README | LICENSE

notetag (1115B) [raw]


      1 #!/bin/sh
      2 # notetag -- small program to sort notes into tagged dirs
      3 set -e
      4 die() {
      5     echo "$*" 1>&2
      6     exit 1
      7 }
      8 
      9 [ -d all ] || die "ERROR: unable to find the 'all' notes directory; check cwd"
     10 
     11 # clean up old directories
     12 for d in */; do
     13     [ "$d" != "all/" ] && rm -r "$d"
     14 done
     15 
     16 for f in all/*; do
     17     tags=$(grep '^tags:' "$f" | sed 's/tags: //')
     18     tags=${tags:-misc}
     19     for t in $tags; do
     20         mkdir -p "$t"
     21         (cd "$t" && ln -sf "../$f")
     22     done
     23 done
     24 
     25 cat <<'EOM'
     26 my technical
     27               __
     28              /\ \__
     29   ___     ___\ \ ,_\    __    ____
     30 /' _ `\  / __`\ \ \/  /'__`\ /',__\
     31 /\ \/\ \/\ \L\ \ \ \_/\  __//\__, `\
     32 \ \_\ \_\ \____/\ \__\ \____\/\____/
     33  \/_/\/_/\/___/  \/__/\/____/\/___/
     34 
     35 No warranty / use at your own risk!
     36 
     37 
     38 
     39 EOM
     40 
     41 for tag in */; do
     42     count="$(ls "$tag" | wc -l | sed 's/^[[:space:]]*//')"
     43     if [ "$count" = "1" ]; then
     44         printf "[1| %-24s  %4s note)|%s|server|port]\n" "$tag" "($count" "$tag"
     45     else
     46         printf "[1| %-24s %4s notes)|%s|server|port]\n" "$tag" "($count" "$tag"
     47     fi
     48 done
     49 
     50 cat <<EOM
     51 
     52 
     53 [1|<-- Home|/|server|port]
     54 
     55 Last Updated: $(date)
     56 EOM