Code Monkey home page Code Monkey logo

chruby's Introduction

Software Engineer, Rubyist, Open Source Maintainer.

Languages

Ruby, Crystal, Bash, and sometimes C, C++, Java, XML/XSLT, HTML5, CSS4, JavaScript (ES6).

Status

Currently taking the rest of the year off to work on Open Source. See my GitHub Sponsor page for my plans/progress.

Projects

Stats

postmodern's github stats postmodern's top-languages stats

chruby's People

Contributors

andrewvos avatar davidegrayson avatar egh avatar erkhembayar-gantulga avatar franklinyu avatar havenwood avatar hosiawak avatar hovsater avatar ilikepi avatar julienxx avatar kbrock avatar ku1ik avatar marcosdsanchez avatar michaelrkn avatar mpapis avatar mrkcor avatar okuramasafumi avatar postmodern avatar pushcx avatar rosstimson avatar shireeshj avatar skorfmann avatar slumos avatar spastorino avatar steveklabnik avatar swrobel avatar terotil avatar tmatilai avatar tsujigiri avatar vmrocha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chruby's Issues

sh: /usr/local/ruby-1.9.3-p327: is a directory

When I try to run the tests for activemodel, this happens:

$ bundle exec rake test
/usr/local/ruby-1.9.3-p327 -w -I"lib:test" -I"/Users/steve/.gem/ruby/1.9.3/gems/rake-10.0.3/lib" "/Users/steve/.gem/ruby/1.9.3/gems/rake-10.0.3/lib/rake/rake_test_loader.rb" "/Users/steve/src/rails/activemodel/test/cases/attribute_methods_test.rb" "/Users/steve/src/rails/activemodel/test/cases/callbacks_test.rb" "/Users/steve/src/rails/activemodel/test/cases/conversion_test.rb" "/Users/steve/src/rails/activemodel/test/cases/deprecated_mass_assignment_security_test.rb" "/Users/steve/src/rails/activemodel/test/cases/dirty_test.rb" "/Users/steve/src/rails/activemodel/test/cases/errors_test.rb" "/Users/steve/src/rails/activemodel/test/cases/forbidden_attributes_protection_test.rb" "/Users/steve/src/rails/activemodel/test/cases/lint_test.rb" "/Users/steve/src/rails/activemodel/test/cases/model_test.rb" "/Users/steve/src/rails/activemodel/test/cases/naming_test.rb" "/Users/steve/src/rails/activemodel/test/cases/railtie_test.rb" "/Users/steve/src/rails/activemodel/test/cases/secure_password_test.rb" "/Users/steve/src/rails/activemodel/test/cases/serialization_test.rb" "/Users/steve/src/rails/activemodel/test/cases/serializers/json_serialization_test.rb" "/Users/steve/src/rails/activemodel/test/cases/serializers/xml_serialization_test.rb" "/Users/steve/src/rails/activemodel/test/cases/translation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/absence_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/acceptance_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/callbacks_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/conditional_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/confirmation_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/exclusion_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/format_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/i18n_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/inclusion_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/length_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/numericality_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/presence_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/validates_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/validations_context_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/with_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations_test.rb" 
sh: /usr/local/ruby-1.9.3-p327: is a directory
rake aborted!

Which, of course, it is! Everything outside of that seems to work though:

$ bundle exec ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]

Ideas?

Optionally support auto-switching

Many users have requested the ability to automatically switch to a Ruby when entering a directory which contains a .ruby-version file. While in the directory and all sub-directories, the Ruby should remain set. Only when the user ascends the directory containing the .ruby-version file should chruby switch back to system Ruby.

This feature is optional and would be enabled by loading /usr/local/share/chruby/auto.sh.

chruby problem with tmux

chruby won't work when starting tmux.

Steps te reproduce:

  1. Put a default ruby in your .zshrc or .zlogin
  2. Run tmux
  3. chruby lists your default ruby as being used, but PATH variables are not set. First you must do chruby system to unset all variables and then change back to your default version

Clarification

chruby looks interesting, but I am confused on one issue. chruby lets one switch between rubies but how do these rubies get built?

Default ruby

Should we support a default ruby? Currently users have to add chruby 1.9 to their ~/.bashrc or global config. Alternatively, users could run chruby $(cat ~/.ruby)?

Proof of concept for automatic, bundler-managed gemsets

Using the same basic function as chruby_auto I created gemsets based on the Gemfile's parent directory name and replace the entire GEM environment variables with that single gem location.

Logically assuming all Gemfiles have a corresponding gemset means shim-less, bundler-managed gems.

https://github.com/daytonn/chruby/blob/automatic-gemsets/scripts/gemsets.sh

This needs tests and could be refactored into a shared function that chruby_auto could also use.

This is a proof of concept.

Thoughts?

"make install" fails on Ubuntu 12.04

When attempting to install, I see this:

vagrant@ubuntu-12-04:~/chruby-0.2.2$ sudo make install
vagrant@ubuntu-12-04:~/chruby-0.2.2$ ls /usr/local/share/chruby
ls: cannot access /usr/local/share/chruby: No such file or directory

make is using sh, which doesn't like the "{etc,lib,bin,sbin,share}" shell expansion. Changing the shell to bash in the Makefile fixes it:

vagrant@ubuntu-12-04:~/chruby-0.2.2$ echo "SHELL:=/bin/bash" | cat - Makefile > Makefile.bash
vagrant@ubuntu-12-04:~/chruby-0.2.2$ sudo make -f Makefile.bash install
vagrant@ubuntu-12-04:~/chruby-0.2.2$ ls /usr/local/share/chruby
chruby.sh

I'm not sure if changing the shell is the best approach, but it works.

Examples all talk about /opt

Everything says something like:

To install put this in your .zshrc:

RUBIES=(
/opt/ruby-1.9.3
)

or whatever. But it doesn't actually install them into /opt. The setup script puts them in /usr/local/, maybe that's a better example?

Unable to list available rubies

Hello,

I'm trying to use chruby but I encountered a problem. Here how I install chruby:

$ git clone https://github.com/postmodern/chruby .chruby
$ cd .chruby
$ sudo make install
$ vim ~/.zshrc
# ...
$ exec $SHELL
$ ls ~/.rubies
2.0.0  2.0.0-dev  rbx-2.0.0
$ chruby
  *
$

Here what I have added to my .zshrc file:

. /usr/local/share/chruby/chruby.sh
RUBIES=~/.rubies/*

My problem is why chruby doesn't list .rubies directory ? I'm using Z-Shell on my computer.

Thanks. Have a nice day.

API Modification Proposal

Much of this is based on ideas for an API change to ruby-version; however, there are some great ideas in current chruby and in pending issues so would be happy to see chruby implement something like this.

See #29 and #30.

The idea is to use sub-commands which should help to keep the API simple (less assumptions need to be made at runtime).

configure multiple ruby directories

$RUBIES=()

change to an installed ruby

% chruby use jruby-1.7.0

change to an installed ruby (fuzzy match)

% chruby use jruby

change to an installed ruby and set options

% chruby use ruby-1.9.3-p327 '-w rake'
  • RUBYOPT=-w rake
  • RBXOPT=-X19

change to the system ruby

% chruby use --system

change to an installed ruby from file

% chruby use $(cat .ruby-version)

NOTE: zsh/bash users can use optional chpwd/cd hooks (load from share directory)

list rubies (star next to current)

% chruby list

help system

% chruby help
% chruby help use
% chruby help list

Upgraded and moved Rubies, now can't load

I upgraded to the last version, but I also move my rubies from /opt/Ruby to ~/.rubies, now I get:

<internal:gem_prelude>:1:in `require': cannot load such file -- rubygems.rb (LoadError)
    from <internal:gem_prelude>:1:in `<compiled>'
<internal:gem_prelude>:1:in `require': cannot load such file -- rubygems.rb (LoadError)
    from <internal:gem_prelude>:1:in `<compiled>'

Add bash completion

This works for me:

__complete_chruby() {
  local cur rubie basenames
  typeset -a basenames
  cur="${COMP_WORDS[COMP_CWORD]}"
  for rubie in ${RUBIES[@]}; do
    basenames+=($(basename $rubie))
  done
  COMPREPLY=( $(compgen -W "${basenames[*]}" -- ${cur}) )
}
complete -F __complete_chruby chruby

I added it to chruby.sh, but maybe you want to do it differently to also support zsh?

Duplicate `chruby_auto` entries in PROMPT_COMMAND

It appears that auto.sh will add duplicates of the chruby_auto function to the PROMPT_COMMAND because if there is an existing PROMPT_COMMAND it assumes that chruby_auto is not in the PROMPT_COMMAND.

It needs a check for existing chruby_auto. Something like this:

if [ -z "$(echo $PROMPT_COMMAND | grep chruby_auto)" ] ; then
  PROMPT_COMMAND="$PROMPT_COMMAND; chruby_auto"
fi

chruby_exec() function

Would it be possible to implement a function that executes a ruby script directly from one or multiple Ruby versions? This would be come handy when writing open source Ruby libraries that should be tested against multiple Rubies.

For example:

chruby_exec <RUBIES> <COMMAND..>
chruby_exec 1.9.3,1.8.7,jruby,rbx rspec ./spec

This would then run each individual Ruby against RSpec. This would also allow for integration with automated testing tools like Guard::RSpec where it would run each test against any of the specified Rubies on save.

sudo and setup.rb

I have a couple ruby libraries that need to be installed the old-fashioned way, with setup.rb. But when I do so they always install to the system Ruby and not the chruby ruby. I am pretty sure the reason is b/c I have to use sudo ./setup.rb b/c my ruby is installed in /opt/Ruby/1.9.3-p327. So unless I use sudo I get a permission error. But if I use sudo, then it makes a different shell for root where chruby isn't being used.

Seems like site_ruby (and maybe vendor_ruby?) should be pointing to a local "home" just like $GEM_HOME does. But is that doable? And if not how do I work around this?

Install Guides and the FHS

I was looking at your install scripts of the wiki (e.g. https://github.com/postmodern/chruby/wiki/MRI) and I'm pretty sure they go against the FHS. Quote:

No other directories, except those listed below, may be in /usr/local after
first installing a FHS-compliant system.

See http://refspecs.linuxfoundation.org/FHS_2.3/fhs-2.3.html#USRLOCALLOCALHIERARCHY

To follow the FHS I think it would instead need to be:

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar -xzvf ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327
./configure --prefix=/usr/local/
make
sudo make install
cd ..
sudo mv ruby-1.9.3-p327 /usr/local/src/

If you want to keep the installation encapsulated, then the most appropriate location is /opt. Something like:

sudo mkdir /opt/ruby-1.9.3-p327
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar -xzvf ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327
./configure --prefix=/opt/ruby-1.9.3-p327/
make
sudo make install
sudo mv ruby-1.9.3-p327 /opt/ruby-1.9.3-p327/src

Errors encountered running chruby-exec in Ubuntu

In Ubuntu, /bin/sh points to dash and this seems to be the cause of the ff. errors encountered when running chruby-exec:

/usr/local/bin/chruby-exec: 10: /usr/local/bin/chruby-exec: [[: not found
/usr/local/bin/chruby-exec: 15: /usr/local/bin/chruby-exec: Syntax error: "(" unexpected

/etc/profile.d/chruby.sh graphical login issue with Ubuntu 12.04

When using scripts/setup.sh to install chruby on Ubuntu 12.04 it adds /etc/profile.d/chruby.sh after which I can no longer login on Unity (regardless of my default shell, I tried both with bash and zsh). On my system I deleted /etc/profile.d/chruby.sh and added the source command to my ~/.zshrc and am now able to login without issue and use chruby.

Write a Quickstart Guide for installing various Rubies

chruby needs a Quickstart guide for installing various Rubies. The guide should contain copy/pastable commands. The guide should also include brew/apt-get/yum commands for installing various dependencies needed to build the Rubies.

Avoid version specific path to chruby.sh in ~/.profile and others

What I got after installing:

Add chruby to ~/.bashrc or ~/.profile:

  . /usr/local/Cellar/chruby/0.2.3/share/chruby/chruby.sh

  RUBIES=(~/.rbenv/versions/*)

Binaries in Homebrew are linked into /usr/local to avoid this problem. I'm not sure if it's possible to do it for other files like chruby.sh, but if it's possible, I think it would be a good solution.

$RUBY variable conflicts with rake 10

Rake 10 (at least, I haven't checked other versions) uses ENV['RUBY'] as the location of the current ruby binary (https://github.com/jimweirich/rake/blob/master/lib/rake/file_utils.rb#L9). Whereas chruby uses it to point to the directory the current ruby sits in. This causes errors when I run rake (for example, I see "sh: /usr/local/ruby/mri-1.9.3-p194 is a directory").

I changed all references to RUBY in the chruby script to CURRENT_RUBY which got me going. I'm not submitting a patch because I expect you'll want something that looks nicer in code. I just needed to solve the problem.

zsh compatibility

Currently, chruby does not work in zsh. Some ideas:

  • The eval $(chruby --init) hack.
  • Write separate scripts for bash, zsh, etc.
  • Rewrite chruby to only use POSIX shell scripting syntax.

Not a git repository

Failed at make install:

[22:02][christopher@ryleh:~/Downloads/chruby-0.2.1]$ make install
fatal: Not a git repository (or any of the parent directories): .git
for dir in `find {etc,lib,bin,sbin,share} -type d 2>/dev/null`; do install -d /usr/local/$dir; done
for file in `find {etc,lib,bin,sbin,share} -type f 2>/dev/null`; do install $file /usr/local/$file; done
install -d /usr/local/share/doc/chruby-0.2.1
cp -r doc/* *.{md,tt,txt} /usr/local/share/doc/chruby-0.2.1/ 2>/dev/null || true

DOC_FILES is not set when running make install on OpenBSD

$ make install
for dir in ; do install -d /home/dentarg/local/$dir; done
for file in ; do install $file /home/dentarg/local/$file; done
install -d /home/dentarg/local/share/doc/chruby-0.2.3
cp -r  /home/dentarg/local/share/doc/chruby-0.2.3/
usage: cp [-fip] [-R [-H | -L | -P]] source target
       cp [-fip] [-R [-H | -L | -P]] source ... directory
*** Error code 1

Stop in /home/dentarg/src/chruby-0.2.3 (line 44 of Makefile).

(Yes, I changed PREFIX in the Makefile before doing make install.)

I'm not sure why this is happening. I'm on OpenBSD 5.2 and using zsh 4.3.17 (i386-unknown-openbsd5.2).

Is this the reason?

zsh:

$ find *.md *.tt *.txt 2>/dev/null
zsh: no matches found: *.tt

sh:

$ find *.md *.tt *.txt 2>/dev/null
ChangeLog.md
README.md
LICENSE.txt

I get the same result ("no matches found") when trying the find command in zsh on OS X but make install works fine. I'm confused.

no exec for sourced files

Hi there,

is there any reason why

/usr/bin/share/chruby/auto.sh
/usr/bin/share/chruby/chruby.sh

need to be executable?
I thought they are sourced by the user.

Cheers
dg

Newly installed ruby not listed in chruby

After successfully installed a ruby version using ruby-build, chruby does not update the installed ruby list:

$ chruby
   jruby-1.7.2
   ruby-1.8.7-p371
 * ruby-1.9.3-p362

$ ruby-build -v 2.0.0-preview2 ~/.rubies/2.0.0-preview2
...
...
Installed ruby-2.0.0-preview2 to ~/.rubies/2.0.0-preview2

$ chruby
   jruby-1.7.2
   ruby-1.8.7-p371
 * ruby-1.9.3-p362

Currently, my workaround is to reopen a new terminal to see the updated list. Does it happen to anyone else here?

Sed

Hey man!

awesome! I'll try to use it since is very very thin an compact, I love it.

Btw I saw some sed commands, Isn't more intuitive use simples shell commands like:

${GEM_HOME/:foo:/:bar:}

Another awesome thing should be autocomplete ;)

Bundler::GemNotFound

This may be similar to #79 but I'm not sure.

When I call chruby 1.9.3-p362, I immediately get:

/Library/Ruby/Gems/1.8/gems/bundler-1.2.3/lib/bundler/spec_set.rb:90:in `block in materialize': Could not find i18n-0.6.1 in any of the sources (Bundler::GemNotFound)

But chruby changes to ruby 1.9.3 just fine, all my gems are there for that ruby version, and my apps behave properly.

This could be a bundler issue, too?

Handling Goboliunx package manager style

I think chroot would be a perfect fit for Gobolinux style package management (also others like stow). But there is an issue. Gobolinux installs packages like so:

Programs/
  Ruby/
    1.8.7-p358/
    1.9.3-p327/
  JRuby/
    1.4.0/

And so forth. So the problem with chruby, when I set:

RUBIES=(/Programs/{Ruby,JRuby,Rubinius}/*)

Then running chruby produces:

  1.8.7-p358
  1.9.3-p327
  1.4.0

So the different implementations can't be distinguished. Note also, there may be a Current soft-link in each implementation directory pointing to which ever is the current version in use, e.g.

Programs/
  Ruby/
    1.8.7-p358/
    1.9.3-p327/
    Current -> ./1.9.3-p327

I'm moving over to this package manager so I would like to get this to work.

add a chruby-exec bin script

Add a chruby-exec bin script that would select the desired ruby, then run another command under it.

chruby-exec jruby --1.9 -- command

This would be useful for people needing to run Ruby scripts via cron jobs.

The env variable 'export' gets set by chruby

Environment:

  • zsh 5.0.1 (x86_64-apple-darwin12.2.1)
  • chruby 0.3.0 (reproduced with 464bfc2)

Problem:

  • After running chruby for the first time, the environment variable 'export' is set to the empty string.

Diagnostics:

diff -U0 <(env) <(chruby 1.9.3-p327;env)
--- /dev/fd/14  2012-12-22 02:20:52.000000000 +0100
+++ /dev/fd/15  2012-12-22 02:20:52.000000000 +0100
@@ -1 +1 @@
-PATH=/Users/pierre/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
+PATH=/Users/pierre/.gem/ruby/1.9.3/bin:/Users/pierre/.rubies/1.9.3-p327/lib/ruby/gems/1.9.1/bin:/Users/pierre/.rubies/1.9.3-p327/bin:/Users/pierre/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
@@ -28,0 +29,8 @@
+RUBY_ROOT=/Users/pierre/.rubies/1.9.3-p327
+RUBYOPT=
+RUBY_ENGINE=ruby
+RUBY_VERSION=1.9.3
+export=
+GEM_ROOT=/Users/pierre/.rubies/1.9.3-p327/lib/ruby/gems/1.9.1
+GEM_HOME=/Users/pierre/.gem/ruby/1.9.3
+GEM_PATH=/Users/pierre/.gem/ruby/1.9.3:/Users/pierre/.rubies/1.9.3-p327/lib/ruby/gems/1.9.1
zsh: exit 1     diff -U0 <(env) <(chruby 1.9.3-p327;env)

Bundler not found

I've been setting up a Radiant site this week and ran into an odd issue. When I ran rake db:bootstrap it told me Bundler wasn't installed. But of course, it is and I had already run bundle install just fine. So I did a chruby system and redid it and it worked fine.

I am not sure if this is solely a Radiant issue or whether it is a broader issue stemming from Rails.

Setup a website

A website would be nice. Also now that GitHub / @kneath disabled Downloads, we will need a location to store properly named releases (chruby-v0.2.3.tar.gz, not v0.2.3.tar.gz) and PGP signatures.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.