-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchruby-ctags
executable file
·55 lines (46 loc) · 1.13 KB
/
chruby-ctags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
set -e
shopt -s nullglob
index() {
echo " indexing $1"
(builtin cd "$1"; ctags -R --languages=ruby)
}
index_LOAD_PATH() {
local LOAD_PATH=()
if [[ -d "$1"/lib/ruby && -w "$1"/lib/ruby ]]; then
LOAD_PATH+=("$1"/lib/ruby/[0-9]*)
LOAD_PATH+=("$1"/lib/ruby/shared*)
LOAD_PATH+=("$1"/lib/ruby/site_ruby/[0-9]*)
LOAD_PATH+=("$1"/lib/ruby/vendor_ruby/[0-9]*)
elif [[ -d "$1"/lib && -w "$1"/lib ]]; then
LOAD_PATH+=("$1"/lib "$1"/site "$1"/vendor)
else
echo "No \$LOAD_PATH directories found in $1" >&2
return 1
fi
echo "Generating ctags for $1"
for dir in ${LOAD_PATH[@]}; do
[[ -d "$dir" ]] && index "$dir"
done
}
RUBIES=()
[[ -d "$PREFIX/opt/rubies/" ]] && RUBIES+=("$PREFIX"/opt/rubies/*)
[[ -d "$HOME/.rubies" ]] && RUBIES+=("$HOME"/.rubies/*)
case "$#" in
0)
for dir in ${RUBIES[@]}; do
index_LOAD_PATH "$dir"
done
;;
*)
for dir in ${RUBIES[@]}; do
[[ "${dir##*/}" == *"$1"* ]] && match="$dir"
done
if [[ -n "$match" ]]; then
index_LOAD_PATH "$match"
else
echo "Unknown Ruby: $1" >&2
exit 1
fi
;;
esac