Skip to content
Open

1.0.0 #474

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
19c1fb5
Version bump to 1.0.0.
postmodern Oct 30, 2019
fbfc551
updated formatting and env descriptions
havenwood Jan 15, 2013
d51fcdc
Renamed chruby.md to chruby.1.md.
postmodern Jan 15, 2013
a88a1c4
Moved docs/chruby.1 into share/man/man1/
postmodern Jan 15, 2013
0600f2c
Added a basic man page task.
postmodern Jan 15, 2013
8087055
added -v, --version to OPTIONS
havenwood Feb 12, 2013
7ce877c
Added chruby-exec(1) manpage to See Also section.
havenwood Mar 31, 2013
8976d1a
initial commit
havenwood Mar 31, 2013
24a286c
initial commit
havenwood Mar 31, 2013
531884b
Added chruby-exec(1) duplicates of chruby(1) entries.
havenwood Mar 31, 2013
11704d0
Use kramdown-man (https://github.com/postmodern/kramdown-man).
postmodern May 7, 2013
fe6e55c
Correct spelling typo.
havenwood Jun 15, 2013
d4f157e
Correct spelling typo.
havenwood Jun 15, 2013
d527ff0
Combined `man` tasks.
postmodern Nov 22, 2019
8af032e
Renamed the `man` task to `update-man`.
postmodern Nov 22, 2019
8345e48
Markdown formatting.
postmodern Nov 22, 2019
1ade2ee
Extracted the chruby ruby matching logic into chruby_find().
postmodern Sep 21, 2020
eb6683e
Added tests for chruby_find.
postmodern Sep 24, 2020
4e3ee1a
Extract the RUBIES listing logic into chruby_list.
postmodern Sep 21, 2020
fcefa1d
Added tests for chruby_list.
postmodern Sep 24, 2020
63a0f71
Renamed chruby_list to chruby_rubies.
postmodern Sep 24, 2020
cb862e0
Moved initialization logic into chruby_init.
postmodern Sep 24, 2020
1db88e8
Added the --reload option to re-initialize chruby.
postmodern Sep 24, 2020
7196ad1
Make the usage string more accurate.
postmodern Sep 24, 2020
1e7eaca
Added more tests for `chruby` listing capaibilities and how it handle…
postmodern Sep 24, 2020
8224fae
Only output $RUBYOPT if it's set.
postmodern Sep 24, 2020
0c5fcda
Test when chruby_use cannot find bin/ruby within the ruby.
postmodern Sep 24, 2020
9f7f844
Quote arguments.
postmodern Sep 24, 2020
2136de9
Renamed test_rubies to original_rubies.
postmodern Sep 24, 2020
f54bbeb
Move tearDown functions to the bottom.
postmodern Sep 24, 2020
edbf9cb
Moved some chruby matching tests into the chruby_find tests.
postmodern Sep 24, 2020
9ea0411
Use assertEquals.
postmodern Sep 24, 2020
262d745
Use better test names.
postmodern Sep 24, 2020
69caf3d
Added a test for `chruby --version`.
postmodern Sep 24, 2020
e930c38
Added a test for `chruby --help`.
postmodern Sep 24, 2020
5e35f5c
Ensure that chruby_init does not accidentally return 1.
postmodern Sep 24, 2020
99f639c
Renamed RUBIES to CHRUBY_RUBIES.
postmodern Sep 24, 2020
74e6936
Renamed RUBY_AUTO_VERSION to CHRUBY_AUTO_VERSION.
postmodern Sep 24, 2020
5c2abd0
80 columns.
postmodern Sep 24, 2020
c339d46
Curly braces go on the following line.
postmodern Sep 24, 2020
66d2360
Use local variables to indicate purpose of function arguments.
postmodern Sep 24, 2020
705bf1b
Replaced `chruby_rubies` with a simple for loop.
postmodern Sep 24, 2020
a97a8d8
Empty line after local variable definitions.
postmodern Sep 24, 2020
bd5b5cd
Renamed chruby_use to chruby_set.
postmodern Oct 7, 2020
b219bae
Fixed a failing test.
postmodern Sep 26, 2021
947ee85
Fix tests that were failing due to zsh indexing arrays starting at 1.
postmodern Sep 26, 2021
bc3b48f
Add the `CHRUBY_DIRS` env variable for configuring the directories to…
postmodern Jan 19, 2023
8babfe5
Use `echo -n`.
postmodern Jan 19, 2023
1afb160
Changed `chruby_find` to search `CHRUBY_DIRS` each time.
postmodern Jan 19, 2023
8ed5579
Update the mock ruby to 3.0.0.
postmodern Jan 19, 2023
c29e407
Use `read -r` to avoid interpreting backslases.
postmodern Jan 19, 2023
ec5a126
Always quote string arguments.
postmodern Jan 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME=chruby
VERSION=0.3.9
VERSION=1.0.0
AUTHOR=postmodern
URL=https://github.com/$(AUTHOR)/$(NAME)

Expand All @@ -22,6 +22,15 @@ all:
pkg:
mkdir $(PKG_DIR)

share/man/man1/chruby.1: doc/man/chruby.1.md
kramdown-man <doc/man/chruby.1.md >share/man/man1/chruby.1

share/man/man1/chruby-exec.1: doc/man/chruby-exec.1.md
kramdown-man <doc/man/chruby-exec.1.md >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
wget -O $(PKG) $(URL)/archive/v$(VERSION).tar.gz

Expand Down Expand Up @@ -80,4 +89,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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/chruby_use.sh → benchmarks/chruby_set.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
76 changes: 76 additions & 0 deletions doc/man/chruby-exec.1.md
Original file line number Diff line number Diff line change
@@ -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 arguments 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)
95 changes: 95 additions & 0 deletions doc/man/chruby.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# chruby(1) -- Changes the current Ruby.

## SYNOPSIS

`chruby` [OPTIONS | <RUBY|VERSION> [<RUBY_OPTS>] | system]

## 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 arguments to pass to Ruby.

## OPTIONS

`-h`, `--help`

`-v`, `--version`

## 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_set /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
chruby-exec(1), ruby(1), gem(1)
14 changes: 8 additions & 6 deletions share/chruby/auto.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unset RUBY_AUTO_VERSION
unset CHRUBY_AUTO_VERSION

function chruby_auto() {
function chruby_auto()
{
local dir="$PWD/" version

until [[ -z "$dir" ]]; do
Expand All @@ -9,18 +10,19 @@ 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
}

Expand Down
85 changes: 54 additions & 31 deletions share/chruby/chruby.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
CHRUBY_VERSION="0.3.9"
RUBIES=()
CHRUBY_VERSION="1.0.0"
CHRUBY_DIRS=("$PREFIX/opt/rubies" "$HOME/.rubies")

for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do
[[ -d "$dir" && -n "$(command ls -A "$dir")" ]] && RUBIES+=("$dir"/*)
done
unset dir
function chruby_list()
{
local rubies_dir ruby_dir

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 ruby_dir ruby_name match

while IFS= read -r ruby_dir; do
ruby_dir="${ruby_dir%%/}"
ruby_name="${ruby_dir##*/}"

case "$ruby_name" in
"$1") match="$ruby_dir" && break ;;
*"$1"*) match="$ruby_dir" ;;
esac
done <<< "$(chruby_list)"

echo -n "$match"
}

function chruby_reset()
{
Expand All @@ -30,16 +55,18 @@ function chruby_reset()
hash -r
}

function chruby_use()
function chruby_set()
{
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"

Expand All @@ -64,41 +91,37 @@ function chruby()
{
case "$1" in
-h|--help)
echo "usage: chruby [RUBY|VERSION|system] [RUBYOPT...]"
echo "usage: chruby [RUBY|VERSION [RUBYOPT...] | system]"
;;
-V|--version)
echo "chruby: $CHRUBY_VERSION"
;;
"")
local dir ruby
for dir in "${RUBIES[@]}"; do
dir="${dir%%/}"; ruby="${dir##*/}"
if [[ "$dir" == "$RUBY_ROOT" ]]; then
echo " * ${ruby} ${RUBYOPT}"
local ruby_dir ruby_name

while IFS= read -r 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 ;;
*)
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

if [[ -z "$match" ]]; then
echo "chruby: unknown Ruby: $1" >&2
local ruby="$1"
local ruby_dir="$(chruby_find "$ruby")"

if [[ -z "$ruby_dir" ]]; then
echo "chruby: unknown Ruby: $ruby" >&2
return 1
fi

shift
chruby_use "$match" "$*"
chruby_set "$ruby_dir" "$*"
;;
esac
}
Loading
Loading