dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

commit 6d392f1a8958a4d6c2393ce5d494c5a119a1039b (patch)
parent 2607280d1f0f8dce4643a768f9bea7d3a451c7cc
Author: Alex Karle <alex@alexkarle.com>
Date:   Mon, 23 Aug 2021 22:34:23 -0400

bin: Add t, a small tag-jumping tool for ed(1)

I like to mess around in ed(1) in my free time. I've always thought
adapting to the environment was a fun challenge (although maybe it's
a fools errand). Either way, tag-jumping is incredibly useful for
navigating a new codebase. This new script is a step closer to that!

usage:

	$ e
	... view code
	> !t main
	jumping to main.c, search the following:
	/^main(volatile int argc, char \*\* volatile argv)$/
	> /^main(volatile int argc, char \*\* volatile argv)$/
	main(volatile int argc, char ** volatile argv)
	... view code
	> q
	... back where we started!

Diffstat:
Abin/t | 38++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/bin/t b/bin/t @@ -0,0 +1,38 @@ +#!/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"