#!/bin/sh # t -- tag jumping in ed(1) # # core concept: # we simulate a "tag stack" by recursing within ed(1). When you're done # at this tag, just `q` out of there! # # NOTE: unfortunately, we can't get ed(1) to jump to the location within # the file (without maybe some crazy hacks like using a fifo for stdin.. # but even that's likely to fail). The best we can do is output the cmd # to search! die() { echo "$*" 1>&2 exit 1 } [ -z "$1" ] && die "usage: t TAG" [ ! -e "tags" ] && die "no ./tags file" TLINE=$(grep "^$1 " tags | head -n 1) [ -z "$TLINE" ] && die "tag not found" file=$(echo "$TLINE" | cut -f2) regex=$(echo "$TLINE" | cut -f3) # trim the universal ctags regex bits # also convert it to a real regex by escaping any special chars! regex=$(echo "$regex" | sed \ -e 's/;"$//' \ -e 's/\\/\\\\/g' \ -e 's/\*/\\*/g' \ -e 's/\[/\\[/g' \ -e 's/\]/\\]/g' \ -e 's/\./\\./g') echo "jumping to $file, search the following:" echo "$regex" exec e "$file"