├── test ├── project │ ├── sub_dir │ │ └── .gitkeep │ ├── bad │ │ └── .ruby-version │ ├── .ruby-version │ ├── bad2 │ │ └── .ruby-version │ ├── modified_version │ │ └── .ruby-version │ └── sub_versioned │ │ └── .ruby-version ├── home │ ├── .gem │ │ └── ruby │ │ │ ├── 2.1.0 │ │ │ └── bin │ │ │ │ └── .keep │ │ │ └── 2.1.1 │ │ │ └── bin │ │ │ └── .keep │ └── .config │ │ └── fish │ │ └── config.fish ├── helper.sh ├── chruby_use_test.fish ├── helper.fish ├── runner ├── chruby_reset_test.fish ├── chruby_test.fish ├── chruby_auto_test.fish └── setup ├── .gitignore ├── .travis.yml ├── homebrew └── chruby-fish.rb ├── pkg ├── chruby-fish-0.5.2.tar.gz.asc ├── chruby-fish-0.5.3.tar.gz.asc ├── chruby-fish-0.5.4.tar.gz.asc └── chruby-fish-0.6.0.tar.gz.asc ├── LICENSE ├── ChangeLog.md ├── Makefile ├── share └── chruby │ ├── auto.fish │ └── chruby.fish └── README.md /test/project/sub_dir/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/home/.gem/ruby/2.1.0/bin/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/home/.gem/ruby/2.1.1/bin/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/project/bad/.ruby-version: -------------------------------------------------------------------------------- 1 | foo 2 | -------------------------------------------------------------------------------- /test/project/.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-2.1 2 | -------------------------------------------------------------------------------- /test/project/bad2/.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-2.1.1 -v 2 | -------------------------------------------------------------------------------- /test/project/modified_version/.ruby-version: -------------------------------------------------------------------------------- 1 | 2.1 2 | -------------------------------------------------------------------------------- /test/project/sub_versioned/.ruby-version: -------------------------------------------------------------------------------- 1 | system 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | test/opt 3 | test/fish_binaries 4 | test/**/fishd.* 5 | pkg/*.tar.gz 6 | -------------------------------------------------------------------------------- /test/home/.config/fish/config.fish: -------------------------------------------------------------------------------- 1 | set -gx original_path $PATH 2 | set -gx PATH $PATH /usr/local/bin /usr/bin /usr/sbin /bin /sbin 3 | 4 | . $PWD/test/helper.fish 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | 3 | install: 4 | - brew update 5 | - brew install chruby 6 | - git clone git://github.com/terlar/fish-tank.git 7 | - cd fish-tank 8 | - sudo make install 9 | - cd .. 10 | 11 | before_script: 12 | - echo yes | rvm implode 13 | - __rvm_unload 14 | - sudo mkdir -p /usr/gnu/bin 15 | 16 | script: 17 | - make test 18 | -------------------------------------------------------------------------------- /homebrew/chruby-fish.rb: -------------------------------------------------------------------------------- 1 | require 'formula' 2 | 3 | class ChrubyFish < Formula 4 | homepage 'https://github.com/JeanMertz/chruby-fish#readme' 5 | url 'https://github.com/JeanMertz/chruby-fish/archive/v0.6.0.tar.gz' 6 | sha1 'e8262283018137db89ba5031ec088a5df3df19d0' 7 | 8 | head 'https://github.com/JeanMertz/chruby-fish.git' 9 | 10 | depends_on 'chruby' => :recommended 11 | 12 | def install 13 | system 'make', 'install', "PREFIX=#{prefix}" 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /pkg/chruby-fish-0.5.2.tar.gz.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP SIGNATURE----- 2 | Version: GnuPG v1 3 | 4 | iQEcBAABAgAGBQJTVvujAAoJENQeLCdg9OD0tx8H/RPfsFe1jPDmZcDtG9i6m85W 5 | JOV9ibVioXfATnwiRxntACJNpDRYUstAHeaqcJvf9qRhk2OD0cx5/2XMQGDixS3U 6 | jzrdxF9YhVT2D3IlspB4hOHuO7hxE2BgBIQwPrzArwAM7O5ymTtwK9xw+i0Irsqc 7 | Am3JAACPEPGWf09oRM0ypISzXG96V6LmvQNW94ymjvLH+EKFf45/bg35MFUJMV85 8 | fE3R5maPwAXexF9VXii55NmluJRimKRiUgmCUESeOFOUgmWmkxu1aI5HBCjLRYT6 9 | 5lO6eGL77/Gl83LNpTpJFaUhKTaAADmzsElUQOBe3aVtFX5wnMr9vN8ZWy+HLO4= 10 | =1pUE 11 | -----END PGP SIGNATURE----- 12 | -------------------------------------------------------------------------------- /pkg/chruby-fish-0.5.3.tar.gz.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP SIGNATURE----- 2 | Version: GnuPG v1 3 | 4 | iQEcBAABAgAGBQJTWhmlAAoJENQeLCdg9OD0iJUH/16EJ1cDnvT5/M1uIrqjmLsf 5 | Wnz8exEl1KZI3BTL/v6fxN6a1V+5LxTQXbCMF1DASZAHi8ntlha0eBQWC7OfAiay 6 | iix10/jdL3iQ0EEDHtBb+oWoE2ofseG8FWRMkfMY2D2V0vtb0nklwWghguPOpgUD 7 | vJYjxVOkv0UH1WJqW1S7cOM4Ul/+OLHS+XzqbZnGf74V5PMdRWct9/cx3QeNblya 8 | xgcObvILQohRBZ596upwT0SUCZ6ykZg8K9EFym16hPNT82dj8lD7/O9tO6nkNI/e 9 | dw2wYFVYWsprZ5dpSYeI+UP8VA19V/i6qBB4BG+yYyPHJuIRGnLucn2xImDLRP8= 10 | =hhit 11 | -----END PGP SIGNATURE----- 12 | -------------------------------------------------------------------------------- /pkg/chruby-fish-0.5.4.tar.gz.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP SIGNATURE----- 2 | Version: GnuPG v1 3 | 4 | iQEcBAABAgAGBQJTW8FpAAoJENQeLCdg9OD0AuIH/1BMU2LW14PGjcQVvqcJnLp8 5 | pYI65cJtklGk6zawz/5lBp0cWNu6teswC8Nsytri7WaqSBvO6aJ6J5xMUBk/+j5/ 6 | KCq4bpex7bgknjMOhMjGWMTjL0Cp0RF+wxRpIWcjmHpfR55ujWt/Uefr9LBOwi1u 7 | klHGXJZXhWrPfuTRt77CM9HlbZVwjQD7VV4YJUoSko6asb5homzfXFPa9X1z9Drh 8 | FWTz+iGbgYYYjFBJkYYHlYpcmLjXdB7Nk6o0rsqG92Hsf67A+baeog+wyCTXy16z 9 | QGBJcxq1YWunAIwSZ1qn9J57fL5TXvKh+AFjJuBT1jC7JktHKSmj+BBL+er3PYc= 10 | =Hqyz 11 | -----END PGP SIGNATURE----- 12 | -------------------------------------------------------------------------------- /test/helper.sh: -------------------------------------------------------------------------------- 1 | export PREFIX="$PWD/test" 2 | export HOME="$PREFIX/home" 3 | export PATH="$PWD/bin:$PATH" 4 | 5 | . /usr/local/share/chruby/chruby.sh 6 | chruby_reset 7 | 8 | test_ruby_engine="ruby" 9 | test_ruby_version=$([[ $(uname) = 'Darwin' ]] && echo '2.1.1' || echo '2.1.0') 10 | test_ruby_api="2.1.0" 11 | test_ruby_root="$PWD/test/opt/rubies/$test_ruby_engine-$test_ruby_version" 12 | 13 | test_path="$PATH" 14 | test_gem_home="$HOME/.gem/$test_ruby_engine/$test_ruby_version" 15 | test_gem_root="$test_ruby_root/lib/ruby/gems/$test_ruby_api" 16 | 17 | test_project_dir="$PWD/test/project" 18 | -------------------------------------------------------------------------------- /test/chruby_use_test.fish: -------------------------------------------------------------------------------- 1 | function suite_chruby_use 2 | function setup 3 | chruby_use $test_ruby_version 4 | end 5 | 6 | function teardown 7 | chruby_reset 8 | end 9 | 10 | function test_chruby_use 11 | assert_equal "$test_ruby_root" "$RUBY_ROOT" 12 | assert_equal "$test_ruby_engine" "$RUBY_ENGINE" 13 | assert_equal "$test_ruby_version" "$RUBY_VERSION" 14 | assert_equal "$test_ruby_root/lib/ruby/gems/$test_ruby_api" "$GEM_ROOT" 15 | assert_equal "$test_ruby_root/bin/ruby" (which ruby) 16 | assert_equal "$test_gem_home" "$GEM_HOME" 17 | assert_equal "$GEM_HOME:$GEM_ROOT" "$GEM_PATH" 18 | assert_equal "$test_gem_home/bin $test_gem_root/bin $test_ruby_root/bin $test_path" "$PATH" 19 | end 20 | end 21 | 22 | if not set -q tank_running 23 | . (dirname (status -f))/helper.fish 24 | tank_run 25 | exit $status 26 | end 27 | -------------------------------------------------------------------------------- /pkg/chruby-fish-0.6.0.tar.gz.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP SIGNATURE----- 2 | Version: GnuPG/MacGPG2 v2.0.22 (Darwin) 3 | 4 | iQIcBAABCgAGBQJTexedAAoJEEq8LXIq/A23sY4P/jakU7jLCLv6bW4KwNPjukyl 5 | QfquMLNiKTUT+VdrUcy8VE0X5+WbPVc6Untcq6M+L/z3cm0v5IqGsEyiqCJclCwQ 6 | GlqDpqPrbP5fq8iR3B+PPKyWDQOQYKef0Bb6nb4zXBWiYmtlxdjpJbu7wcFjvCDY 7 | roP0ElwdKTCSVok+393dj7YXuQwuDw84R+JTQU5vYo/KN6YNMtJeIo1RNSljrbAv 8 | HfByPje0xP1OENoE3YAgyoJFEGrFO7vjoiZGDczcFOnv2w7c+6TQhbTJ5EgzYuL0 9 | gzVWwq/vKfUEYo4zWCd5LchUU2eP+Y0jopax6CdlUjnLNmCKIL3McUnbblPIvHXG 10 | vTpIyVa8Q297NBaTJ3u0TUiwBv/jXE0TKAm1aCUtQuRJC/6s0WghTwVB3sksp07t 11 | fk/buoe5ym6nx6Qvq0FHbEF+EadciVoktHyMK8W/cxg/A4XXXJfnD5Mvero3b8ch 12 | c9oB19jhJv0AW21r0Z2s4AN51NRG8bMmA9UUPTtyK3Hpw8p2dodz2v1qTgb/22A9 13 | cCdNaqeA6renBPUZ61dpay68dTvwyWW3yj8/EW4p2aI5U9Cz/JKj385qvqV5Za1G 14 | JACdxxC0qWnWENKK7ue3D9uoa85RZIszSsKC6L0zLkJP6OoEl4sIIQHwtmBKmvCt 15 | 8n6Ar+dxEj6e11QVvPjh 16 | =JKtF 17 | -----END PGP SIGNATURE----- 18 | -------------------------------------------------------------------------------- /test/helper.fish: -------------------------------------------------------------------------------- 1 | set -gx PREFIX "$PWD/test" 2 | set -g original_path $PATH 3 | set -g original_rubies $RUBIES 4 | 5 | set -l fish_tank /usr/local/share/fish-tank/tank.fish 6 | if not test -e $fish_tank 7 | echo 'error: fish-tank is required to run these tests (https://github.com/terlar/fish-tank)' 8 | exit 1 9 | end 10 | 11 | . $fish_tank 12 | . (dirname (status -f))/../share/chruby/chruby.fish 13 | chruby_reset 14 | 15 | set -g test_ruby_engine 'ruby' 16 | set -g test_ruby_version (test (uname) = 'Darwin'; and echo '2.1.1'; or echo '2.1.0') 17 | set -g test_ruby_api '2.1.0' 18 | set -g test_ruby_root "$PWD/test/opt/rubies/$test_ruby_engine-$test_ruby_version" 19 | 20 | set -g test_path $PATH 21 | set -g test_gem_home "$HOME/.gem/$test_ruby_engine/$test_ruby_version" 22 | set -g test_gem_root "$test_ruby_root/lib/ruby/gems/$test_ruby_api" 23 | 24 | set -g test_project_dir "$PWD/test/project" 25 | 26 | # reset to original state after finishing tests 27 | function reset_system_defaults -e tank_finished 28 | set -gx PATH $original_path 29 | set -e original_path 30 | set -q original_prefix; and set -gx PREFIX $original_prefix 31 | end 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jean Mertz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/runner: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/fish 2 | 3 | set -q PREFIX; and set -g original_prefix $PREFIX 4 | set -gx PREFIX "$PWD/test" 5 | set test_status 0 6 | 7 | function log 8 | echo -e "\x1b[1m\x1b[32m>>>\x1b[0m \x1b[1m\x1b[37m{$argv}\x1b[0m" 9 | end 10 | 11 | if test -f ~/.ruby-version 12 | mv ~/.ruby-version ~/.ruby-version.chruby.bak 13 | end 14 | 15 | set -U tank_reporter spec 16 | 17 | set fish_app_bin 'fish.app/Contents/Resources/base/bin/fish' 18 | set fish_binaries "$PREFIX/fish_binaries/fish-2.1.0/$fish_app_bin" \ 19 | "$PREFIX/fish_binaries/fish-2.0.0/$fish_app_bin" (which fish) 20 | 21 | for fish_binary in $fish_binaries 22 | log "Running tests under $fish_binary in interactive-mode ..." 23 | 24 | for test in (dirname (status -f))/*_test.fish 25 | log "Running $test ..." 26 | env HOME=$PREFIX/home $fish_binary -i $test 27 | 28 | set results $status 29 | test $results -ne 0; and set test_status $results 30 | end 31 | 32 | log "Running tests under $fish_binary in non-interactive-mode ..." 33 | 34 | for test in (dirname (status -f))/*_test.fish 35 | log "Running $test ..." 36 | env HOME=$PREFIX/home $fish_binary $test 37 | 38 | set results $status 39 | test $results -ne 0; and set test_status $results 40 | end 41 | end 42 | 43 | if test -f ~/.ruby-version.chruby.bak 44 | mv ~/.ruby-version.chruby.bak ~/.ruby-version 45 | end 46 | 47 | exit $test_status 48 | -------------------------------------------------------------------------------- /test/chruby_reset_test.fish: -------------------------------------------------------------------------------- 1 | function suite_chruby_reset 2 | function setup 3 | chruby_use $test_ruby_version 4 | set -g PATH "$RUBY_ROOT/bin" $test_path 5 | end 6 | 7 | function test_chruby_reset 8 | chruby_reset 9 | 10 | assert_empty "$RUBY_ROOT" 11 | assert_empty "$RUBY_ENGINE" 12 | assert_empty "$RUBY_VERSION" 13 | assert_empty "$RUBYOPT" 14 | assert_empty "$GEM_HOME" 15 | 16 | # FIXME: `GEM_PATH` is not empty if `test_chruby_reset_modified_gem_path` 17 | # runs first. Needs more investigation. 18 | # 19 | # assert_empty "$GEM_PATH" 20 | end 21 | 22 | function test_chruby_reset_duplicate_path 23 | set -gx PATH $PATH "$RUBY_ROOT/bin" 24 | 25 | chruby_reset 26 | assert_equal "$test_path" "$PATH" 27 | end 28 | 29 | function test_chruby_reset_modified_gem_path 30 | set -l gem_dir "$HOME/gems" 31 | set -gx GEM_PATH "$GEM_PATH:$gem_dir" 32 | 33 | chruby_reset 34 | assert_equal "$gem_dir" "$GEM_PATH" 35 | end 36 | 37 | # FIXME: If this test runs first, then `test_chruby_reset_modified_gem_path` 38 | # will fail. Needs more investigation. 39 | # 40 | # function test_chruby_reset_no_gem_root_or_gem_home 41 | # set -gx GEM_HOME "" 42 | # set -gx GEM_ROOT "" 43 | # set -gx PATH $test_path /bin 44 | 45 | # chruby_reset 46 | # assert_equal "$test_path /bin" $PATH 47 | # end 48 | end 49 | 50 | if not set -q tank_running 51 | . (dirname (status -f))/helper.fish 52 | tank_run 53 | exit $status 54 | end 55 | -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## v0.6.0 (2014-05-20) 4 | 5 | ### Features 6 | 7 | - use `CHRUBY_ROOT` instead of `CHRUBY_SOURCE` to define custom chruby path, 8 | see: 11904eb573526c14358acc1ac8c5ec25de44c6aa 9 | 10 | ### Improvements 11 | 12 | - reduce possible number of `chruby-bash` calls when calling `chruby` by 1 13 | - add `CHRUBY_VERSION` global variable 14 | - run tests on multiple Fish versions 15 | 16 | ### Fixes 17 | 18 | - Only run `chruby_use` through `chruby_auto` if active Ruby version doesn't 19 | match `.ruby-version` (thanks @dalizard) 20 | - Work around fish-shell/fish-shell#1168 (thanks @schisamo) 21 | 22 | ## v0.5.4 (2014-04-26) 23 | 24 | ### Improvements 25 | 26 | - run `chruby_auto` before every command 27 | - add tests for `chruby_auto` 28 | - return `CHRUBY_FISH_VERSION` on `chruby --version` 29 | 30 | ### Fixes 31 | 32 | - run bash `chruby_auto` only once 33 | - allow overriding ruby version using `chruby` when `.ruby-version` is present 34 | 35 | ## v0.5.3 (2014-04-25) 36 | 37 | ### Improvements 38 | 39 | - add tests for `chruby`, `chruby_use` and `chruby_reset` 40 | - return correct exit code if `chruby` fails 41 | - add missing global variables: `CHRUBY_FISH_VERSION`, `RUBIES`, `GEM_ROOT` 42 | 43 | ### Fixes 44 | 45 | - only set `GEM_PATH` variable if required 46 | - use `(id -u)` instead of (non-existent) `$UID` to determine user ID 47 | 48 | ## v0.5.2 (2014-04-24) 49 | 50 | ### Fixes 51 | 52 | - Make chruby_auto only run on path changes and not override manual `chruby` 53 | 54 | ## v0.5.1 (2014-04-24) 55 | 56 | ### Improvements 57 | 58 | - Clean up files 59 | 60 | ## v0.5.0 (2014-04-23) 61 | 62 | ### Features 63 | 64 | - Initial commit of `chruby-fish` wrapper scripts 65 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | NAME=chruby-fish 2 | VERSION=0.6.0 3 | AUTHOR=JeanMertz 4 | URL=https://github.com/$(AUTHOR)/$(NAME) 5 | 6 | DIRS=etc lib bin sbin share 7 | INSTALL_DIRS=`find $(DIRS) -type d 2>/dev/null` 8 | INSTALL_FILES=`find $(DIRS) -type f 2>/dev/null` 9 | DOC_FILES=*.md LICENSE 10 | 11 | PKG_DIR=pkg 12 | PKG_NAME=$(NAME)-$(VERSION) 13 | PKG=$(PKG_DIR)/$(PKG_NAME).tar.gz 14 | SIG=$(PKG).asc 15 | 16 | PREFIX?=/usr/local 17 | DOC_DIR=$(PREFIX)/share/doc/$(PKG_NAME) 18 | 19 | pkg: 20 | mkdir $(PKG_DIR) 21 | 22 | download: pkg 23 | wget -O $(PKG) $(URL)/archive/v$(VERSION).tar.gz 24 | 25 | build: pkg 26 | git archive --output=$(PKG) --prefix=$(PKG_NAME)/ HEAD 27 | 28 | sign: $(PKG) 29 | gpg --sign --detach-sign --armor $(PKG) 30 | git add $(PKG).asc 31 | git commit $(PKG).asc -m "Added PGP signature for v$(VERSION)" 32 | git push origin master 33 | 34 | verify: $(PKG) $(SIG) 35 | gpg --verify $(SIG) $(PKG) 36 | 37 | clean: 38 | rm -f $(PKG) $(SIG) 39 | 40 | all: $(PKG) $(SIG) 41 | 42 | test/opt/rubies: 43 | ./test/setup 44 | 45 | test: test/opt/rubies 46 | fish ./test/runner 47 | 48 | tag: 49 | git push origin master 50 | git tag -s -m "Releasing $(VERSION)" v$(VERSION) 51 | git push origin master --tags 52 | 53 | release: tag download sign 54 | 55 | rpm: 56 | rpmdev-setuptree 57 | spectool -g -R rpm/chruby.spec 58 | rpmbuild -ba rpm/chruby.spec 59 | 60 | install: 61 | for dir in $(INSTALL_DIRS); do mkdir -p $(PREFIX)/$$dir; done 62 | for file in $(INSTALL_FILES); do cp $$file $(PREFIX)/$$file; done 63 | mkdir -p $(DOC_DIR) 64 | cp -r $(DOC_FILES) $(DOC_DIR)/ 65 | 66 | uninstall: 67 | for file in $(INSTALL_FILES); do rm -f $(PREFIX)/$$file; done 68 | rm -rf $(DOC_DIR) 69 | 70 | .PHONY: build download sign verify clean test tag release rpm install uninstall all 71 | -------------------------------------------------------------------------------- /test/chruby_test.fish: -------------------------------------------------------------------------------- 1 | function suite_chruby 2 | function setup 3 | set original_rubies $RUBIES 4 | end 5 | 6 | function teardown 7 | chruby_reset 8 | set RUBIES $original_rubies 9 | end 10 | 11 | function test_chruby_default_RUBIES 12 | assert_equal "$test_ruby_root" "$RUBIES" 13 | end 14 | 15 | function test_chruby_version 16 | set chruby_fish_version (chruby --version) 17 | set chruby_fish_V (chruby -V) 18 | set expected_output "chruby: $CHRUBY_VERSION chruby-fish: $CHRUBY_FISH_VERSION" 19 | 20 | assert_equal "$expected_output" "$chruby_fish_version" 21 | assert_equal "$expected_output" "$chruby_fish_V" 22 | end 23 | 24 | function test_chruby_help 25 | set chruby_fish_help (chruby --help) 26 | set chruby_fish_h (chruby -h) 27 | set expected_output 'usage: chruby [RUBY|VERSION|system] [RUBYOPT...]' 28 | 29 | assert_equal "$expected_output" "$chruby_fish_help" 30 | assert_equal "$expected_output" "$chruby_fish_h" 31 | end 32 | 33 | function test_chruby_2_1 34 | chruby '2.1' 35 | assert_equal "$test_ruby_root" "$RUBY_ROOT" 36 | end 37 | 38 | function test_chruby_multiple_matches 39 | set -g RUBIES /path/to/ruby-2.1.0 "$test_ruby_root" 40 | 41 | chruby '2.1' 42 | assert_equal "$test_ruby_root" "$RUBY_ROOT" 43 | end 44 | 45 | function test_chruby_exact_match_first 46 | set -g RUBIES "$test_ruby_root" "$test_ruby_root-rc1" 47 | 48 | chruby "$test_ruby_engine-$test_ruby_version" 49 | assert_equal "$test_ruby_root" "$RUBY_ROOT" 50 | end 51 | 52 | function test_chruby_system 53 | chruby "$test_ruby_version" 54 | chruby 'system' 55 | 56 | assert_empty "$RUBY_ROOT" 57 | end 58 | 59 | function test_chruby_unknown 60 | chruby 'does_not_exist' 2>/dev/null 61 | refute $status 62 | end 63 | 64 | function test_chruby_invalid_ruby 65 | set -g RUBIES '/does/not/exist/jruby' 66 | 67 | chruby 'jruby' 2>/dev/null 68 | refute $status 69 | end 70 | end 71 | 72 | if not set -q tank_running 73 | . (dirname (status -f))/helper.fish 74 | tank_run 75 | exit $status 76 | end 77 | -------------------------------------------------------------------------------- /test/chruby_auto_test.fish: -------------------------------------------------------------------------------- 1 | function suite_chruby_auto 2 | function setup 3 | chruby_reset 4 | set -e RUBY_AUTO_VERSION 5 | end 6 | 7 | function teardown 8 | cd "$PWD" 9 | end 10 | 11 | function test_chruby_auto_enter_project_dir 12 | cd "$test_project_dir"; and chruby_auto 13 | 14 | assert_equal "$test_ruby_root" "$RUBY_ROOT" 15 | end 16 | 17 | function test_chruby_auto_enter_subdir_directly 18 | cd "$test_project_dir/sub_dir"; and chruby_auto 19 | 20 | assert_equal "$test_ruby_root" "$RUBY_ROOT" 21 | end 22 | 23 | function test_chruby_auto_enter_subdir 24 | cd "$test_project_dir"; and chruby_auto 25 | cd sub_dir; and chruby_auto 26 | 27 | assert_equal "$test_ruby_root" "$RUBY_ROOT" 28 | end 29 | 30 | function test_chruby_auto_enter_subdir_with_ruby_version 31 | cd "$test_project_dir"; and chruby_auto 32 | cd sub_versioned/; and chruby_auto 33 | 34 | assert_empty "$RUBY_ROOT" 35 | end 36 | 37 | function test_chruby_auto_modified_ruby_version 38 | cd "$test_project_dir/modified_version"; and chruby_auto 39 | echo '2.1' > .ruby-version; and chruby_auto 40 | 41 | assert_equal "$test_ruby_root" "$RUBY_ROOT" 42 | end 43 | 44 | function test_chruby_auto_overriding_ruby_version 45 | cd "$test_project_dir"; and chruby_auto 46 | chruby system; and chruby_auto 47 | 48 | assert_empty "$RUBY_ROOT" 49 | end 50 | 51 | function test_chruby_auto_leave_project_dir 52 | cd "$test_project_dir"; and chruby_auto 53 | cd "$test_project_dir/.."; and chruby_auto 54 | 55 | assert_empty "$RUBY_ROOT" 56 | end 57 | 58 | function test_chruby_auto_invalid_ruby_version 59 | set -l expected_auto_version (cat $test_project_dir/bad/.ruby-version) 60 | 61 | cd "$test_project_dir"; and chruby_auto 62 | cd bad/; and chruby_auto 2>/dev/null 63 | 64 | assert_equal "$test_ruby_root" "$RUBY_ROOT" 65 | assert_equal "$expected_auto_version" "$RUBY_AUTO_VERSION" 66 | end 67 | end 68 | 69 | if not set -q tank_running 70 | . (dirname (status -f))/../share/chruby/auto.fish 71 | . (dirname (status -f))/helper.fish 72 | tank_run 73 | exit $status 74 | end 75 | -------------------------------------------------------------------------------- /share/chruby/auto.fish: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 2014 Jean Mertz 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | set -e RUBY_AUTO_VERSION 25 | 26 | # 27 | # Wrapper around bash `chruby_auto`. 28 | # 29 | # This wrapper triggers the bash version of `chruby_auto`, captures its output 30 | # as `RUBY_ENGINE` and `RUBY_VERSION` and fires the Fish wrapper around the 31 | # `chruby` tool, passing along the `$RUBY_ENGINE-$RUBY_VERSION` argument to the 32 | # command. 33 | # 34 | # You can optionally set the $CHRUBY_ROOT environment variable if your 35 | # `chruby.sh` and `auto.sh` are located in a custom path. 36 | # 37 | function chruby_auto -e fish_prompt 38 | status --is-command-substitution; and return 39 | 40 | set -q CHRUBY_ROOT; or set CHRUBY_ROOT /usr/local 41 | 42 | # 43 | # line 1: source official `chruby.sh` file. 44 | # line 2: unset BASH_VERSION so that sourcing `auto.sh` doesn't trigger an 45 | # initial `chruby_auto` execution. 46 | # line 3: source official `auto.sh` file. 47 | # line 4: set `RUBY_AUTO_VERSION` to currently active RUBY_AUTO_VERSION. This 48 | # is required because sourcing `auto.sh` unset this variable. 49 | # line 5: manually run `chruby_auto`, only switching rubies if 50 | # `RUBY_AUTO_VERSION` doesn't match the string in `.ruby-version`. 51 | # line 6: echo `$RUBY_AUTO_VERSION` to capture in Fish shell. 52 | # 53 | command bash -c "source $CHRUBY_ROOT/share/chruby/chruby.sh; \ 54 | unset BASH_VERSION; \ 55 | source $CHRUBY_ROOT/share/chruby/auto.sh; \ 56 | RUBY_AUTO_VERSION=$RUBY_AUTO_VERSION; \ 57 | chruby_auto; \ 58 | echo \$RUBY_AUTO_VERSION" 2>/dev/null | \ 59 | read -l ch_ruby_auto_version 60 | 61 | # 62 | # if non-equal, either `chruby` ran, or no .ruby-version was detected. If 63 | # equal, a .ruby-version was detected, but it equals active 64 | # RUBY_AUTO_VERSION, so we return quickly. 65 | # 66 | if test "$ch_ruby_auto_version" != "$RUBY_AUTO_VERSION" 67 | set -gx RUBY_AUTO_VERSION $ch_ruby_auto_version 68 | 69 | if test -n "$RUBY_AUTO_VERSION" 70 | chruby "$RUBY_AUTO_VERSION" 71 | else 72 | chruby_reset 73 | end 74 | else 75 | return 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # chruby-fish 2 | 3 | [![Build Status](http://img.shields.io/travis/JeanMertz/chruby-fish.svg)][travis] 4 | [![Gittip](http://img.shields.io/gittip/JeanMertz.svg)][gittip] 5 | 6 | Thin wrapper around [chruby][] to make it work with the [Fish shell][] 7 | 8 | [travis]: http://travis-ci.org/JeanMertz/chruby-fish 9 | [gittip]: https://www.gittip.com/JeanMertz 10 | [chruby]: https://github.com/postmodern/chruby 11 | [Fish shell]: http://fishshell.com 12 | 13 | ## install 14 | 15 | **note** that `chruby-fish` is dependent on `chruby`, please [install it first]. 16 | 17 | ```bash 18 | wget -O chruby-fish-0.6.0.tar.gz https://github.com/JeanMertz/chruby-fish/archive/v0.6.0.tar.gz 19 | tar -xzvf chruby-fish-0.6.0.tar.gz 20 | cd chruby-fish-0.6.0/ 21 | sudo make install 22 | ``` 23 | 24 | [install it first]: https://github.com/postmodern/chruby#install 25 | 26 | ### Homebrew 27 | 28 | chruby-fish can also be installed with [homebrew]: 29 | 30 | brew install chruby-fish 31 | 32 | Or the absolute latest chruby-fish can be installed from source: 33 | 34 | brew install chruby-fish --HEAD 35 | 36 | chruby is installed as a dependency of chruby-fish, if you installed chruby 37 | manually, add the `--without-chruby` flag to the above commands. 38 | 39 | [homebrew]: http://brew.sh/ 40 | 41 | ## configuration 42 | 43 | Add the following line to your `config.fish` file: 44 | 45 | source /usr/local/share/chruby/chruby.fish 46 | 47 | To enable auto-switching, also add the `auto.fish` file: 48 | 49 | source /usr/local/share/chruby/auto.fish 50 | 51 | If you use a custom install location for chruby, use the 52 | [`CHRUBY_ROOT` variable][chruby_root] to point in the right direction. 53 | 54 | For more general instructions, see the [chruby documentation][]. 55 | 56 | [chruby_root]: https://github.com/JeanMertz/chruby-fish/blob/ad62361884941067485df6c417959cdc2a42c182/share/chruby/chruby.fish#L33-L34 57 | [chruby documentation]: https://github.com/postmodern/chruby#chruby 58 | 59 | ## Known Issues 60 | 61 | Invalid PATH warning 62 | 63 | If you see a warning similiar to 64 | ``` 65 | set: Warning: path component /path/to/ruby-x.y.z/lib/ruby/gems/x.y.z/bin may not be valid in PATH. 66 | set: No such file or directory 67 | ``` 68 | you can silence it by creating that directory: 69 | ``` 70 | mkdir /path/to/ruby-x.y.z/lib/ruby/gems/x.y.z/bin 71 | ``` 72 | 73 | ## License & Authors 74 | 75 | - Author: Jean Mertz 76 | 77 | ```text 78 | The MIT License (MIT) 79 | 80 | Copyright (c) 2014 Jean Mertz 81 | 82 | Permission is hereby granted, free of charge, to any person obtaining a copy 83 | of this software and associated documentation files (the "Software"), to deal 84 | in the Software without restriction, including without limitation the rights 85 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 86 | copies of the Software, and to permit persons to whom the Software is 87 | furnished to do so, subject to the following conditions: 88 | 89 | The above copyright notice and this permission notice shall be included in 90 | all copies or substantial portions of the Software. 91 | 92 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 93 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 94 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 95 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 96 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 97 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 98 | THE SOFTWARE. 99 | ``` 100 | -------------------------------------------------------------------------------- /share/chruby/chruby.fish: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | # 3 | # Copyright (c) 2014 Jean Mertz 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | # 23 | 24 | set -gx CHRUBY_FISH_VERSION '0.6.0' 25 | 26 | # 27 | # Execute chruby commands through bash. 28 | # 29 | # This method allows any command to be executed through the bash interpreter, 30 | # allowing us to use the original chruby implementation while overlaying a thin 31 | # wrapper on top of it to set ENV variables in the Fish shell. 32 | # 33 | # You can optionally set the $CHRUBY_ROOT environment variable if your 34 | # `chruby.sh` is located in a custom path. 35 | # 36 | function bchruby 37 | set -q CHRUBY_ROOT; or set CHRUBY_ROOT /usr/local 38 | 39 | if test ! -f "$CHRUBY_ROOT/share/chruby/chruby.sh"; 40 | echo "$CHRUBY_ROOT/share/chruby/chruby.sh does not exist." \ 41 | "Set \$CHRUBY_ROOT to point to the correct path." \ 42 | "(currently pointing to `$CHRUBY_ROOT`)" 43 | return 1 44 | end 45 | 46 | command bash -c "source $CHRUBY_ROOT/share/chruby/chruby.sh; $argv" 47 | end 48 | 49 | # Define RUBIES variable with paths to installed ruby versions. 50 | # 51 | # Gets its list of Rubies from `bchruby`, then adds it to the local RUBIES env. 52 | # 53 | set -gx RUBIES (bchruby 'echo ${RUBIES[@]}' | tr ' ' '\n') 54 | set -gx CHRUBY_VERSION (bchruby 'echo $CHRUBY_VERSION') 55 | 56 | # 57 | # Reset chruby-set environment variables. 58 | # 59 | # Calls the `chruby_reset()` method provided by chruby. Removing all custom 60 | # environment variables, returning the ruby version to the system default. 61 | # 62 | function chruby_reset 63 | bchruby 'chruby_reset; echo $PATH ${GEM_PATH:-_}' | \ 64 | read -l ch_path ch_gem_path 65 | 66 | if test (id -u) != '0' 67 | set -e GEM_HOME 68 | set -e GEM_ROOT 69 | 70 | if test "$ch_gem_path" = '_' 71 | set -e GEM_PATH 72 | else 73 | set -gx GEM_PATH $ch_gem_path 74 | end 75 | end 76 | 77 | set -gx PATH (echo $ch_path | tr : '\n') 78 | 79 | set -l unset_vars RUBY_ROOT RUBY_ENGINE RUBY_VERSION RUBYOPT 80 | for i in (seq (count $unset_vars)) 81 | set -e $unset_vars[$i] 82 | end 83 | end 84 | 85 | # 86 | # Set environment variables to point to custom Ruby install. 87 | # 88 | # Resets current Ruby version then runs chruby in bash, capturing it's defined 89 | # variables and setting them in the current Fish instance. 90 | # 91 | function chruby_use 92 | set -l args '; echo $RUBY_ROOT ${RUBYOPT:-_} ${GEM_HOME:-_} ${GEM_PATH:-_} \ 93 | ${GEM_ROOT:-_} $PATH $RUBY_ENGINE $RUBY_VERSION $?' 94 | 95 | bchruby 'chruby' $argv $args | read -l ch_ruby_root ch_rubyopt ch_gem_home \ 96 | ch_gem_path ch_gem_root ch_path \ 97 | ch_ruby_engine ch_ruby_version \ 98 | ch_status 99 | 100 | test "$ch_status" = 0; or return 1 101 | test -n "$RUBY_ROOT"; and chruby_reset 102 | 103 | set -gx RUBY_ENGINE $ch_ruby_engine 104 | set -gx RUBY_VERSION $ch_ruby_version 105 | set -gx RUBY_ROOT $ch_ruby_root 106 | test $ch_gem_root = '_'; or set -gx GEM_ROOT $ch_gem_root 107 | test $ch_rubyopt = '_'; or set -gx RUBYOPT $ch_rubyopt 108 | set -gx PATH (echo $ch_path | tr : '\n') 109 | 110 | if test (id -u) != '0' 111 | set -gx GEM_HOME $ch_gem_home 112 | set -gx GEM_PATH $ch_gem_path 113 | end 114 | end 115 | 116 | # 117 | # Custom `chruby` command to be called in the Fish environment. 118 | # 119 | # Thin wrapper around the bash version of `chruby`, passing along arguments to 120 | # it, and capturing the outputted environment variables to be set in Fish. 121 | # 122 | function chruby 123 | set -l version_commands '-V' '--version' 124 | set -l external_commands '-h' '--help' $version_commands 125 | 126 | if echo $external_commands | grep -qe "$argv[1]" 127 | bchruby 'chruby' $argv 128 | 129 | echo $version_commands | grep -qe "$argv[1]"; or return 130 | echo 'chruby-fish:' $CHRUBY_FISH_VERSION 131 | else if test -z "$argv" 132 | bchruby 'chruby' 133 | else if test $argv[1] = 'system' 134 | chruby_reset 135 | else 136 | chruby_use $argv 137 | return $status 138 | end 139 | end 140 | -------------------------------------------------------------------------------- /test/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . ./test/helper.sh 4 | 5 | function log() { 6 | if [[ -t 1 ]]; then 7 | printf "%b>>>%b %b%s%b\n" "\x1b[1m\x1b[32m" "\x1b[0m" \ 8 | "\x1b[1m\x1b[37m" "$1" "\x1b[0m" 9 | else 10 | printf ">>> %s\n" "$1" 11 | fi 12 | } 13 | 14 | function error() { 15 | if [[ -t 1 ]]; then 16 | printf "%b!!!%b %b%s%b\n" "\x1b[1m\x1b[31m" "\x1b[0m" \ 17 | "\x1b[1m\x1b[37m" "$1" "\x1b[0m" >&2 18 | else 19 | printf "!!! %s\n" "$1" >&2 20 | fi 21 | } 22 | 23 | function fail() { 24 | error "$1" 25 | exit -1 26 | } 27 | 28 | function download() { 29 | if command -v wget >/dev/null; then 30 | wget -cq -O "$2" "$1" 31 | elif command -v curl >/dev/null; then 32 | curl -Ls -C - -o "$2" "$1" 33 | else 34 | error "Could not find wget or curl" 35 | return 1 36 | fi 37 | } 38 | 39 | function detect_system() { 40 | # adapted from RVM: https://github.com/wayneeseguin/rvm/blob/master/scripts/functions/utility_system#L3 41 | system_type="unknown" 42 | system_name="unknown" 43 | system_version="unknown" 44 | system_arch="$(uname -m)" 45 | 46 | case "$(uname)" in 47 | (Linux|GNU*) 48 | system_type="linux" 49 | 50 | if [[ -f /etc/lsb-release ]] && 51 | [[ "$(< /etc/lsb-release)" == *"DISTRIB_ID=Ubuntu"* ]] 52 | then 53 | system_name="ubuntu" 54 | system_version="$(awk -F'=' '$1=="DISTRIB_RELEASE"{print $2}' /etc/lsb-release)" 55 | system_arch="$(dpkg --print-architecture)" 56 | elif [[ -f /etc/lsb-release ]] && 57 | [[ "$(< /etc/lsb-release)" == *"DISTRIB_ID=LinuxMint"* ]] 58 | then 59 | system_name="mint" 60 | system_version="$(awk -F'=' '$1=="DISTRIB_RELEASE"{print $2}' /etc/lsb-release)" 61 | system_arch="$( dpkg --print-architecture )" 62 | elif [[ -f /etc/lsb-release ]] && 63 | [[ "$(< /etc/lsb-release)" == *"DISTRIB_ID=ManjaroLinux"* ]] 64 | then 65 | system_name="manjaro" 66 | system_version="$(awk -F'=' '$1=="DISTRIB_RELEASE"{print $2}' /etc/lsb-release)" 67 | elif [[ -f /etc/os-release ]] && 68 | [[ "$(< /etc/os-release)" == *"ID=opensuse"* ]] 69 | then 70 | system_name="opensuse" 71 | system_version="$(awk -F'=' '$1=="VERSION_ID"{gsub(/"/,"");print $2}' /etc/os-release)" #' 72 | elif [[ -f /etc/SuSE-release ]]; then 73 | system_name="suse" 74 | system_version="$( 75 | awk -F'=' '{gsub(/ /,"")} $1~/VERSION/ {version=$2} $1~/PATCHLEVEL/ {patch=$2} END {print version"."patch}' < /etc/SuSE-release 76 | )" 77 | elif [[ -f /etc/debian_version ]]; then 78 | system_name="debian" 79 | system_version="$(< /etc/debian_version | awk -F. '{print $1"."$2}')" 80 | system_arch="$( dpkg --print-architecture )" 81 | elif [[ -f /etc/os-release ]] && 82 | [[ "$(< /etc/os-release)" == *"ID=debian"* ]] 83 | then 84 | system_name="debian" 85 | system_version="$(awk -F'=' '$1=="VERSION_ID"{gsub(/"/,"");print $2}' /etc/os-release | awk -F. '{print $1"."$2}')" #' 86 | system_arch="$( dpkg --print-architecture )" 87 | elif [[ -f /etc/fedora-release ]]; then 88 | system_name="fedora" 89 | system_version="$(grep -Eo '[[:digit:]]+' /etc/fedora-release)" 90 | elif [[ -f /etc/centos-release ]]; then 91 | system_name="centos" 92 | system_version="$(grep -Eo '[[:digit:]\.]+' /etc/centos-release | awk -F. '{print $1"."$2}')" 93 | elif [[ -f /etc/redhat-release ]]; then 94 | if [[ "$(< /etc/redhat-release)" == *"CentOS"* ]]; then 95 | system_name="centos" 96 | else 97 | system_name="redhat" 98 | fi 99 | 100 | system_version="$(grep -Eo '[[:digit:]\.]+' /etc/redhat-release | awk -F. '{print $1"."$2}')" 101 | elif [[ -f /etc/system-release ]] && 102 | [[ "$(< /etc/system-release)" == *"Amazon Linux AMI"* ]] 103 | then 104 | system_name="amazon" 105 | system_version="$(grep -Eo '[[:digit:]\.]+' /etc/system-release | awk -F. '{print $1"."$2}')" 106 | elif [[ -f /etc/gentoo-release ]]; then 107 | system_name="gentoo" 108 | system_version="base-$(< /etc/gentoo-release | awk 'NR==1 {print $NF}' | awk -F. '{print $1"."$2}')" 109 | elif [[ -f /etc/arch-release ]]; then 110 | system_name="arch" 111 | system_version="libc-$(ldd --version | awk 'NR==1 {print $NF}' | awk -F. '{print $1"."$2}')" 112 | else 113 | system_version="libc-$(ldd --version | awk 'NR==1 {print $NF}' | awk -F. '{print $1"."$2}')" 114 | fi 115 | ;; 116 | 117 | (SunOS) 118 | system_type="sunos" 119 | system_name="solaris" 120 | system_version="$(uname -v)" 121 | 122 | if [[ "${system_version}" == joyent* ]]; then 123 | system_name="smartos" 124 | system_version="${system_version#* }" 125 | elif [[ "${system_version}" == oi* ]]; then 126 | system_name="openindiana" 127 | system_version="${system_version#* }" 128 | fi 129 | ;; 130 | 131 | (OpenBSD) 132 | system_type="bsd" 133 | system_name="openbsd" 134 | system_version="$(uname -r)" 135 | ;; 136 | 137 | (Darwin) 138 | system_type="darwin" 139 | system_name="osx" 140 | system_version="$(sw_vers -productVersion)" 141 | system_version="${system_version%.*}" # only major.minor - teeny is ignored 142 | ;; 143 | 144 | (FreeBSD) 145 | system_type="bsd" 146 | system_name="freebsd" 147 | system_version="$(uname -r)" 148 | system_version="${system_version%%-*}" 149 | ;; 150 | 151 | (*) 152 | return 1 153 | ;; 154 | esac 155 | 156 | system_type="${system_type//[ \/]/_}" 157 | system_name="${system_name//[ \/]/_}" 158 | system_version="${system_version//[ \/]/_}" 159 | system_arch="${system_arch//[ \/]/_}" 160 | system_arch="${system_arch/amd64/x86_64}" 161 | system_arch="${system_arch/i[123456789]86/i386}" 162 | } 163 | 164 | detect_system || fail "Cannot auto-detect system type" 165 | [[ "$system_name" == "unknown" ]] && fail "Could not detect system name" 166 | [[ "$system_version" == "unknown" ]] && fail "Could not detect system version" 167 | [[ "$system_arch" == "unknown" ]] && fail "Could not detect system arch" 168 | 169 | test_ruby_archive="$test_ruby_engine-$test_ruby_version.tar.bz2" 170 | test_ruby_url="http://rvm.io/binaries/$system_name/$system_version/$system_arch/$test_ruby_archive" 171 | test_ruby_root="$test_ruby_engine-$test_ruby_version" 172 | 173 | mkdir -p "$PREFIX/fish_binaries" 174 | cd $PREFIX/fish_binaries 175 | 176 | declare -a fish_versions=('2.0.0' '2.1.0' 'HEAD') 177 | for fish_version in "${fish_versions[@]}"; do 178 | if [[ "$fish_version" = 'HEAD' ]]; then 179 | if [[ $(command -v brew) ]] && ! [[ $(command -v fish) ]]; then 180 | log "Installing Fish-$fish_version through Homebrew" 181 | brew install fish --HEAD 182 | fi 183 | else 184 | log "Downloading http://fishshell.com/files/$fish_version/fish.app.zip ..." 185 | download "http://fishshell.com/files/$fish_version/fish.app.zip" 'fish.zip' 186 | unzip -o -d "fish-$fish_version" 'fish.zip' >/dev/null 187 | rm 'fish.zip' 188 | fi 189 | done 190 | 191 | mkdir -p "$PREFIX/opt/rubies" 192 | cd "$PREFIX/opt/rubies" 193 | 194 | log "Downloading $test_ruby_url ..." 195 | download "$test_ruby_url" "$test_ruby_archive" || fail "Download failed" 196 | 197 | log "Unpacking $test_ruby_archive ..." 198 | tar -xjf "$test_ruby_archive" || fail "Unpacking failed" 199 | 200 | log "Cleaning up ..." 201 | rm -f "$test_ruby_archive" 202 | --------------------------------------------------------------------------------