Skip to content

Instantly share code, notes, and snippets.

@edma2
Last active August 29, 2015 14:07
Show Gist options
  • Save edma2/c63eda5e3eca28262290 to your computer and use it in GitHub Desktop.
Save edma2/c63eda5e3eca28262290 to your computer and use it in GitHub Desktop.
#!/usr/local/plan9/bin/rc
# Given a list of tags, plumb the corresponding file:line to edit.
if(test $#* -lt 1) {
echo 'usage: '$0' tag [-f tagfile] [tag...]' >[1=2]
exit usage
}
flagfmt='f tagfile'
eval `{getflags $*}
if(~ $#flagf 0)
flagf=`{git rev-parse --show-toplevel}^/.git/tags
if(! test -r $flagf) {
echo 'error: can''t read tag file ' $flagf >[1=2]
exit readtags
}
fn lookup {
look $1' ' $flagf |
awk '{printf "%s:%s\n", $2, $3}' |
sed 's/;"$//'
}
prevfile=''
for(i in $*) {
flag p +
for(a in `{lookup $i}) {
addr=`{greadlink -f `{dirname $flagf}^/^$a}
file=`{echo -n $addr | awk -F : '{print $1}'}
if(flag p) {
plumb $addr
prevfile=$file
flag p -
}
# Only plumb the first result
if not {
# Don't show the file again if plumbed
if(~ $prevfile $file);
if not echo $addr
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment