t (1010B) [raw]
1 #!/bin/sh 2 # t -- tag jumping in ed(1) 3 # 4 # core concept: 5 # we simulate a "tag stack" by recursing within ed(1). When you're done 6 # at this tag, just `q` out of there! 7 # 8 # NOTE: unfortunately, we can't get ed(1) to jump to the location within 9 # the file (without maybe some crazy hacks like using a fifo for stdin.. 10 # but even that's likely to fail). The best we can do is output the cmd 11 # to search! 12 die() { 13 echo "$*" 1>&2 14 exit 1 15 } 16 17 [ -z "$1" ] && die "usage: t TAG" 18 [ ! -e "tags" ] && die "no ./tags file" 19 20 TLINE=$(grep "^$1 " tags | head -n 1) 21 [ -z "$TLINE" ] && die "tag not found" 22 23 file=$(echo "$TLINE" | cut -f2) 24 regex=$(echo "$TLINE" | cut -f3) 25 26 # trim the universal ctags regex bits 27 # also convert it to a real regex by escaping any special chars! 28 regex=$(echo "$regex" | sed \ 29 -e 's/;"$//' \ 30 -e 's/\\/\\\\/g' \ 31 -e 's/\*/\\*/g' \ 32 -e 's/\[/\\[/g' \ 33 -e 's/\]/\\]/g' \ 34 -e 's/\./\\./g') 35 36 echo "jumping to $file, search the following:" 37 echo "$regex" 38 exec e "$file"