From 6f110d751477189601437d17a50cb28a383d5639 Mon Sep 17 00:00:00 2001 From: James Blanding Date: Wed, 6 Jan 2016 23:37:22 -0500 Subject: [PATCH 1/3] Wrap chruby_auto to ease augmentation (issue #227) --- share/chruby/auto.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/share/chruby/auto.sh b/share/chruby/auto.sh index 88f3cb34..ef9bb7c9 100644 --- a/share/chruby/auto.sh +++ b/share/chruby/auto.sh @@ -24,10 +24,14 @@ function chruby_auto() { fi } +function ruby_version_autoexec() { + chruby_auto +} + if [[ -n "$ZSH_VERSION" ]]; then - if [[ ! "$preexec_functions" == *chruby_auto* ]]; then - preexec_functions+=("chruby_auto") + if [[ ! "$preexec_functions" == *ruby_version_autoexec* ]]; then + preexec_functions+=("ruby_version_autoexec") fi elif [[ -n "$BASH_VERSION" ]]; then - trap '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto' DEBUG + trap '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && ruby_version_autoexec' DEBUG fi From def0c5b3759b0a4b3c1fc2372ae5383776c544ce Mon Sep 17 00:00:00 2001 From: James Blanding Date: Wed, 6 Jan 2016 23:45:53 -0500 Subject: [PATCH 2/3] Fix broken tests --- test/chruby_auto_test.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/chruby_auto_test.sh b/test/chruby_auto_test.sh index e48d36a2..9b67f7d1 100755 --- a/test/chruby_auto_test.sh +++ b/test/chruby_auto_test.sh @@ -7,35 +7,35 @@ function setUp() unset RUBY_AUTO_VERSION } -function test_chruby_auto_loaded_in_zsh() +function test_ruby_version_autoexec_loaded_in_zsh() { [[ -n "$ZSH_VERSION" ]] || return - assertEquals "did not add chruby_auto to preexec_functions" \ - "chruby_auto" \ + assertEquals "did not add ruby_version_autoexec to preexec_functions" \ + "ruby_version_autoexec" \ "$preexec_functions" } -function test_chruby_auto_loaded_in_bash() +function test_ruby_version_autoexec_loaded_in_bash() { [[ -n "$BASH_VERSION" ]] || return local command=". $PWD/share/chruby/auto.sh && trap -p DEBUG" local output="$("$SHELL" -c "$command")" - assertTrue "did not add a trap hook for chruby_auto" \ - '[[ "$output" == *chruby_auto* ]]' + assertTrue "did not add a trap hook for ruby_version_autoexec" \ + '[[ "$output" == *ruby_version_autoexec* ]]' } -function test_chruby_auto_loaded_twice_in_zsh() +function test_ruby_version_autoexec_loaded_twice_in_zsh() { [[ -n "$ZSH_VERSION" ]] || return . ./share/chruby/auto.sh - assertNotEquals "should not add chruby_auto twice" \ + assertNotEquals "should not add ruby_version_autoexec twice" \ "$preexec_functions" \ - "chruby_auto chruby_auto" + "ruby_version_autoexec ruby_version_autoexec" } function test_chruby_auto_loaded_twice() From d704c0df0d2ed8e9da5543c2721ce79b1a60b6c8 Mon Sep 17 00:00:00 2001 From: James Blanding Date: Thu, 7 Jan 2016 00:00:58 -0500 Subject: [PATCH 3/3] Note existance of wrapper in README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7287fe14..5b630b13 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,9 @@ https://gist.github.com/1912050 If you want to automatically run the version of a gem executable specified in your project's Gemfile, try -[rubygems-bundler](https://github.com/mpapis/rubygems-bundler). +[rubygems-bundler](https://github.com/mpapis/rubygems-bundler). If you want to +modify how and when chruby_auto is called, you may override the +`ruby_version_autoexec` shell function. ### Default Ruby