From 19c1fb5f6aea0b91d568b31808ad780d0957f643 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Tue, 29 Oct 2019 18:24:13 -0700 Subject: [PATCH 01/52] Version bump to 1.0.0. --- Makefile | 2 +- share/chruby/chruby.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c8502798..f22e5cf9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NAME=chruby -VERSION=0.3.9 +VERSION=1.0.0 AUTHOR=postmodern URL=https://github.com/$(AUTHOR)/$(NAME) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 7b2b4895..6f4cf7b1 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -1,4 +1,4 @@ -CHRUBY_VERSION="0.3.9" +CHRUBY_VERSION="1.0.0" RUBIES=() for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do From fbfc551a01795ec0f382ba7a41bf62095e5d7e02 Mon Sep 17 00:00:00 2001 From: Shannon Skipper Date: Tue, 15 Jan 2013 14:55:24 -0800 Subject: [PATCH 02/52] updated formatting and env descriptions * Pulled in @HavenWood's chruby man page. --- docs/chruby.1 | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ docs/chruby.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 docs/chruby.1 create mode 100644 docs/chruby.md diff --git a/docs/chruby.1 b/docs/chruby.1 new file mode 100644 index 00000000..ca52536a --- /dev/null +++ b/docs/chruby.1 @@ -0,0 +1,94 @@ +.TH +.BR chruby (1) +\-\- Changes the current Ruby. +.SH SYNOPSIS +.PP +\fB\fCchruby\fR [] [] +.SH ARGUMENTS +.PP +\fIRUBY|VERSION\fP + Change current Ruby based on fuzzy matching of Ruby by name. +.PP +\fIsystem\fP + Change current Ruby to system Ruby. +.PP +\fIRUBY_OPTS\fP + Additional optional arguements to pass to Ruby. +.SH OPTIONS +.PP +\fB\fC-h\fR, \fB\fC--help\fR +.SH DESCRIPTION +.PP +Changes the current Ruby version by correctly setting the appropriate environment variables. +.PP +https://github.com/postmodern/chruby/blob/master/README.md +.UR https://github.com/postmodern/chruby/blob/master/README.md +.UE +.SH EXAMPLES +.PP +List available Rubies: + $ chruby + ruby\-1.9.3\-p362 + jruby\-1.7.2 + rubinius\-2.0.0\-rc1 +.PP +Select a Ruby: + $ chruby 1.9.3 + $ chruby + * ruby\-1.9.3\-p362 + jruby\-1.7.2 + rubinius\-2.0.0\-rc1 +.PP +Switch to JRuby in 1.9 mode: + $ chruby jruby \-\-1.9 +.PP +Switch back to system Ruby: + $ chruby system +.PP +Switch to an arbitrary Ruby on the fly: + $ chruby_use /path/to/ruby +.SH FILES +.PP +\fI/opt/rubies\fP + Primary default Ruby install location. +.PP +\fI~/.rubies/\fP + Secondary default Ruby install location. +.PP +\fI/etc/profile.d/chruby.sh\fP + Application environment settings for chruby. +.PP +\fI~/.gem/$ruby/$version\fP + Default gem install location. +.SH ENVIRONMENT +.PP +\fIPATH\fP + Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. +.PP +\fIGEM_HOME\fP + Default repository location for gem installation. +.PP +\fIGEM_PATH\fP + A colon\-separated list of gem repository directories. +.PP +\fIGEM_ROOT\fP +.PP +\fIRUBY_ROOT\fP +.PP +\fIRUBY_ENGINE\fP + Name of Ruby implementation. +.PP +\fIRUBY_VERSION\fP + Ruby version number. +.PP +\fIRUBYOPT\fP + Optionally set if additional Ruby options are given. +.SH AUTHOR +.PP +Postmodern postmodern.mod3\@gmail.com +.MT postmodern.mod3@gmail.com +.ME . +.SH SEE ALSO +.PP +.BR ruby (1), +.BR gem (1) \ No newline at end of file diff --git a/docs/chruby.md b/docs/chruby.md new file mode 100644 index 00000000..18352780 --- /dev/null +++ b/docs/chruby.md @@ -0,0 +1,93 @@ +# chruby(1) -- Changes the current Ruby. + +## SYNOPSIS + +`chruby` [] [] + +## ARGUMENTS + +*RUBY|VERSION* + Change current Ruby based on fuzzy matching of Ruby by name. + +*system* + Change current Ruby to system Ruby. + +*RUBY_OPTS* + Additional optional arguements to pass to Ruby. + +## OPTIONS + +`-h`, `--help` + +## DESCRIPTION +Changes the current Ruby version by correctly setting the appropriate environment variables. + +[https://github.com/postmodern/chruby/blob/master/README.md](https://github.com/postmodern/chruby/blob/master/README.md) + +## EXAMPLES + +List available Rubies: + $ chruby + ruby-1.9.3-p362 + jruby-1.7.2 + rubinius-2.0.0-rc1 + +Select a Ruby: + $ chruby 1.9.3 + $ chruby + * ruby-1.9.3-p362 + jruby-1.7.2 + rubinius-2.0.0-rc1 + +Switch to JRuby in 1.9 mode: + $ chruby jruby --1.9 + +Switch back to system Ruby: + $ chruby system + +Switch to an arbitrary Ruby on the fly: + $ chruby_use /path/to/ruby + +##FILES + +*/opt/rubies* + Primary default Ruby install location. + +*~/.rubies/* + Secondary default Ruby install location. + +*/etc/profile.d/chruby.sh* + Application environment settings for chruby. + +*~/.gem/$ruby/$version* + Default gem install location. + +##ENVIRONMENT + +*PATH* + Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. + +*GEM_HOME* + Default repository location for gem installation. + +*GEM_PATH* + A colon-separated list of gem repository directories. + +*GEM_ROOT* + +*RUBY_ROOT* + +*RUBY_ENGINE* + Name of Ruby implementation. + +*RUBY_VERSION* + Ruby version number. + +*RUBYOPT* + Optionally set if additional Ruby options are given. + +##AUTHOR +Postmodern [postmodern.mod3\@gmail.com](mailto:postmodern.mod3\@gmail.com). + +##SEE ALSO +ruby(1), gem(1) \ No newline at end of file From d51fcdc948acf2070a2bb5ff7d24d9e388b12f99 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Tue, 15 Jan 2013 15:21:40 -0800 Subject: [PATCH 03/52] Renamed chruby.md to chruby.1.md. --- docs/chruby.md => doc/man/chruby.1.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/chruby.md => doc/man/chruby.1.md (100%) diff --git a/docs/chruby.md b/doc/man/chruby.1.md similarity index 100% rename from docs/chruby.md rename to doc/man/chruby.1.md From a88a1c4f9977a9b52e6cdd22ab1d3d08cc80d6db Mon Sep 17 00:00:00 2001 From: Postmodern Date: Tue, 15 Jan 2013 15:24:39 -0800 Subject: [PATCH 04/52] Moved docs/chruby.1 into share/man/man1/ --- {docs => share/man/man1}/chruby.1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {docs => share/man/man1}/chruby.1 (100%) diff --git a/docs/chruby.1 b/share/man/man1/chruby.1 similarity index 100% rename from docs/chruby.1 rename to share/man/man1/chruby.1 From 0600f2ccee2b282babed3475f33d43930b893c87 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Tue, 15 Jan 2013 15:26:41 -0800 Subject: [PATCH 05/52] Added a basic man page task. --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f22e5cf9..69c5951a 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,12 @@ all: pkg: mkdir $(PKG_DIR) +share/man/man1/chruby.1: doc/man/chruby.1.md + md2man doc/man/chruby.1.md > share/man/man1/chruby.1 + +man: share/man/man1/chruby.1 + git commit -m "Updated the man pages" doc/man/chruby.1.md share/man/man1/chruby.1 + download: pkg wget -O $(PKG) $(URL)/archive/v$(VERSION).tar.gz @@ -80,4 +86,4 @@ uninstall: rm -rf $(DESTDIR)$(PREFIX)/$(DOC_DIR) rmdir $(DESTDIR)$(PREFIX)/$(SHARE_DIR)/chruby -.PHONY: build download sign verify clean check configure_tests test integration_tests gauntlet tag release rpm install uninstall all +.PHONY: build man download sign verify clean check configure_tests test integration_tests gauntlet tag release rpm install uninstall all From 808705599a25a925e28bf77dd6781b04500f6727 Mon Sep 17 00:00:00 2001 From: Shannon Skipper Date: Mon, 11 Feb 2013 18:14:05 -0800 Subject: [PATCH 06/52] added -v, --version to OPTIONS --- doc/man/chruby.1.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/man/chruby.1.md b/doc/man/chruby.1.md index 18352780..a5ed6b5d 100644 --- a/doc/man/chruby.1.md +++ b/doc/man/chruby.1.md @@ -19,6 +19,8 @@ `-h`, `--help` +`-v`, `--version` + ## DESCRIPTION Changes the current Ruby version by correctly setting the appropriate environment variables. @@ -90,4 +92,4 @@ Switch to an arbitrary Ruby on the fly: Postmodern [postmodern.mod3\@gmail.com](mailto:postmodern.mod3\@gmail.com). ##SEE ALSO -ruby(1), gem(1) \ No newline at end of file +ruby(1), gem(1) From 7ce877c34bf305995557ca428228f8dc17f97bb9 Mon Sep 17 00:00:00 2001 From: havenwood Date: Sun, 31 Mar 2013 13:13:24 -0700 Subject: [PATCH 07/52] Added chruby-exec(1) manpage to See Also section. --- doc/man/chruby.1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/man/chruby.1.md b/doc/man/chruby.1.md index a5ed6b5d..653d5481 100644 --- a/doc/man/chruby.1.md +++ b/doc/man/chruby.1.md @@ -92,4 +92,4 @@ Switch to an arbitrary Ruby on the fly: Postmodern [postmodern.mod3\@gmail.com](mailto:postmodern.mod3\@gmail.com). ##SEE ALSO -ruby(1), gem(1) +chruby-exec(1), ruby(1), gem(1) From 8976d1a9e33ef8ef6c413257c1829658aca6346b Mon Sep 17 00:00:00 2001 From: havenwood Date: Sun, 31 Mar 2013 13:14:06 -0700 Subject: [PATCH 08/52] initial commit --- doc/man/chruby-exec.1.md | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 doc/man/chruby-exec.1.md diff --git a/doc/man/chruby-exec.1.md b/doc/man/chruby-exec.1.md new file mode 100644 index 00000000..1146ab00 --- /dev/null +++ b/doc/man/chruby-exec.1.md @@ -0,0 +1,76 @@ +# chruby-exec(1) -- Run a command with selected Ruby. + +## SYNOPSIS + +`chruby-exec` RUBY [RUBYOPTS] -- COMMAND + +## ARGUMENTS + +*RUBY* + Change current Ruby based on fuzzy matching of Ruby by name. + +*RUBYOPTS* + Additional optional arguements to pass to Ruby. + +*COMMAND* + Command to run under the selected Ruby. + +## OPTIONS + +`-h`, `--help` + +`-v`, `--version` + +## DESCRIPTION +Run a command with the selected Ruby version by correctly setting the appropriate environment variables. + +[https://github.com/postmodern/chruby/blob/master/README.md](https://github.com/postmodern/chruby/blob/master/README.md) + +## EXAMPLES + +Run the command `gem update` under JRuby: + $ chruby-exec jruby -- gem update + +##FILES + +*/opt/rubies* + Primary default Ruby install location. + +*~/.rubies/* + Secondary default Ruby install location. + +*/etc/profile.d/chruby.sh* + Application environment settings for chruby. + +*~/.gem/$ruby/$version* + Default gem install location. + +##ENVIRONMENT + +*PATH* + Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. + +*GEM_HOME* + Default repository location for gem installation. + +*GEM_PATH* + A colon-separated list of gem repository directories. + +*GEM_ROOT* + +*RUBY_ROOT* + +*RUBY_ENGINE* + Name of Ruby implementation. + +*RUBY_VERSION* + Ruby version number. + +*RUBYOPT* + Optionally set if additional Ruby options are given. + +##AUTHOR +Postmodern [postmodern.mod3\@gmail.com](mailto:postmodern.mod3\@gmail.com). + +##SEE ALSO +chruby(1), ruby(1), gem(1) From 24a286c0da5ac415f6f0eeffaf72249d04142cb6 Mon Sep 17 00:00:00 2001 From: havenwood Date: Sun, 31 Mar 2013 13:30:02 -0700 Subject: [PATCH 09/52] initial commit --- share/man/man1/chruby-exec.1 | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 share/man/man1/chruby-exec.1 diff --git a/share/man/man1/chruby-exec.1 b/share/man/man1/chruby-exec.1 new file mode 100644 index 00000000..47704d2f --- /dev/null +++ b/share/man/man1/chruby-exec.1 @@ -0,0 +1,78 @@ +.TH +.BR chruby-exec (1) +\-\- Run a command with selected Ruby. +.SH SYNOPSIS +.PP +\fB\fCchruby-exec\fR RUBY [RUBYOPTS] \-\- COMMAND +.SH ARGUMENTS +.PP +\fIRUBY\fP + Change current Ruby based on fuzzy matching of Ruby by name. +.PP +\fIRUBYOPTS\fP + Additional optional arguements to pass to Ruby. +.PP +\fICOMMAND\fP + Command to run under the selected Ruby. +.SH OPTIONS +.PP +\fB\fC-h\fR, \fB\fC--help\fR +.PP +\fB\fC-v\fR, \fB\fC--version\fR +.SH DESCRIPTION +.PP +Run a command with the selected Ruby version by correctly setting the appropriate environment variables. +.PP +https://github.com/postmodern/chruby/blob/master/README.md +.UR https://github.com/postmodern/chruby/blob/master/README.md +.UE +.SH EXAMPLES +.PP +Run the command \fB\fCgem update\fR under JRuby: + $ chruby\-exec jruby \-\- gem update +.SH FILES +.PP +\fI/opt/rubies\fP + Primary default Ruby install location. +.PP +\fI~/.rubies/\fP + Secondary default Ruby install location. +.PP +\fI/etc/profile.d/chruby.sh\fP + Application environment settings for chruby. +.PP +\fI~/.gem/$ruby/$version\fP + Default gem install location. +.SH ENVIRONMENT +.PP +\fIPATH\fP + Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. +.PP +\fIGEM_HOME\fP + Default repository location for gem installation. +.PP +\fIGEM_PATH\fP + A colon\-separated list of gem repository directories. +.PP +\fIGEM_ROOT\fP +.PP +\fIRUBY_ROOT\fP +.PP +\fIRUBY_ENGINE\fP + Name of Ruby implementation. +.PP +\fIRUBY_VERSION\fP + Ruby version number. +.PP +\fIRUBYOPT\fP + Optionally set if additional Ruby options are given. +.SH AUTHOR +.PP +Postmodern postmodern.mod3\@gmail.com +.MT postmodern.mod3@gmail.com +.ME . +.SH SEE ALSO +.PP +.BR chruby (1), +.BR ruby (1), +.BR gem (1) \ No newline at end of file From 531884b795624e9d7eb7221d0a2d701e2a8bdc31 Mon Sep 17 00:00:00 2001 From: havenwood Date: Sun, 31 Mar 2013 13:51:23 -0700 Subject: [PATCH 10/52] Added chruby-exec(1) duplicates of chruby(1) entries. --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 69c5951a..48de80b4 100644 --- a/Makefile +++ b/Makefile @@ -25,9 +25,15 @@ pkg: share/man/man1/chruby.1: doc/man/chruby.1.md md2man doc/man/chruby.1.md > share/man/man1/chruby.1 +share/man/man1/chruby-exec.1: doc/man/chruby-exec.1.md + md2man doc/man/chruby-exec.1.md > share/man/man1/chruby-exec.1 + man: share/man/man1/chruby.1 git commit -m "Updated the man pages" doc/man/chruby.1.md share/man/man1/chruby.1 +man: share/man/man1/chruby-exec.1 + git commit -m "Updated the man pages" doc/man/chruby-exec.1.md share/man/man1/chruby-exec.1 + download: pkg wget -O $(PKG) $(URL)/archive/v$(VERSION).tar.gz From 11704d07f0010c3f08836c018567bcb24d47838e Mon Sep 17 00:00:00 2001 From: Postmodern Date: Mon, 6 May 2013 18:31:01 -0700 Subject: [PATCH 11/52] Use kramdown-man (https://github.com/postmodern/kramdown-man). --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 48de80b4..a1a643bf 100644 --- a/Makefile +++ b/Makefile @@ -23,10 +23,10 @@ pkg: mkdir $(PKG_DIR) share/man/man1/chruby.1: doc/man/chruby.1.md - md2man doc/man/chruby.1.md > share/man/man1/chruby.1 + kramdown-man share/man/man1/chruby.1 share/man/man1/chruby-exec.1: doc/man/chruby-exec.1.md - md2man doc/man/chruby-exec.1.md > share/man/man1/chruby-exec.1 + kramdown-man share/man/man1/chruby-exec.1 man: share/man/man1/chruby.1 git commit -m "Updated the man pages" doc/man/chruby.1.md share/man/man1/chruby.1 From fe6e55c5f8e50b90bcee3853899959b9761a0b4c Mon Sep 17 00:00:00 2001 From: Shannon Skipper Date: Fri, 14 Jun 2013 18:38:29 -0600 Subject: [PATCH 12/52] Correct spelling typo. --- doc/man/chruby.1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/man/chruby.1.md b/doc/man/chruby.1.md index 653d5481..fb1e7631 100644 --- a/doc/man/chruby.1.md +++ b/doc/man/chruby.1.md @@ -13,7 +13,7 @@ Change current Ruby to system Ruby. *RUBY_OPTS* - Additional optional arguements to pass to Ruby. + Additional optional arguments to pass to Ruby. ## OPTIONS From d4f157e73f285e317f590bd81c30edf331ac149f Mon Sep 17 00:00:00 2001 From: Shannon Skipper Date: Fri, 14 Jun 2013 18:42:15 -0600 Subject: [PATCH 13/52] Correct spelling typo. --- doc/man/chruby-exec.1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/man/chruby-exec.1.md b/doc/man/chruby-exec.1.md index 1146ab00..fa25af93 100644 --- a/doc/man/chruby-exec.1.md +++ b/doc/man/chruby-exec.1.md @@ -10,7 +10,7 @@ Change current Ruby based on fuzzy matching of Ruby by name. *RUBYOPTS* - Additional optional arguements to pass to Ruby. + Additional optional arguments to pass to Ruby. *COMMAND* Command to run under the selected Ruby. From d527ff0a1984d62b0c8740832f4264a21c5a65bc Mon Sep 17 00:00:00 2001 From: Postmodern Date: Thu, 21 Nov 2019 20:28:17 -0800 Subject: [PATCH 14/52] Combined `man` tasks. --- Makefile | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a1a643bf..800d1e31 100644 --- a/Makefile +++ b/Makefile @@ -28,11 +28,8 @@ share/man/man1/chruby.1: doc/man/chruby.1.md share/man/man1/chruby-exec.1: doc/man/chruby-exec.1.md kramdown-man share/man/man1/chruby-exec.1 -man: share/man/man1/chruby.1 - git commit -m "Updated the man pages" doc/man/chruby.1.md share/man/man1/chruby.1 - -man: share/man/man1/chruby-exec.1 - git commit -m "Updated the man pages" doc/man/chruby-exec.1.md share/man/man1/chruby-exec.1 +man: share/man/man1/chruby.1 share/man/man1/chruby-exec.1 + git commit -m "Updated the man pages" doc/man/chruby.1.md share/man/man1/chruby.1 doc/man/chruby-exec.1.md share/man/man1/chruby-exec.1 download: pkg wget -O $(PKG) $(URL)/archive/v$(VERSION).tar.gz From 8af032e58c32b8a7db57b20401d44c7e27b01810 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Thu, 21 Nov 2019 20:28:37 -0800 Subject: [PATCH 15/52] Renamed the `man` task to `update-man`. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 800d1e31..84ce578b 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ share/man/man1/chruby.1: doc/man/chruby.1.md share/man/man1/chruby-exec.1: doc/man/chruby-exec.1.md kramdown-man share/man/man1/chruby-exec.1 -man: share/man/man1/chruby.1 share/man/man1/chruby-exec.1 +update-man: share/man/man1/chruby.1 share/man/man1/chruby-exec.1 git commit -m "Updated the man pages" doc/man/chruby.1.md share/man/man1/chruby.1 doc/man/chruby-exec.1.md share/man/man1/chruby-exec.1 download: pkg From 8345e48993999db511c3c61da4bf1c7fdb631c27 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Thu, 21 Nov 2019 20:32:59 -0800 Subject: [PATCH 16/52] Markdown formatting. --- doc/man/chruby-exec.1.md | 8 ++++---- doc/man/chruby.1.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/man/chruby-exec.1.md b/doc/man/chruby-exec.1.md index fa25af93..a06cd4fd 100644 --- a/doc/man/chruby-exec.1.md +++ b/doc/man/chruby-exec.1.md @@ -31,7 +31,7 @@ Run a command with the selected Ruby version by correctly setting the appropriat Run the command `gem update` under JRuby: $ chruby-exec jruby -- gem update -##FILES +## FILES */opt/rubies* Primary default Ruby install location. @@ -45,7 +45,7 @@ Run the command `gem update` under JRuby: *~/.gem/$ruby/$version* Default gem install location. -##ENVIRONMENT +## ENVIRONMENT *PATH* Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. @@ -69,8 +69,8 @@ Run the command `gem update` under JRuby: *RUBYOPT* Optionally set if additional Ruby options are given. -##AUTHOR +## AUTHOR Postmodern [postmodern.mod3\@gmail.com](mailto:postmodern.mod3\@gmail.com). -##SEE ALSO +## SEE ALSO chruby(1), ruby(1), gem(1) diff --git a/doc/man/chruby.1.md b/doc/man/chruby.1.md index fb1e7631..61bc77c1 100644 --- a/doc/man/chruby.1.md +++ b/doc/man/chruby.1.md @@ -50,7 +50,7 @@ Switch back to system Ruby: Switch to an arbitrary Ruby on the fly: $ chruby_use /path/to/ruby -##FILES +## FILES */opt/rubies* Primary default Ruby install location. @@ -64,7 +64,7 @@ Switch to an arbitrary Ruby on the fly: *~/.gem/$ruby/$version* Default gem install location. -##ENVIRONMENT +## ENVIRONMENT *PATH* Updates the PATH environment variable to include Rubies and RubyGems bin/ directories. @@ -88,8 +88,8 @@ Switch to an arbitrary Ruby on the fly: *RUBYOPT* Optionally set if additional Ruby options are given. -##AUTHOR +## AUTHOR Postmodern [postmodern.mod3\@gmail.com](mailto:postmodern.mod3\@gmail.com). -##SEE ALSO +## SEE ALSO chruby-exec(1), ruby(1), gem(1) From 1ade2eea0f56436e70286759247ae53ebe19ae31 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Sun, 20 Sep 2020 22:28:25 -0700 Subject: [PATCH 17/52] Extracted the chruby ruby matching logic into chruby_find(). * This will allow overriding the default ruby matching logic with custom searching algorithms. --- share/chruby/chruby.sh | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 6f4cf7b1..56f26b4f 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -6,6 +6,21 @@ for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do done unset dir +function chruby_find() +{ + local dir ruby match + + for dir in "${RUBIES[@]}"; do + dir="${dir%%/}"; ruby="${dir##*/}" + case "$ruby" in + "$1") match="$dir" && break ;; + *"$1"*) match="$dir" ;; + esac + done + + echo "$match" +} + function chruby_reset() { [[ -z "$RUBY_ROOT" ]] && return @@ -83,14 +98,7 @@ function chruby() ;; system) chruby_reset ;; *) - local dir ruby match - for dir in "${RUBIES[@]}"; do - dir="${dir%%/}"; ruby="${dir##*/}" - case "$ruby" in - "$1") match="$dir" && break ;; - *"$1"*) match="$dir" ;; - esac - done + local match="$(chruby_find "$1")" if [[ -z "$match" ]]; then echo "chruby: unknown Ruby: $1" >&2 From eb6683ed7d68894c6dc419fcf4bfc9b9ca0fc5ed Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 17:37:54 -0700 Subject: [PATCH 18/52] Added tests for chruby_find. --- test/chruby_find_test.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 test/chruby_find_test.sh diff --git a/test/chruby_find_test.sh b/test/chruby_find_test.sh new file mode 100755 index 00000000..03bde54f --- /dev/null +++ b/test/chruby_find_test.sh @@ -0,0 +1,28 @@ +. ./test/helper.sh + +function test_chruby_find_with_exact_name() +{ + local exact_match="${test_ruby_root##*/}" + local result="$(chruby_find "$exact_match")" + + assertEquals "did not return the correct ruby dir" \ + "$test_ruby_root" "$result" +} + +function test_chruby_find_with_a_substring() +{ + local substring="$test_ruby_version" + local result="$(chruby_find "$substring")" + + assertEquals "did not return the correct ruby dir" \ + "$test_ruby_root" "$result" +} + +function test_chruby_find_when_cannot_find_match() +{ + local result="$(chruby_find "foo")" + + assertTrue "did not return an empty string" '[[ -z "$result" ]]' +} + +SHUNIT_PARENT=$0 . $SHUNIT2 From 4e3ee1aa612e849ac42c2e90a44dfb1cc0f93785 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Sun, 20 Sep 2020 23:08:46 -0700 Subject: [PATCH 19/52] Extract the RUBIES listing logic into chruby_list. * This will allow overriding chruby_list with custom ruby listing logic. --- share/chruby/chruby.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 56f26b4f..f7a924dc 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -6,6 +6,15 @@ for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do done unset dir +function chruby_list() +{ + local dir + + for dir in "${RUBIES[@]}"; do + echo "$dir" + done +} + function chruby_find() { local dir ruby match @@ -86,15 +95,14 @@ function chruby() ;; "") local dir ruby - for dir in "${RUBIES[@]}"; do + while IFS= read dir; do dir="${dir%%/}"; ruby="${dir##*/}" if [[ "$dir" == "$RUBY_ROOT" ]]; then echo " * ${ruby} ${RUBYOPT}" else echo " ${ruby}" fi - - done + done <<< $(chruby_list) ;; system) chruby_reset ;; *) From fcefa1d3b4ebddaaa4a49cf855e9806f39e1bfa0 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 17:45:50 -0700 Subject: [PATCH 20/52] Added tests for chruby_list. --- test/chruby_list_test.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 test/chruby_list_test.sh diff --git a/test/chruby_list_test.sh b/test/chruby_list_test.sh new file mode 100755 index 00000000..d62bd1d2 --- /dev/null +++ b/test/chruby_list_test.sh @@ -0,0 +1,27 @@ +. ./test/helper.sh + +function setUp() +{ + test_rubies=("${RUBIES[@]}") +} + +function test_chruby_list() +{ + local path1="/path/to/ruby1" + local path2="/path/to/ruby2" + local expected="$(echo "$path1"; echo "$path2")" + + RUBIES=("$path1" "$path2") + + local output="$(chruby_list)" + + assertEquals "did not output the expected ruby paths" \ + "$expected" "$output" +} + +function tearDown() +{ + RUBIES=("${test_rubies[@]}") +} + +SHUNIT_PARENT=$0 . $SHUNIT2 From 63a0f71636982eb209af0ce651d8f41107d39329 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 17:55:44 -0700 Subject: [PATCH 21/52] Renamed chruby_list to chruby_rubies. --- share/chruby/chruby.sh | 4 ++-- test/{chruby_list_test.sh => chruby_rubies_test.sh} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename test/{chruby_list_test.sh => chruby_rubies_test.sh} (86%) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index f7a924dc..bda63309 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -6,7 +6,7 @@ for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do done unset dir -function chruby_list() +function chruby_rubies() { local dir @@ -102,7 +102,7 @@ function chruby() else echo " ${ruby}" fi - done <<< $(chruby_list) + done <<< $(chruby_rubies) ;; system) chruby_reset ;; *) diff --git a/test/chruby_list_test.sh b/test/chruby_rubies_test.sh similarity index 86% rename from test/chruby_list_test.sh rename to test/chruby_rubies_test.sh index d62bd1d2..e055e84e 100755 --- a/test/chruby_list_test.sh +++ b/test/chruby_rubies_test.sh @@ -5,7 +5,7 @@ function setUp() test_rubies=("${RUBIES[@]}") } -function test_chruby_list() +function test_chruby_rubies() { local path1="/path/to/ruby1" local path2="/path/to/ruby2" @@ -13,7 +13,7 @@ function test_chruby_list() RUBIES=("$path1" "$path2") - local output="$(chruby_list)" + local output="$(chruby_rubies)" assertEquals "did not output the expected ruby paths" \ "$expected" "$output" From cb862e08fce420e68a2d6a0a6591c5931a44bdc8 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 18:20:22 -0700 Subject: [PATCH 22/52] Moved initialization logic into chruby_init. --- share/chruby/chruby.sh | 16 +++++++++++----- test/chruby_init_test.sh | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100755 test/chruby_init_test.sh diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index bda63309..c723a8b8 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -1,10 +1,14 @@ CHRUBY_VERSION="1.0.0" -RUBIES=() -for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do - [[ -d "$dir" && -n "$(command ls -A "$dir")" ]] && RUBIES+=("$dir"/*) -done -unset dir +function chruby_init() +{ + local dir + + RUBIES=() + for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do + [[ -d "$dir" && -n "$(ls -A "$dir")" ]] && RUBIES+=("$dir"/*) + done +} function chruby_rubies() { @@ -118,3 +122,5 @@ function chruby() ;; esac } + +chruby_init diff --git a/test/chruby_init_test.sh b/test/chruby_init_test.sh new file mode 100755 index 00000000..09a96788 --- /dev/null +++ b/test/chruby_init_test.sh @@ -0,0 +1,25 @@ +. ./test/helper.sh + +function test_chruby_init_with_clean_env() +{ + unset RUBIES + chruby_init + + assertEquals "did not reset RUBIES" 1 ${#RUBIES[@]} + assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ + "$test_ruby_root" "${RUBIES[0]}" +} + +function test_chruby_init_with_modified_env() +{ + local new_path="/path/to/new/ruby" + + chruby_init + RUBIES+=("$new_path") + + chruby_init + + assertEquals "did not reset RUBIES" "" "${RUBIES[1]}" +} + +SHUNIT_PARENT=$0 . $SHUNIT2 From 1db88e8ca66d2ad57f35e64130581a084911fca8 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 19:09:55 -0700 Subject: [PATCH 23/52] Added the --reload option to re-initialize chruby. --- doc/man/chruby.1.md | 5 ++++- share/chruby/chruby.sh | 3 ++- test/unit/chruby_test.sh | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/man/chruby.1.md b/doc/man/chruby.1.md index 61bc77c1..11995997 100644 --- a/doc/man/chruby.1.md +++ b/doc/man/chruby.1.md @@ -2,7 +2,7 @@ ## SYNOPSIS -`chruby` [] [] +`chruby` [OPTIONS | []] ## ARGUMENTS @@ -17,6 +17,9 @@ ## OPTIONS +`--reload` + Reloads the list of available Rubies + `-h`, `--help` `-v`, `--version` diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index c723a8b8..1e8a5e1f 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -92,11 +92,12 @@ function chruby() { case "$1" in -h|--help) - echo "usage: chruby [RUBY|VERSION|system] [RUBYOPT...]" + echo "usage: chruby [--reload | RUBY|VERSION|system [RUBYOPT...]]" ;; -V|--version) echo "chruby: $CHRUBY_VERSION" ;; + --reload) chruby_init ;; "") local dir ruby while IFS= read dir; do diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index e466fa58..5f31a3ff 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -63,6 +63,18 @@ function test_chruby_invalid_ruby() assertEquals "did not return 1" 1 $? } +function test_chruby_reload() +{ + RUBIES=() + + chruby --reload + + assertEquals "did not return 1" 1 $? + assertEquals "did not re-populate RUBIES" 1 ${#RUBIES[@]} + assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ + "$test_ruby_root" "${RUBIES[0]}" +} + function tearDown() { chruby_reset From 7196ad1247a14aee668f983aaa14ddba28222be0 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 19:11:07 -0700 Subject: [PATCH 24/52] Make the usage string more accurate. --- doc/man/chruby.1.md | 2 +- share/chruby/chruby.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/man/chruby.1.md b/doc/man/chruby.1.md index 11995997..2212b877 100644 --- a/doc/man/chruby.1.md +++ b/doc/man/chruby.1.md @@ -2,7 +2,7 @@ ## SYNOPSIS -`chruby` [OPTIONS | []] +`chruby` [OPTIONS | [] | system] ## ARGUMENTS diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 1e8a5e1f..e42b3f33 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -92,7 +92,7 @@ function chruby() { case "$1" in -h|--help) - echo "usage: chruby [--reload | RUBY|VERSION|system [RUBYOPT...]]" + echo "usage: chruby [--reload | RUBY|VERSION [RUBYOPT...] | system]" ;; -V|--version) echo "chruby: $CHRUBY_VERSION" From 1e7eaca5fedcb15df9b825d6b9bc5b71717f631b Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 21:08:38 -0700 Subject: [PATCH 25/52] Added more tests for `chruby` listing capaibilities and how it handles paths with spaces. --- test/unit/chruby_test.sh | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index 5f31a3ff..c4c3272e 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -2,14 +2,39 @@ function setUp() { - original_rubies=(${RUBIES[@]}) + original_rubies=("${RUBIES[@]}") } -function test_chruby_default_RUBIES() +function test_chruby_list_rubies() { - assertEquals "did not correctly populate RUBIES" \ - "$test_ruby_root" \ - "${RUBIES[@]}" + local expected=" ${test_ruby_engine}-${test_ruby_version}" + local output="$(chruby)" + + assertEquals "did not correctly list RUBIES" \ + "$expected" "$output" +} + +function test_chruby_list_rubies_when_a_ruby_is_active() +{ + chruby "${test_ruby_engine}-${test_ruby_version}" + + local expected=" * ${test_ruby_engine}-${test_ruby_version}" + local output="$(chruby)" + + assertEquals "did not correctly list RUBIES" \ + "$expected" "$output" +} + +function test_chruby_list_RUBIES_when_one_contains_a_space() +{ + local ruby_name="ruby" + local path_with_spaces="/path/with spaces/$ruby_name" + + RUBIES=("$path_with_spaces") + local output="$(chruby)" + + assertEquals "did not correctly handle paths containing spaces" \ + " $ruby_name" "$output" } function test_chruby_X_Y() From 8224fae099d9710896f421e432a2a97ca4e75c16 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 21:09:18 -0700 Subject: [PATCH 26/52] Only output $RUBYOPT if it's set. --- share/chruby/chruby.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index e42b3f33..b46c1ad3 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -103,7 +103,7 @@ function chruby() while IFS= read dir; do dir="${dir%%/}"; ruby="${dir##*/}" if [[ "$dir" == "$RUBY_ROOT" ]]; then - echo " * ${ruby} ${RUBYOPT}" + echo " * ${ruby}${RUBYOPT:+ $RUBYOPT}" else echo " ${ruby}" fi From 0c5fcda1b95b8b3d6f67021f1ff8669451086d52 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 21:26:38 -0700 Subject: [PATCH 27/52] Test when chruby_use cannot find bin/ruby within the ruby. --- test/unit/chruby_use_test.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unit/chruby_use_test.sh b/test/unit/chruby_use_test.sh index 7cd8e049..8db40dad 100755 --- a/test/unit/chruby_use_test.sh +++ b/test/unit/chruby_use_test.sh @@ -15,6 +15,13 @@ function test_chruby_clears_hash_table() fi } +function test_chruby_use_with_invalid_ruby_path() +{ + chruby_use "/path/to/fake/ruby" 2>/dev/null + + assertEquals "did not return an error code" 1 $? +} + function test_chruby_use_env_variables() { chruby_use "$test_ruby_root" >/dev/null From 9f7f84415188818d0c2f9b42cf5f27178b69847e Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 21:28:55 -0700 Subject: [PATCH 28/52] Quote arguments. --- test/unit/chruby_use_test.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unit/chruby_use_test.sh b/test/unit/chruby_use_test.sh index 8db40dad..b9b01283 100755 --- a/test/unit/chruby_use_test.sh +++ b/test/unit/chruby_use_test.sh @@ -1,5 +1,10 @@ . ./test/unit/helper.sh +function setUp() +{ + chruby_use "$test_ruby_root" >/dev/null +} + function test_chruby_clears_hash_table() { if [[ -n "$ZSH_VERSION" ]]; then From 2136de9f5c52bf0493e5c22f2a8b471252fd2bde Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 21:29:30 -0700 Subject: [PATCH 29/52] Renamed test_rubies to original_rubies. --- test/chruby_rubies_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/chruby_rubies_test.sh b/test/chruby_rubies_test.sh index e055e84e..7ff8e8dc 100755 --- a/test/chruby_rubies_test.sh +++ b/test/chruby_rubies_test.sh @@ -2,7 +2,7 @@ function setUp() { - test_rubies=("${RUBIES[@]}") + original_rubies=("${RUBIES[@]}") } function test_chruby_rubies() @@ -21,7 +21,7 @@ function test_chruby_rubies() function tearDown() { - RUBIES=("${test_rubies[@]}") + RUBIES=("${original_rubies[@]}") } SHUNIT_PARENT=$0 . $SHUNIT2 From f54bbeb008865cff056010369fadf8180c27f12b Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 21:30:35 -0700 Subject: [PATCH 30/52] Move tearDown functions to the bottom. --- test/unit/chruby_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index c4c3272e..b1d8ba5b 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -104,7 +104,7 @@ function tearDown() { chruby_reset - RUBIES=(${original_rubies[@]}) + RUBIES=("${original_rubies[@]}") } SHUNIT_PARENT=$0 . $SHUNIT2 From edbf9cba4b71ac45e91eff7d2318a396fd325e53 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 21:43:31 -0700 Subject: [PATCH 31/52] Moved some chruby matching tests into the chruby_find tests. --- test/chruby_find_test.sh | 39 ++++++++++++++++++++++++++++++++++----- test/unit/chruby_test.sh | 20 -------------------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/test/chruby_find_test.sh b/test/chruby_find_test.sh index 03bde54f..ef8c2a0b 100755 --- a/test/chruby_find_test.sh +++ b/test/chruby_find_test.sh @@ -1,21 +1,50 @@ . ./test/helper.sh +function setUp() +{ + test_ruby_path1="/path/to/ruby1" + test_ruby_path2="/path/to/ruby2" + + RUBIES=("$test_ruby_path1" "$test_ruby_path2") +} + function test_chruby_find_with_exact_name() { - local exact_match="${test_ruby_root##*/}" + local exact_match="${test_ruby_path2##*/}" local result="$(chruby_find "$exact_match")" assertEquals "did not return the correct ruby dir" \ - "$test_ruby_root" "$result" + "$test_ruby_path2" "$result" +} + +function test_chruby_find_with_exact_name_but_there_are_multiple_matches() +{ + RUBIES=( + "$test_ruby_path1" + "${test_ruby_path1}-foo" + "$test_ruby_path2" + "${test_ruby_path2}-bar" + ) + + local result="$(chruby_find "${test_ruby_path2##*/}")" + + assertEquals "did not use the exact match first" \ + "$test_ruby_path2" "$result" } function test_chruby_find_with_a_substring() { - local substring="$test_ruby_version" - local result="$(chruby_find "$substring")" + local result="$(chruby_find "2")" assertEquals "did not return the correct ruby dir" \ - "$test_ruby_root" "$result" + "$test_ruby_path2" "$result" +} + +function test_chruby_find_when_there_are_multiple_matches() +{ + local result="$(chruby_find "ruby")" + + assertEquals "did not use the last match" "$test_ruby_path2" "$result" } function test_chruby_find_when_cannot_find_match() diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index b1d8ba5b..114681db 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -44,26 +44,6 @@ function test_chruby_X_Y() assertEquals "did not match $test_ruby_version_x_y" "$test_ruby_root" "$RUBY_ROOT" } -function test_chruby_multiple_matches() -{ - local fake_ruby="/path/to/ruby-${test_ruby_version_x_y}" - - RUBIES=("$fake_ruby" "$test_ruby_root") - - chruby "${test_ruby_version_x_y}" >/dev/null - - assertEquals "did not use the last match" "$test_ruby_root" "$RUBY_ROOT" -} - -function test_chruby_exact_match_first() -{ - RUBIES=("$test_ruby_root" "${test_ruby_root}-rc1") - - chruby "${test_ruby_root##*/}" - - assertEquals "did not use the exact match" "$test_ruby_root" "$RUBY_ROOT" -} - function test_chruby_system() { chruby "$test_ruby_version" >/dev/null From 9ea0411576ba04616954aec09f76a6b77d0b0a4e Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 22:06:36 -0700 Subject: [PATCH 32/52] Use assertEquals. --- test/chruby_find_test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/chruby_find_test.sh b/test/chruby_find_test.sh index ef8c2a0b..39236add 100755 --- a/test/chruby_find_test.sh +++ b/test/chruby_find_test.sh @@ -51,7 +51,7 @@ function test_chruby_find_when_cannot_find_match() { local result="$(chruby_find "foo")" - assertTrue "did not return an empty string" '[[ -z "$result" ]]' + assertEquals "did not return an empty string" "" "$result" } SHUNIT_PARENT=$0 . $SHUNIT2 From 262d7455111d307cdefc67daa9d93c7cc67a257f Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 22:06:43 -0700 Subject: [PATCH 33/52] Use better test names. --- test/unit/chruby_test.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index 114681db..0dca4aa4 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -25,7 +25,7 @@ function test_chruby_list_rubies_when_a_ruby_is_active() "$expected" "$output" } -function test_chruby_list_RUBIES_when_one_contains_a_space() +function test_chruby_list_rubies_when_one_contains_a_space() { local ruby_name="ruby" local path_with_spaces="/path/with spaces/$ruby_name" @@ -37,14 +37,14 @@ function test_chruby_list_RUBIES_when_one_contains_a_space() " $ruby_name" "$output" } -function test_chruby_X_Y() +function test_chruby_with_X_Y() { chruby "$test_ruby_version_x_y" >/dev/null assertEquals "did not match $test_ruby_version_x_y" "$test_ruby_root" "$RUBY_ROOT" } -function test_chruby_system() +function test_chruby_with_system() { chruby "$test_ruby_version" >/dev/null chruby system @@ -52,14 +52,14 @@ function test_chruby_system() assertNull "did not reset the Ruby" "$RUBY_ROOT" } -function test_chruby_unknown() +function test_chruby_with_unknown_ruby() { chruby "does_not_exist" 2>/dev/null assertEquals "did not return 1" 1 $? } -function test_chruby_invalid_ruby() +function test_chruby_with_invalid_ruby() { RUBIES=(/does/not/exist/jruby) From 69caf3d1b512f2705e3d1e81fdb932a4e929a4f4 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 22:35:03 -0700 Subject: [PATCH 34/52] Added a test for `chruby --version`. --- test/unit/chruby_test.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index 0dca4aa4..05d0e7fc 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -80,6 +80,14 @@ function test_chruby_reload() "$test_ruby_root" "${RUBIES[0]}" } +function test_chruby_version() +{ + local output="$(chruby --version)" + + assertEquals "did not output the chruby version" \ + "chruby: $CHRUBY_VERSION" "$output" +} + function tearDown() { chruby_reset From e930c386df0a16ee92f8b0f5b06fdf60dfbefe17 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 22:36:10 -0700 Subject: [PATCH 35/52] Added a test for `chruby --help`. --- test/unit/chruby_test.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index 05d0e7fc..0dad8aed 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -80,6 +80,15 @@ function test_chruby_reload() "$test_ruby_root" "${RUBIES[0]}" } +function test_chruby_help() +{ + local usage="usage: chruby [--reload | RUBY|VERSION [RUBYOPT...] | system]" + local output="$(chruby --help)" + + assertEquals "did not output the chruby usage string" \ + "$usage" "$output" +} + function test_chruby_version() { local output="$(chruby --version)" From 5e35f5c14ecc9dc904348515ab9e29a741c36dec Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 23:16:07 -0700 Subject: [PATCH 36/52] Ensure that chruby_init does not accidentally return 1. --- share/chruby/chruby.sh | 4 +++- test/unit/chruby_test.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index b46c1ad3..fb227ec4 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -6,7 +6,9 @@ function chruby_init() RUBIES=() for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do - [[ -d "$dir" && -n "$(ls -A "$dir")" ]] && RUBIES+=("$dir"/*) + if [[ -d "$dir" && -n "$(ls -A "$dir")" ]]; then + RUBIES+=("$dir"/*) + fi done } diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index 0dad8aed..502e48ae 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -74,7 +74,7 @@ function test_chruby_reload() chruby --reload - assertEquals "did not return 1" 1 $? + assertEquals "did not return 0" 0 $? assertEquals "did not re-populate RUBIES" 1 ${#RUBIES[@]} assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ "$test_ruby_root" "${RUBIES[0]}" From 99f639cb2e96367486654661bd8cbcefedcddabd Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 23:23:03 -0700 Subject: [PATCH 37/52] Renamed RUBIES to CHRUBY_RUBIES. --- share/chruby/chruby.sh | 8 ++++---- test/chruby_find_test.sh | 4 ++-- test/chruby_init_test.sh | 10 +++++----- test/chruby_rubies_test.sh | 6 +++--- test/unit/chruby_test.sh | 18 +++++++++--------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index fb227ec4..0b5bc62d 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -4,10 +4,10 @@ function chruby_init() { local dir - RUBIES=() + CHRUBY_RUBIES=() for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do if [[ -d "$dir" && -n "$(ls -A "$dir")" ]]; then - RUBIES+=("$dir"/*) + CHRUBY_RUBIES+=("$dir"/*) fi done } @@ -16,7 +16,7 @@ function chruby_rubies() { local dir - for dir in "${RUBIES[@]}"; do + for dir in "${CHRUBY_RUBIES[@]}"; do echo "$dir" done } @@ -25,7 +25,7 @@ function chruby_find() { local dir ruby match - for dir in "${RUBIES[@]}"; do + for dir in "${CHRUBY_RUBIES[@]}"; do dir="${dir%%/}"; ruby="${dir##*/}" case "$ruby" in "$1") match="$dir" && break ;; diff --git a/test/chruby_find_test.sh b/test/chruby_find_test.sh index 39236add..562968f6 100755 --- a/test/chruby_find_test.sh +++ b/test/chruby_find_test.sh @@ -5,7 +5,7 @@ function setUp() test_ruby_path1="/path/to/ruby1" test_ruby_path2="/path/to/ruby2" - RUBIES=("$test_ruby_path1" "$test_ruby_path2") + CHRUBY_RUBIES=("$test_ruby_path1" "$test_ruby_path2") } function test_chruby_find_with_exact_name() @@ -19,7 +19,7 @@ function test_chruby_find_with_exact_name() function test_chruby_find_with_exact_name_but_there_are_multiple_matches() { - RUBIES=( + CHRUBY_RUBIES=( "$test_ruby_path1" "${test_ruby_path1}-foo" "$test_ruby_path2" diff --git a/test/chruby_init_test.sh b/test/chruby_init_test.sh index 09a96788..f8598571 100755 --- a/test/chruby_init_test.sh +++ b/test/chruby_init_test.sh @@ -2,12 +2,12 @@ function test_chruby_init_with_clean_env() { - unset RUBIES + unset CHRUBY_RUBIES chruby_init - assertEquals "did not reset RUBIES" 1 ${#RUBIES[@]} + assertEquals "did not reset CHRUBY_RUBIES" 1 ${#CHRUBY_RUBIES[@]} assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ - "$test_ruby_root" "${RUBIES[0]}" + "$test_ruby_root" "${CHRUBY_RUBIES[0]}" } function test_chruby_init_with_modified_env() @@ -15,11 +15,11 @@ function test_chruby_init_with_modified_env() local new_path="/path/to/new/ruby" chruby_init - RUBIES+=("$new_path") + CHRUBY_RUBIES+=("$new_path") chruby_init - assertEquals "did not reset RUBIES" "" "${RUBIES[1]}" + assertEquals "did not reset CHRUBY_RUBIES" "" "${CHRUBY_RUBIES[1]}" } SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/chruby_rubies_test.sh b/test/chruby_rubies_test.sh index 7ff8e8dc..4aafbdb4 100755 --- a/test/chruby_rubies_test.sh +++ b/test/chruby_rubies_test.sh @@ -2,7 +2,7 @@ function setUp() { - original_rubies=("${RUBIES[@]}") + original_rubies=("${CHRUBY_RUBIES[@]}") } function test_chruby_rubies() @@ -11,7 +11,7 @@ function test_chruby_rubies() local path2="/path/to/ruby2" local expected="$(echo "$path1"; echo "$path2")" - RUBIES=("$path1" "$path2") + CHRUBY_RUBIES=("$path1" "$path2") local output="$(chruby_rubies)" @@ -21,7 +21,7 @@ function test_chruby_rubies() function tearDown() { - RUBIES=("${original_rubies[@]}") + CHRUBY_RUBIES=("${original_rubies[@]}") } SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index 502e48ae..06c89103 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -2,7 +2,7 @@ function setUp() { - original_rubies=("${RUBIES[@]}") + original_rubies=("${CHRUBY_RUBIES[@]}") } function test_chruby_list_rubies() @@ -10,7 +10,7 @@ function test_chruby_list_rubies() local expected=" ${test_ruby_engine}-${test_ruby_version}" local output="$(chruby)" - assertEquals "did not correctly list RUBIES" \ + assertEquals "did not correctly list CHRUBY_RUBIES" \ "$expected" "$output" } @@ -21,7 +21,7 @@ function test_chruby_list_rubies_when_a_ruby_is_active() local expected=" * ${test_ruby_engine}-${test_ruby_version}" local output="$(chruby)" - assertEquals "did not correctly list RUBIES" \ + assertEquals "did not correctly list CHRUBY_RUBIES" \ "$expected" "$output" } @@ -30,7 +30,7 @@ function test_chruby_list_rubies_when_one_contains_a_space() local ruby_name="ruby" local path_with_spaces="/path/with spaces/$ruby_name" - RUBIES=("$path_with_spaces") + CHRUBY_RUBIES=("$path_with_spaces") local output="$(chruby)" assertEquals "did not correctly handle paths containing spaces" \ @@ -61,7 +61,7 @@ function test_chruby_with_unknown_ruby() function test_chruby_with_invalid_ruby() { - RUBIES=(/does/not/exist/jruby) + CHRUBY_RUBIES=(/does/not/exist/jruby) chruby "jruby" 2>/dev/null @@ -70,14 +70,14 @@ function test_chruby_with_invalid_ruby() function test_chruby_reload() { - RUBIES=() + CHRUBY_RUBIES=() chruby --reload assertEquals "did not return 0" 0 $? - assertEquals "did not re-populate RUBIES" 1 ${#RUBIES[@]} + assertEquals "did not re-populate CHRUBY_RUBIES" 1 ${#CHRUBY_RUBIES[@]} assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ - "$test_ruby_root" "${RUBIES[0]}" + "$test_ruby_root" "${CHRUBY_RUBIES[0]}" } function test_chruby_help() @@ -101,7 +101,7 @@ function tearDown() { chruby_reset - RUBIES=("${original_rubies[@]}") + CHRUBY_RUBIES=("${original_rubies[@]}") } SHUNIT_PARENT=$0 . $SHUNIT2 From 74e693627f27df61833ccc9b254dd089a853f403 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 23:28:10 -0700 Subject: [PATCH 38/52] Renamed RUBY_AUTO_VERSION to CHRUBY_AUTO_VERSION. --- share/chruby/auto.sh | 10 +++++----- test/unit/chruby_auto_test.sh | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/share/chruby/auto.sh b/share/chruby/auto.sh index 88f3cb34..879a83fd 100644 --- a/share/chruby/auto.sh +++ b/share/chruby/auto.sh @@ -1,4 +1,4 @@ -unset RUBY_AUTO_VERSION +unset CHRUBY_AUTO_VERSION function chruby_auto() { local dir="$PWD/" version @@ -9,18 +9,18 @@ function chruby_auto() { if { read -r version <"$dir/.ruby-version"; } 2>/dev/null || [[ -n "$version" ]]; then version="${version%%[[:space:]]}" - if [[ "$version" == "$RUBY_AUTO_VERSION" ]]; then return + if [[ "$version" == "$CHRUBY_AUTO_VERSION" ]]; then return else - RUBY_AUTO_VERSION="$version" + CHRUBY_AUTO_VERSION="$version" chruby "$version" return $? fi fi done - if [[ -n "$RUBY_AUTO_VERSION" ]]; then + if [[ -n "$CHRUBY_AUTO_VERSION" ]]; then chruby_reset - unset RUBY_AUTO_VERSION + unset CHRUBY_AUTO_VERSION fi } diff --git a/test/unit/chruby_auto_test.sh b/test/unit/chruby_auto_test.sh index 46729627..0669a96f 100755 --- a/test/unit/chruby_auto_test.sh +++ b/test/unit/chruby_auto_test.sh @@ -25,7 +25,7 @@ function setUp() echo "system" > "$test_auto_version_dir/sub_versioned/.ruby-version" chruby_reset - unset RUBY_AUTO_VERSION + unset CHRUBY_AUTO_VERSION } function test_chruby_auto_loaded_in_zsh() @@ -61,12 +61,12 @@ function test_chruby_auto_loaded_twice_in_zsh() function test_chruby_auto_loaded_twice() { - RUBY_AUTO_VERSION="dirty" + CHRUBY_AUTO_VERSION="dirty" PROMPT_COMMAND="chruby_auto" . ./share/chruby/auto.sh - assertNull "RUBY_AUTO_VERSION was not unset" "$RUBY_AUTO_VERSION" + assertNull "CHRUBY_AUTO_VERSION was not unset" "$CHRUBY_AUTO_VERSION" } function test_chruby_auto_enter_project_dir() @@ -155,8 +155,8 @@ function test_chruby_auto_ruby_version_containing_options() assertEquals "did not keep the current Ruby when loading an unknown version" \ "$test_ruby_root" "$RUBY_ROOT" - assertEquals "did not set RUBY_AUTO_VERSION" \ - "$expected_auto_version" "$RUBY_AUTO_VERSION" + assertEquals "did not set CHRUBY_AUTO_VERSION" \ + "$expected_auto_version" "$CHRUBY_AUTO_VERSION" } function tearDown() From 5c2abd08e4afd3bf12b2ffb7451e204c131d58af Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 23:35:18 -0700 Subject: [PATCH 39/52] 80 columns. --- share/chruby/auto.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/chruby/auto.sh b/share/chruby/auto.sh index 879a83fd..c25d8cf9 100644 --- a/share/chruby/auto.sh +++ b/share/chruby/auto.sh @@ -9,7 +9,8 @@ function chruby_auto() { if { read -r version <"$dir/.ruby-version"; } 2>/dev/null || [[ -n "$version" ]]; then version="${version%%[[:space:]]}" - if [[ "$version" == "$CHRUBY_AUTO_VERSION" ]]; then return + if [[ "$version" == "$CHRUBY_AUTO_VERSION" ]]; then + return else CHRUBY_AUTO_VERSION="$version" chruby "$version" From c339d46719fafbff298046fb75e47328ce083ea6 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 23:36:30 -0700 Subject: [PATCH 40/52] Curly braces go on the following line. --- share/chruby/auto.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/chruby/auto.sh b/share/chruby/auto.sh index c25d8cf9..1fb5247f 100644 --- a/share/chruby/auto.sh +++ b/share/chruby/auto.sh @@ -1,6 +1,7 @@ unset CHRUBY_AUTO_VERSION -function chruby_auto() { +function chruby_auto() +{ local dir="$PWD/" version until [[ -z "$dir" ]]; do From 66d236088f05721bd0f5643dc5820b39f6657018 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 23 Sep 2020 23:59:22 -0700 Subject: [PATCH 41/52] Use local variables to indicate purpose of function arguments. --- share/chruby/chruby.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 0b5bc62d..63898e86 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -6,7 +6,7 @@ function chruby_init() CHRUBY_RUBIES=() for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do - if [[ -d "$dir" && -n "$(ls -A "$dir")" ]]; then + if [[ -d "$dir" ]] && [[ -n "$(ls -A "$dir")" ]]; then CHRUBY_RUBIES+=("$dir"/*) fi done @@ -62,14 +62,16 @@ function chruby_reset() function chruby_use() { - if [[ ! -x "$1/bin/ruby" ]]; then - echo "chruby: $1/bin/ruby not executable" >&2 + local ruby_dir="$1" + + if [[ ! -x "$ruby_dir/bin/ruby" ]]; then + echo "chruby: $ruby_dir/bin/ruby not executable" >&2 return 1 fi [[ -n "$RUBY_ROOT" ]] && chruby_reset - export RUBY_ROOT="$1" + export RUBY_ROOT="$ruby_dir" export RUBYOPT="$2" export PATH="$RUBY_ROOT/bin:$PATH" @@ -113,15 +115,16 @@ function chruby() ;; system) chruby_reset ;; *) - local match="$(chruby_find "$1")" + local ruby="$1" + local ruby_dir="$(chruby_find "$ruby")" - if [[ -z "$match" ]]; then - echo "chruby: unknown Ruby: $1" >&2 + if [[ -z "$ruby_dir" ]]; then + echo "chruby: unknown Ruby: $ruby" >&2 return 1 fi shift - chruby_use "$match" "$*" + chruby_use "$ruby_dir" "$*" ;; esac } From 705bf1b6492b902c4da89d2a64ad21df94519498 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Thu, 24 Sep 2020 04:24:25 -0700 Subject: [PATCH 42/52] Replaced `chruby_rubies` with a simple for loop. * Customization of `CHRUBY_RUBIES` array should be done in `chruby_init`. --- share/chruby/chruby.sh | 13 ++----------- test/chruby_rubies_test.sh | 27 --------------------------- 2 files changed, 2 insertions(+), 38 deletions(-) delete mode 100755 test/chruby_rubies_test.sh diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 63898e86..a12d31c9 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -12,15 +12,6 @@ function chruby_init() done } -function chruby_rubies() -{ - local dir - - for dir in "${CHRUBY_RUBIES[@]}"; do - echo "$dir" - done -} - function chruby_find() { local dir ruby match @@ -104,14 +95,14 @@ function chruby() --reload) chruby_init ;; "") local dir ruby - while IFS= read dir; do + for dir in "${CHRUBY_RUBIES[@]}"; do dir="${dir%%/}"; ruby="${dir##*/}" if [[ "$dir" == "$RUBY_ROOT" ]]; then echo " * ${ruby}${RUBYOPT:+ $RUBYOPT}" else echo " ${ruby}" fi - done <<< $(chruby_rubies) + done ;; system) chruby_reset ;; *) diff --git a/test/chruby_rubies_test.sh b/test/chruby_rubies_test.sh deleted file mode 100755 index 4aafbdb4..00000000 --- a/test/chruby_rubies_test.sh +++ /dev/null @@ -1,27 +0,0 @@ -. ./test/helper.sh - -function setUp() -{ - original_rubies=("${CHRUBY_RUBIES[@]}") -} - -function test_chruby_rubies() -{ - local path1="/path/to/ruby1" - local path2="/path/to/ruby2" - local expected="$(echo "$path1"; echo "$path2")" - - CHRUBY_RUBIES=("$path1" "$path2") - - local output="$(chruby_rubies)" - - assertEquals "did not output the expected ruby paths" \ - "$expected" "$output" -} - -function tearDown() -{ - CHRUBY_RUBIES=("${original_rubies[@]}") -} - -SHUNIT_PARENT=$0 . $SHUNIT2 From a97a8d87ca324cd52f34283daa0b5cf636bd819d Mon Sep 17 00:00:00 2001 From: Postmodern Date: Thu, 24 Sep 2020 04:29:16 -0700 Subject: [PATCH 43/52] Empty line after local variable definitions. --- share/chruby/chruby.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index a12d31c9..06735d32 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -95,6 +95,7 @@ function chruby() --reload) chruby_init ;; "") local dir ruby + for dir in "${CHRUBY_RUBIES[@]}"; do dir="${dir%%/}"; ruby="${dir##*/}" if [[ "$dir" == "$RUBY_ROOT" ]]; then From bd5b5cdb53aec1c4f84e6266072bd3e1629ee78a Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 7 Oct 2020 16:40:07 -0700 Subject: [PATCH 44/52] Renamed chruby_use to chruby_set. --- README.md | 2 +- benchmarks/{chruby_use.sh => chruby_set.sh} | 2 +- doc/man/chruby.1.md | 2 +- share/chruby/chruby.sh | 4 ++-- share/man/man1/chruby.1 | 4 ++-- test/{ => unit}/chruby_find_test.sh | 2 +- test/{ => unit}/chruby_init_test.sh | 2 +- test/unit/chruby_reset_test.sh | 2 +- .../{chruby_use_test.sh => chruby_set_test.sh} | 14 +++++++------- 9 files changed, 17 insertions(+), 17 deletions(-) rename benchmarks/{chruby_use.sh => chruby_set.sh} (90%) rename test/{ => unit}/chruby_find_test.sh (98%) rename test/{ => unit}/chruby_init_test.sh (95%) rename test/unit/{chruby_use_test.sh => chruby_set_test.sh} (79%) diff --git a/README.md b/README.md index 107e1a33..a2b48078 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ Run a command under a Ruby with `chruby-exec`: Switch to an arbitrary Ruby on the fly: - $ chruby_use /path/to/ruby + $ chruby_set /path/to/ruby ## Uninstall diff --git a/benchmarks/chruby_use.sh b/benchmarks/chruby_set.sh similarity index 90% rename from benchmarks/chruby_use.sh rename to benchmarks/chruby_set.sh index ff60bf7e..40fccf7a 100755 --- a/benchmarks/chruby_use.sh +++ b/benchmarks/chruby_set.sh @@ -9,7 +9,7 @@ for i in {1..3}; do time ( for ((i=0; i<$n; i+=1)); do - chruby_use "$ruby_dir" + chruby_set "$ruby_dir" done ) done diff --git a/doc/man/chruby.1.md b/doc/man/chruby.1.md index 2212b877..15a21962 100644 --- a/doc/man/chruby.1.md +++ b/doc/man/chruby.1.md @@ -51,7 +51,7 @@ Switch back to system Ruby: $ chruby system Switch to an arbitrary Ruby on the fly: - $ chruby_use /path/to/ruby + $ chruby_set /path/to/ruby ## FILES diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 06735d32..1f837b4d 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -51,7 +51,7 @@ function chruby_reset() hash -r } -function chruby_use() +function chruby_set() { local ruby_dir="$1" @@ -116,7 +116,7 @@ function chruby() fi shift - chruby_use "$ruby_dir" "$*" + chruby_set "$ruby_dir" "$*" ;; esac } diff --git a/share/man/man1/chruby.1 b/share/man/man1/chruby.1 index ca52536a..33df162d 100644 --- a/share/man/man1/chruby.1 +++ b/share/man/man1/chruby.1 @@ -46,7 +46,7 @@ Switch back to system Ruby: $ chruby system .PP Switch to an arbitrary Ruby on the fly: - $ chruby_use /path/to/ruby + $ chruby_set /path/to/ruby .SH FILES .PP \fI/opt/rubies\fP @@ -91,4 +91,4 @@ Postmodern postmodern.mod3\@gmail.com .SH SEE ALSO .PP .BR ruby (1), -.BR gem (1) \ No newline at end of file +.BR gem (1) diff --git a/test/chruby_find_test.sh b/test/unit/chruby_find_test.sh similarity index 98% rename from test/chruby_find_test.sh rename to test/unit/chruby_find_test.sh index 562968f6..8db65f53 100755 --- a/test/chruby_find_test.sh +++ b/test/unit/chruby_find_test.sh @@ -1,4 +1,4 @@ -. ./test/helper.sh +. ./test/unit/helper.sh function setUp() { diff --git a/test/chruby_init_test.sh b/test/unit/chruby_init_test.sh similarity index 95% rename from test/chruby_init_test.sh rename to test/unit/chruby_init_test.sh index f8598571..622246da 100755 --- a/test/chruby_init_test.sh +++ b/test/unit/chruby_init_test.sh @@ -1,4 +1,4 @@ -. ./test/helper.sh +. ./test/unit/helper.sh function test_chruby_init_with_clean_env() { diff --git a/test/unit/chruby_reset_test.sh b/test/unit/chruby_reset_test.sh index 5e19ed60..ee2f5422 100755 --- a/test/unit/chruby_reset_test.sh +++ b/test/unit/chruby_reset_test.sh @@ -2,7 +2,7 @@ function setUp() { - chruby_use "$test_ruby_root" >/dev/null + chruby_set "$test_ruby_root" >/dev/null export PATH="$GEM_HOME/bin:$GEM_ROOT/bin:$RUBY_ROOT/bin:$original_path" } diff --git a/test/unit/chruby_use_test.sh b/test/unit/chruby_set_test.sh similarity index 79% rename from test/unit/chruby_use_test.sh rename to test/unit/chruby_set_test.sh index b9b01283..957f4c42 100755 --- a/test/unit/chruby_use_test.sh +++ b/test/unit/chruby_set_test.sh @@ -2,34 +2,34 @@ function setUp() { - chruby_use "$test_ruby_root" >/dev/null + chruby_set "$test_ruby_root" >/dev/null } function test_chruby_clears_hash_table() { if [[ -n "$ZSH_VERSION" ]]; then - chruby_use "$test_ruby_root" >/dev/null + chruby_set "$test_ruby_root" >/dev/null assertEquals "did not clear the path table" \ "" "$(hash)" elif [[ -n "$BASH_VERSION" ]]; then - chruby_use "$test_ruby_root" >/dev/null + chruby_set "$test_ruby_root" >/dev/null assertEquals "did not clear the path table" \ "hash: hash table empty" "$(hash)" fi } -function test_chruby_use_with_invalid_ruby_path() +function test_chruby_set_with_invalid_ruby_path() { - chruby_use "/path/to/fake/ruby" 2>/dev/null + chruby_set "/path/to/fake/ruby" 2>/dev/null assertEquals "did not return an error code" 1 $? } -function test_chruby_use_env_variables() +function test_chruby_set_env_variables() { - chruby_use "$test_ruby_root" >/dev/null + chruby_set "$test_ruby_root" >/dev/null assertEquals "invalid RUBY_ROOT" "$test_ruby_root" "$RUBY_ROOT" assertEquals "invalid RUBY_ENGINE" "$test_ruby_engine" "$RUBY_ENGINE" From b219bae4eddb098d12686e7d34bee1d66741a741 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Sun, 26 Sep 2021 13:33:12 -0700 Subject: [PATCH 45/52] Fixed a failing test. --- test/unit/chruby_auto_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/chruby_auto_test.sh b/test/unit/chruby_auto_test.sh index 0669a96f..22c6f135 100755 --- a/test/unit/chruby_auto_test.sh +++ b/test/unit/chruby_auto_test.sh @@ -142,8 +142,8 @@ function test_chruby_auto_unknown_ruby() assertEquals "did not keep the current Ruby when loading an unknown version" \ "$test_ruby_root" "$RUBY_ROOT" - assertEquals "did not set RUBY_AUTO_VERSION" \ - "$expected_auto_version" "$RUBY_AUTO_VERSION" + assertEquals "did not set CHRUBY_AUTO_VERSION" \ + "$expected_auto_version" "$CHRUBY_AUTO_VERSION" } function test_chruby_auto_ruby_version_containing_options() From 947ee85754c4f916971c4ee82bc599ad3e947caf Mon Sep 17 00:00:00 2001 From: Postmodern Date: Sun, 26 Sep 2021 14:12:28 -0700 Subject: [PATCH 46/52] Fix tests that were failing due to zsh indexing arrays starting at 1. --- test/unit/chruby_init_test.sh | 18 +++++++++++++++--- test/unit/chruby_test.sh | 10 ++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/test/unit/chruby_init_test.sh b/test/unit/chruby_init_test.sh index 622246da..e0e2c4e2 100755 --- a/test/unit/chruby_init_test.sh +++ b/test/unit/chruby_init_test.sh @@ -6,8 +6,14 @@ function test_chruby_init_with_clean_env() chruby_init assertEquals "did not reset CHRUBY_RUBIES" 1 ${#CHRUBY_RUBIES[@]} - assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ - "$test_ruby_root" "${CHRUBY_RUBIES[0]}" + + if [[ -n "$ZSH_VERSION" ]]; then + assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ + "$test_ruby_root" "${CHRUBY_RUBIES[1]}" + else + assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ + "$test_ruby_root" "${CHRUBY_RUBIES[0]}" + fi } function test_chruby_init_with_modified_env() @@ -19,7 +25,13 @@ function test_chruby_init_with_modified_env() chruby_init - assertEquals "did not reset CHRUBY_RUBIES" "" "${CHRUBY_RUBIES[1]}" + if [[ -n "$ZSH_VERSION" ]]; then + assertEquals "did not reset CHRUBY_RUBIES" \ + "" "${CHRUBY_RUBIES[2]}" + else + assertEquals "did not reset CHRUBY_RUBIES" \ + "" "${CHRUBY_RUBIES[1]}" + fi } SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index 06c89103..897cab0b 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -76,8 +76,14 @@ function test_chruby_reload() assertEquals "did not return 0" 0 $? assertEquals "did not re-populate CHRUBY_RUBIES" 1 ${#CHRUBY_RUBIES[@]} - assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ - "$test_ruby_root" "${CHRUBY_RUBIES[0]}" + + if [[ -n "$ZSH_VERSION" ]]; then + assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ + "$test_ruby_root" "${CHRUBY_RUBIES[1]}" + else + assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ + "$test_ruby_root" "${CHRUBY_RUBIES[0]}" + fi } function test_chruby_help() From bc3b48f159c713d91068e3c34412b2f2e58ad51e Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 18 Jan 2023 17:29:06 -0800 Subject: [PATCH 47/52] Add the `CHRUBY_DIRS` env variable for configuring the directories to search. --- share/chruby/chruby.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 1f837b4d..fd376510 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -1,11 +1,12 @@ CHRUBY_VERSION="1.0.0" +CHRUBY_DIRS=("$PREFIX/opt/rubies" "$HOME/.rubies") function chruby_init() { local dir CHRUBY_RUBIES=() - for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do + for dir in "${CHRUBY_DIRS[@]}"; do if [[ -d "$dir" ]] && [[ -n "$(ls -A "$dir")" ]]; then CHRUBY_RUBIES+=("$dir"/*) fi From 8babfe521ec0621683faaa8cc441a347f07373f0 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 18 Jan 2023 18:08:50 -0800 Subject: [PATCH 48/52] Use `echo -n`. --- share/chruby/chruby.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index fd376510..01debb0a 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -25,7 +25,7 @@ function chruby_find() esac done - echo "$match" + echo -n "$match" } function chruby_reset() From 1afb1601c6a69718d98f03faff1d0d38721cb598 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 18 Jan 2023 18:09:07 -0800 Subject: [PATCH 49/52] Changed `chruby_find` to search `CHRUBY_DIRS` each time. * Added `chruby_list` to list the contents of `CHRUBY_DIRS`. * Removed `chruby_init` and the `--reload` option. * This prevents having to restart the shell after installing a new ruby. --- doc/man/chruby.1.md | 3 -- share/chruby/chruby.sh | 52 ++++++++++++++++++----------------- test/unit/chruby_find_test.sh | 31 +++++++++++++-------- test/unit/chruby_init_test.sh | 37 ------------------------- test/unit/chruby_test.sh | 46 ++++++++++--------------------- test/unit/helper.sh | 3 +- 6 files changed, 63 insertions(+), 109 deletions(-) delete mode 100755 test/unit/chruby_init_test.sh diff --git a/doc/man/chruby.1.md b/doc/man/chruby.1.md index 15a21962..56bd0b79 100644 --- a/doc/man/chruby.1.md +++ b/doc/man/chruby.1.md @@ -17,9 +17,6 @@ ## OPTIONS -`--reload` - Reloads the list of available Rubies - `-h`, `--help` `-v`, `--version` diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 01debb0a..2ad5245d 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -1,29 +1,32 @@ CHRUBY_VERSION="1.0.0" CHRUBY_DIRS=("$PREFIX/opt/rubies" "$HOME/.rubies") -function chruby_init() +function chruby_list() { - local dir + local rubies_dir ruby_dir - CHRUBY_RUBIES=() - for dir in "${CHRUBY_DIRS[@]}"; do - if [[ -d "$dir" ]] && [[ -n "$(ls -A "$dir")" ]]; then - CHRUBY_RUBIES+=("$dir"/*) - fi + for rubies_dir in "${CHRUBY_DIRS[@]}"; do + for ruby_dir in "${rubies_dir}"/*; do + if [[ -d "$ruby_dir" ]]; then + echo "$ruby_dir" + fi + done done } function chruby_find() { - local dir ruby match + local ruby_dir ruby_name match + + while IFS= read ruby_dir; do + ruby_dir="${ruby_dir%%/}" + ruby_name="${ruby_dir##*/}" - for dir in "${CHRUBY_RUBIES[@]}"; do - dir="${dir%%/}"; ruby="${dir##*/}" - case "$ruby" in - "$1") match="$dir" && break ;; - *"$1"*) match="$dir" ;; + case "$ruby_name" in + "$1") match="$ruby_dir" && break ;; + *"$1"*) match="$ruby_dir" ;; esac - done + done <<< $(chruby_list) echo -n "$match" } @@ -88,23 +91,24 @@ function chruby() { case "$1" in -h|--help) - echo "usage: chruby [--reload | RUBY|VERSION [RUBYOPT...] | system]" + echo "usage: chruby [RUBY|VERSION [RUBYOPT...] | system]" ;; -V|--version) echo "chruby: $CHRUBY_VERSION" ;; - --reload) chruby_init ;; "") - local dir ruby + local ruby_dir ruby_name - for dir in "${CHRUBY_RUBIES[@]}"; do - dir="${dir%%/}"; ruby="${dir##*/}" - if [[ "$dir" == "$RUBY_ROOT" ]]; then - echo " * ${ruby}${RUBYOPT:+ $RUBYOPT}" + while IFS= read ruby_dir; do + ruby_dir="${ruby_dir%%/}" + ruby_name="${ruby_dir##*/}" + + if [[ "$ruby_dir" == "$RUBY_ROOT" ]]; then + echo " * ${ruby_name}${RUBYOPT:+ $RUBYOPT}" else - echo " ${ruby}" + echo " ${ruby_name}" fi - done + done <<< $(chruby_list) ;; system) chruby_reset ;; *) @@ -121,5 +125,3 @@ function chruby() ;; esac } - -chruby_init diff --git a/test/unit/chruby_find_test.sh b/test/unit/chruby_find_test.sh index 8db65f53..2bf9d188 100755 --- a/test/unit/chruby_find_test.sh +++ b/test/unit/chruby_find_test.sh @@ -2,15 +2,19 @@ function setUp() { - test_ruby_path1="/path/to/ruby1" - test_ruby_path2="/path/to/ruby2" + test_ruby1="ruby1" + test_ruby2="ruby2" - CHRUBY_RUBIES=("$test_ruby_path1" "$test_ruby_path2") + test_ruby_path1="${test_root_dir}/opt/rubies/${test_ruby1}" + test_ruby_path2="${test_home_dir}/.rubies/${test_ruby2}" + + mkdir -p "$test_ruby_path1" + mkdir -p "$test_ruby_path2" } function test_chruby_find_with_exact_name() { - local exact_match="${test_ruby_path2##*/}" + local exact_match="${test_ruby2}" local result="$(chruby_find "$exact_match")" assertEquals "did not return the correct ruby dir" \ @@ -19,17 +23,16 @@ function test_chruby_find_with_exact_name() function test_chruby_find_with_exact_name_but_there_are_multiple_matches() { - CHRUBY_RUBIES=( - "$test_ruby_path1" - "${test_ruby_path1}-foo" - "$test_ruby_path2" - "${test_ruby_path2}-bar" - ) + mkdir -p "${test_root_dir}${test_ruby_path1}-foo" + mkdir -p "${test_home_dir}${test_ruby_path2}-bar" - local result="$(chruby_find "${test_ruby_path2##*/}")" + local result="$(chruby_find "$test_ruby2")" assertEquals "did not use the exact match first" \ "$test_ruby_path2" "$result" + + rmdir "${test_root_dir}${test_ruby_path1}-foo" + rmdir "${test_home_dir}${test_ruby_path2}-bar" } function test_chruby_find_with_a_substring() @@ -54,4 +57,10 @@ function test_chruby_find_when_cannot_find_match() assertEquals "did not return an empty string" "" "$result" } +function tearDown() +{ + rmdir "${test_ruby_path1}" + rmdir "${test_ruby_path2}" +} + SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/unit/chruby_init_test.sh b/test/unit/chruby_init_test.sh deleted file mode 100755 index e0e2c4e2..00000000 --- a/test/unit/chruby_init_test.sh +++ /dev/null @@ -1,37 +0,0 @@ -. ./test/unit/helper.sh - -function test_chruby_init_with_clean_env() -{ - unset CHRUBY_RUBIES - chruby_init - - assertEquals "did not reset CHRUBY_RUBIES" 1 ${#CHRUBY_RUBIES[@]} - - if [[ -n "$ZSH_VERSION" ]]; then - assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ - "$test_ruby_root" "${CHRUBY_RUBIES[1]}" - else - assertEquals "did not detect rubies in \$PREFIX/opt/rubies" \ - "$test_ruby_root" "${CHRUBY_RUBIES[0]}" - fi -} - -function test_chruby_init_with_modified_env() -{ - local new_path="/path/to/new/ruby" - - chruby_init - CHRUBY_RUBIES+=("$new_path") - - chruby_init - - if [[ -n "$ZSH_VERSION" ]]; then - assertEquals "did not reset CHRUBY_RUBIES" \ - "" "${CHRUBY_RUBIES[2]}" - else - assertEquals "did not reset CHRUBY_RUBIES" \ - "" "${CHRUBY_RUBIES[1]}" - fi -} - -SHUNIT_PARENT=$0 . $SHUNIT2 diff --git a/test/unit/chruby_test.sh b/test/unit/chruby_test.sh index 897cab0b..1124ec31 100755 --- a/test/unit/chruby_test.sh +++ b/test/unit/chruby_test.sh @@ -1,16 +1,11 @@ . ./test/unit/helper.sh -function setUp() -{ - original_rubies=("${CHRUBY_RUBIES[@]}") -} - function test_chruby_list_rubies() { local expected=" ${test_ruby_engine}-${test_ruby_version}" local output="$(chruby)" - assertEquals "did not correctly list CHRUBY_RUBIES" \ + assertEquals "did not correctly list the rubies in CHRUBY_DIRS" \ "$expected" "$output" } @@ -21,20 +16,27 @@ function test_chruby_list_rubies_when_a_ruby_is_active() local expected=" * ${test_ruby_engine}-${test_ruby_version}" local output="$(chruby)" - assertEquals "did not correctly list CHRUBY_RUBIES" \ + assertEquals "did not correctly list the rubies in CHRUBY_DIRS" \ "$expected" "$output" } function test_chruby_list_rubies_when_one_contains_a_space() { - local ruby_name="ruby" - local path_with_spaces="/path/with spaces/$ruby_name" + local ruby_name="ruby with spaces" + local ruby_dir="$test_home_dir/.rubies/$ruby_name" + mkdir -p "$ruby_dir" - CHRUBY_RUBIES=("$path_with_spaces") local output="$(chruby)" + local expected="$(cat < Date: Wed, 18 Jan 2023 18:26:39 -0800 Subject: [PATCH 50/52] Update the mock ruby to 3.0.0. --- test/unit/config.sh | 2 +- test/unit/configure | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/config.sh b/test/unit/config.sh index f5a5370e..20b2fabf 100644 --- a/test/unit/config.sh +++ b/test/unit/config.sh @@ -11,7 +11,7 @@ EOF )" else test_ruby_engine="${TEST_RUBY_ENGINE:-ruby}" - test_ruby_version="${TEST_RUBY_VERSION:-2.2.5}" + test_ruby_version="${TEST_RUBY_VERSION:-3.0.0}" test_ruby_root="$test_fixtures_dir/root/opt/rubies/$test_ruby_engine-$test_ruby_version" test_ruby_api="${TEST_RUBY_API:-${test_ruby_version%.*}.0}" test_gem_root="$test_ruby_root/lib/ruby/gems/$test_ruby_api" diff --git a/test/unit/configure b/test/unit/configure index a08ee75c..01f85d00 100755 --- a/test/unit/configure +++ b/test/unit/configure @@ -31,7 +31,7 @@ if [[ "\$1" == "-e" ]]; then echo \$PPID ;; "print RUBY_VERSION") - echo -n 2.2.5 + echo -n 3.0.0 ;; *) echo "error: no stub for ruby expression: '\$2'" >&2 From c29e407d0fd1c21f71c8658b54d7052e647cba80 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 18 Jan 2023 18:27:13 -0800 Subject: [PATCH 51/52] Use `read -r` to avoid interpreting backslases. --- share/chruby/chruby.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 2ad5245d..ca59b5b7 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -18,7 +18,7 @@ function chruby_find() { local ruby_dir ruby_name match - while IFS= read ruby_dir; do + while IFS= read -r ruby_dir; do ruby_dir="${ruby_dir%%/}" ruby_name="${ruby_dir##*/}" @@ -99,7 +99,7 @@ function chruby() "") local ruby_dir ruby_name - while IFS= read ruby_dir; do + while IFS= read -r ruby_dir; do ruby_dir="${ruby_dir%%/}" ruby_name="${ruby_dir##*/}" From ec5a12657f0ed9b49c292d75e359815f68a81f5f Mon Sep 17 00:00:00 2001 From: Postmodern Date: Wed, 18 Jan 2023 18:33:35 -0800 Subject: [PATCH 52/52] Always quote string arguments. --- share/chruby/chruby.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index ca59b5b7..c9e31ff0 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -26,7 +26,7 @@ function chruby_find() "$1") match="$ruby_dir" && break ;; *"$1"*) match="$ruby_dir" ;; esac - done <<< $(chruby_list) + done <<< "$(chruby_list)" echo -n "$match" } @@ -108,7 +108,7 @@ function chruby() else echo " ${ruby_name}" fi - done <<< $(chruby_list) + done <<< "$(chruby_list)" ;; system) chruby_reset ;; *)