├── CONTRIBUTING.markdown ├── etc └── rbenv.d │ └── install │ └── ctags.bash ├── MIT-LICENSE ├── README.markdown └── bin └── rbenv-ctags /CONTRIBUTING.markdown: -------------------------------------------------------------------------------- 1 | [Don't screw up the commit message.][commit messages] It's all I ask. 2 | 3 | [commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html 4 | -------------------------------------------------------------------------------- /etc/rbenv.d/install/ctags.bash: -------------------------------------------------------------------------------- 1 | if declare -Ff after_install >/dev/null; then 2 | after_install generate_ctags 3 | fi 4 | 5 | generate_ctags() { 6 | if [ "$STATUS" -eq 0 ]; then 7 | rbenv-ctags "$VERSION_NAME" 8 | fi 9 | } 10 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Tim Pope 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # Automatically generate ctags for rbenv Ruby stdlibs 2 | 3 | I've got [tags for my code base][Git Ctags]. I've got [tags for my 4 | gems][gem-ctags]. All I'm missing is tags for Ruby stdlib. Until now. 5 | 6 | ## Installation 7 | 8 | mkdir -p ~/.rbenv/plugins 9 | git clone https://github.com/tpope/rbenv-ctags.git \ 10 | ~/.rbenv/plugins/rbenv-ctags 11 | rbenv ctags 12 | 13 | You'll also need [Exuberant Ctags][]. With Homebrew, `brew install ctags`. 14 | It is imperative that you make sure the correct `ctags` binary comes first in 15 | your `$PATH`. Check `ctags --version` to verify. 16 | 17 | ## Usage 18 | 19 | Run `rbenv ctags ` to index the given version. If you are using 20 | [ruby-build][] as an rbenv plugin, this will happen automatically on install. 21 | 22 | You need to configure your editor to look for tags files in the Ruby 23 | `$LOAD_PATH`. If you're using Vim, reasonably recent versions of [vim-ruby][] 24 | (and optionally [rbenv.vim][]) take care of that for you. 25 | 26 | You might also want to use [rbenv-default-gems][] to automatically install 27 | [gem-ctags][]. Put it at the top of `~/.rbenv/default-gems` so that it 28 | indexes all gems underneath it. 29 | 30 | [Git Ctags]: http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html 31 | [gem-ctags]: https://github.com/tpope/gem-ctags 32 | [Exuberant Ctags]: http://ctags.sourceforge.net/ 33 | [ruby-build]: https://github.com/sstephenson/ruby-build 34 | [vim-ruby]: https://github.com/vim-ruby/vim-ruby 35 | [rbenv.vim]: https://github.com/tpope/vim-rbenv 36 | [rbenv-default-gems]: https://github.com/sstephenson/rbenv-default-gems 37 | -------------------------------------------------------------------------------- /bin/rbenv-ctags: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Summary: Generate ctags for a given version's standard library 4 | # 5 | # Usage: rbenv ctags 6 | # rbenv ctags [ ...] 7 | # rbenv ctags --all 8 | 9 | shopt -s nullglob 10 | 11 | # Provide rbenv completions 12 | if [ "$1" = "--complete" ]; then 13 | exec rbenv-versions --bare 14 | fi 15 | 16 | declare -a versions 17 | 18 | for arg; do 19 | case $arg in 20 | --) ;; 21 | -a|--all) 22 | all=1 23 | ;; 24 | -*) 25 | rbenv-help --usage ctags >&2 26 | exit 1 27 | ;; 28 | *) 29 | versions["${#versions[@]}"]="$arg" 30 | ;; 31 | esac 32 | done 33 | 34 | generate_ctags_in() { 35 | local tags_file_dir="$1" 36 | local languages="${2:-Ruby}" 37 | local source_code_dir="${3:-$tags_file_dir}" 38 | echo "Running ctags on $source_code_dir" 39 | (cd "$tags_file_dir"; ctags --languages="$languages" -R --tag-relative=yes "$source_code_dir") 40 | } 41 | 42 | generate_ctags_for() { 43 | local prefix=$(rbenv-prefix "$1") 44 | [ -n "$prefix" ] || return 1 45 | if [ -w "$prefix/lib/ruby" ]; then 46 | for dir in \ 47 | "$prefix"/lib/ruby/[0-9]* \ 48 | "$prefix"/lib/ruby/shared* 49 | do 50 | generate_ctags_in "$dir" 51 | done 52 | for dir in \ 53 | "$prefix"/lib/ruby/site_ruby/[0-9]* \ 54 | "$prefix"/lib/ruby/vendor_ruby/[0-9]* 55 | do 56 | [ "$(find "$dir" -name '*.rb'|wc -l)" = 0 ] || generate_ctags_in "$dir" 57 | done 58 | elif [ -w "$prefix/lib" ]; then 59 | generate_ctags_in "$prefix/lib" 60 | else 61 | echo "No directories for ctags found in $prefix" >&2 62 | return 1 63 | fi 64 | 65 | local ruby_include_dir="$(RBENV_VERSION=$version rbenv-exec ruby -rrbconfig -e 'print RbConfig::CONFIG["rubyhdrdir"] || RbConfig::CONFIG["topdir"]')" 66 | if [ -w "$ruby_include_dir" ]; then 67 | generate_ctags_in "$ruby_include_dir" "C,C++" "${RUBY_BUILD_BUILD_PATH:-$ruby_include_dir}" 68 | else 69 | echo "No Ruby include directory for ctags found in $prefix" >&2 70 | return 1 71 | fi 72 | } 73 | 74 | if [ -n "$all" ]; then 75 | for version in $(rbenv-versions --bare); do 76 | [ -L "$(rbenv-prefix "$version")" ] || \ 77 | generate_ctags_for "$version" 78 | done 79 | elif [ ${#versions[@]} -eq 0 ]; then 80 | generate_ctags_for "$(rbenv-version-name)" 81 | else 82 | code=0 83 | for version in "${versions[@]}"; do 84 | generate_ctags_for "$version" || code=1 85 | done 86 | exit "$code" 87 | fi 88 | --------------------------------------------------------------------------------