Skip to content

Instantly share code, notes, and snippets.

@isao
Last active May 25, 2021 20:33
Show Gist options
  • Save isao/f26aaedd770350117fa3 to your computer and use it in GitHub Desktop.
Save isao/f26aaedd770350117fa3 to your computer and use it in GitHub Desktop.
ctags
#!/bin/bash -e
# Wrapper script to do BBEdit compatible ctags when invoked by any of the these:
# 1. from the command line
# 2. from a BBEdit Script Menu
# 3. from a .git/hooks file like post-checkout or post-merge
maketags()
{
cd "$dir"
logger "ctags $language $excludes $ctagflags $*"
ctags $language $excludes $ctagflags $@
}
alert()
{
osascript -e "display notification \"$dir\" with title \"ctags: $1\""
}
# Handle invocation from BBEdit Script Menu
[[ -n $BB_DOC_PATH ]] && cd "$(dirname "$BB_DOC_PATH")"
# Always
ctagflags='--excmd=number --tag-relative=no --fields=+a+m+n+S --recurse'
# Defaults
language=''
excludes='--exclude=node_modules --exclude=.git'
dir="$(git rev-parse --show-toplevel 2>/dev/null)"
# special case for MRGIT
[[ $(git remote -v 2>/dev/null) =~ /MRGIT/_git/ReachClient ]] && {
dir="$dir/Web/scripts"
language='--languages=typescript'
excludes="$excludes --exclude=OPEN_SOURCE_SOFTWARE --exclude=napa"
}
# pass through any args if not run as a git hook
if [[ -n $GIT_DIR ]]
then
args=''
else
args=$*
fi
# main
(maketags $args && alert "$(basename "$0")") &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment