clean up rbenv and ruby resources
parent
58fad4d664
commit
755942fcf7
|
|
@ -1,36 +1,32 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Completion for gem
|
# Completion for gem
|
||||||
|
|
||||||
_installcomp() {
|
__gem_installcomp() {
|
||||||
if [ -z "$REMOTE_GEMS" ]
|
if [[ -z "$REMOTE_GEMS" ]] ; then
|
||||||
then
|
|
||||||
REMOTE_GEMS=( $(gem list --remote --no-versions | tr '\n' ' ') )
|
REMOTE_GEMS=( $(gem list --remote --no-versions | tr '\n' ' ') )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
COMPREPLY=( $(compgen -W "${REMOTE_GEMS[*]}" -- $cur) )
|
COMPREPLY=( $(compgen -W "${REMOTE_GEMS[*]}" -- $cur) )
|
||||||
}
|
}
|
||||||
|
|
||||||
_uninstallcomp() {
|
__gem_uninstallcomp() {
|
||||||
if [ -z "$LOCAL_GEMS" ]
|
if [[ -z "$LOCAL_GEMS" ]] ; then
|
||||||
then
|
|
||||||
LOCAL_GEMS=( $(gem list --no-versions | sed 's/\*\*\* LOCAL GEMS \*\*\*//' | tr '\n' ' ') )
|
LOCAL_GEMS=( $(gem list --no-versions | sed 's/\*\*\* LOCAL GEMS \*\*\*//' | tr '\n' ' ') )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
COMPREPLY=( $(compgen -W "${LOCAL_GEMS[*]}" -- $cur) )
|
COMPREPLY=( $(compgen -W "${LOCAL_GEMS[*]}" -- $cur) )
|
||||||
}
|
}
|
||||||
|
|
||||||
_gem() {
|
__gem_comp() {
|
||||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
local prev=${COMP_WORDS[COMP_CWORD-1]}
|
local prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||||
case $prev in
|
case $prev in
|
||||||
install)
|
install)
|
||||||
_installcomp
|
__gem_installcomp
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
uninstall)
|
uninstall)
|
||||||
_uninstallcomp
|
__gem_uninstallcomp
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -38,4 +34,4 @@ _gem() {
|
||||||
COMPREPLY=( $(compgen -W "${commands[*]}" -- $cur) )
|
COMPREPLY=( $(compgen -W "${commands[*]}" -- $cur) )
|
||||||
}
|
}
|
||||||
|
|
||||||
complete -F _gem gem
|
complete -F __gem_comp gem
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Bash completion support for rbenv
|
||||||
|
|
||||||
|
if _command_exists rbenv && [[ -r "$(dirname $(readlink -f $(which rbenv)))/../completions/rbenv.bash" ]] ; then
|
||||||
|
source "$(dirname $(readlink -f $(which rbenv)))/../completions/rbenv.bash"
|
||||||
|
fi
|
||||||
|
|
@ -1,7 +1,25 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'load rbenv, if you are using it'
|
about-plugin 'load rbenv, if you are using it'
|
||||||
|
|
||||||
export RBENV_ROOT="$HOME/.rbenv"
|
# Load after basher
|
||||||
pathmunge "$RBENV_ROOT/bin"
|
# BASH_IT_LOAD_PRIORITY: 275
|
||||||
|
|
||||||
[[ `which rbenv 2>/dev/null` ]] && eval "$(rbenv init - bash)"
|
# Don't modify the environment if we can't find the tool:
|
||||||
|
# - Check if in $PATH already
|
||||||
|
# - Check if installed manually to $RBENV_ROOT
|
||||||
|
# - Check if installed manually to $HOME
|
||||||
|
_command_exists rbenv ||
|
||||||
|
[[ -n "$RBENV_ROOT" && -x "$RBENV_ROOT/bin/rbenv" ]] ||
|
||||||
|
[[ -x "$HOME/.rbenv/bin/rbenv" ]] ||
|
||||||
|
return 0
|
||||||
|
|
||||||
|
# Set RBENV_ROOT, if not already set
|
||||||
|
export RBENV_ROOT="${RBENV_ROOT:-$HOME/.rbenv}"
|
||||||
|
|
||||||
|
# Add RBENV_ROOT/bin to PATH, if that's where it's installed
|
||||||
|
if ! _command_exists rbenv && [[ -x "$RBENV_ROOT/bin/rbenv" ]] ; then
|
||||||
|
pathmunge "$RBENV_ROOT/bin"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Initialize rbenv
|
||||||
|
eval "$(rbenv init - bash)"
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,23 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'ruby and rubygems specific functions and settings'
|
about-plugin 'ruby and rubygems specific functions and settings'
|
||||||
|
|
||||||
# Make commands installed with 'gem install --user-install' available
|
# Load after rbenv
|
||||||
# ~/.gem/ruby/${RUBY_VERSION}/bin/
|
# BASH_IT_LOAD_PRIORITY: 285
|
||||||
if which ruby >/dev/null && which gem >/dev/null; then
|
|
||||||
pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after
|
# Check ruby version to ensure rbenv can find ruby
|
||||||
fi
|
{ _command_exists ruby && ruby --version &>/dev/null ; } || return 0
|
||||||
|
|
||||||
|
# Check gem version to ensure rbenv can find gem
|
||||||
|
{ _command_exists gem && gem --version &>/dev/null ; } || return 0
|
||||||
|
|
||||||
function remove_gem {
|
function remove_gem {
|
||||||
about 'removes installed gem'
|
about 'removes installed gem'
|
||||||
param '1: installed gem name'
|
param '1: installed gem name'
|
||||||
group 'ruby'
|
group 'ruby'
|
||||||
|
|
||||||
gem list | grep $1 | awk '{ print $1; }' | xargs sudo gem uninstall
|
{ _command_exists gem && gem --version &>/dev/null ; } || return 1
|
||||||
|
gem list | grep $1 | awk '{ print $1; }' | xargs gem uninstall
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Make commands installed with 'gem install --user-install' are available
|
||||||
|
pathmunge "$(ruby -e 'print Gem.user_dir')/bin"
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,19 @@
|
||||||
load ../test_helper
|
load ../test_helper
|
||||||
load ../../lib/helpers
|
load ../../lib/helpers
|
||||||
load ../../lib/composure
|
load ../../lib/composure
|
||||||
load ../../plugins/available/ruby.plugin
|
|
||||||
|
|
||||||
function local_setup {
|
function local_setup {
|
||||||
setup_test_fixture
|
setup_test_fixture
|
||||||
|
|
||||||
export OLD_PATH="$PATH"
|
export OLD_PATH="$PATH"
|
||||||
export PATH="/usr/bin:/bin:/usr/sbin"
|
export PATH="/usr/bin:/bin:/usr/sbin"
|
||||||
|
|
||||||
|
if ! _command_exists ruby || ! ruby --version &>/dev/null ; then
|
||||||
|
function ruby { echo -n "${HOME}/.gem/ruby/0.0.0" ; }
|
||||||
|
fi
|
||||||
|
if ! _command_exists gem || ! gem --version &>/dev/null ; then
|
||||||
|
function gem { return 0 ; }
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function local_teardown {
|
function local_teardown {
|
||||||
|
|
@ -18,17 +24,15 @@ function local_teardown {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "plugins ruby: remove_gem is defined" {
|
@test "plugins ruby: remove_gem is defined" {
|
||||||
|
load ../../plugins/available/ruby.plugin
|
||||||
run type remove_gem
|
run type remove_gem
|
||||||
assert_line -n 1 "remove_gem () "
|
assert_line -n 1 "remove_gem () "
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "plugins ruby: PATH includes ~/.gem/ruby/bin" {
|
@test "plugins ruby: PATH includes ~/.gem/ruby/bin" {
|
||||||
if ! which ruby >/dev/null; then
|
|
||||||
skip 'ruby not installed'
|
|
||||||
fi
|
|
||||||
|
|
||||||
load ../../plugins/available/ruby.plugin
|
load ../../plugins/available/ruby.plugin
|
||||||
|
local last_path_entry=$(echo $PATH | tr ":" "\n" | head -1)
|
||||||
local last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1)
|
# check that the path matches expectations, without getting caught up on the version number
|
||||||
[[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]]
|
assert_equal "${last_path_entry##/*/}" "bin"
|
||||||
|
assert_equal "${last_path_entry%/*/*}" "${HOME}/.gem/ruby"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue