Permalink
Browse files

rvm remove old, closes #1362

  • Loading branch information...
mpapis committed Dec 5, 2012
1 parent 0e21380 commit 81afa79beef65aed4262d7796d2a5c0315898163
Showing with 43 additions and 1 deletion.
  1. +1 −1 help/remove
  2. +18 −0 scripts/cli
  3. +24 −0 scripts/functions/manage/base
View
@@ -1,5 +1,5 @@
-∴ rvm remove [ruby-string[,ruby-string[,...]]]
+∴ rvm remove [all|old [date]|ruby-string[,ruby-string[,...]]]
Remove one or more rubies and their sources.
View
@@ -345,6 +345,24 @@ __rvm_parse_args()
rvm_ruby_strings="$rvm_token"
;;
+ old)
+ case "${rvm_action:-action-missing}" in
+ remove)
+ rvm_ruby_strings="old:${next_token:-}"
+ next_token="${1:-}"
+ (( $# == 0 )) || shift
+ ;;
+ action-missing)
+ rvm_error_message="what do you want to do with old rubies? rvm can only remove old rubies."
+ rvm_action="error"
+ ;;
+ *)
+ rvm_error_message="rvm can not $rvm_action old rubies, rvm can only remove old rubies."
+ rvm_action="error"
+ ;;
+ esac
+ ;;
+
*.rb) # we have a specified ruby script
rvm_ruby_args=("$rvm_token")
rvm_ruby_file="$rvm_token"
@@ -1059,6 +1059,30 @@ __rvm_manage_rubies()
# Given list of ruby strings.
if
+ __rvm_string_match "${rubies_string:-}" "old:*"
+ then
+ typeset _older_then
+ _older_then=${rubies_string#old:}
+ if
+ [[ -z "${_older_then}" ]]
+ then
+ # minified https://github.com/mpapis/home_dotfiles/blob/master/bin/git-summary#L5-L50
+ case "$(uname)" in
+ (Darwin) _older_then="$( date -j -v6m +%F )" ;;
+ (*) _older_then="$( date --date="-6months" +%F )" ;;
+ esac
+ fi
+ __rvm_read_lines rubies < <(
+ chpwd_functions="" builtin cd "$rvm_rubies_path"
+ find . -maxdepth 1 -mindepth 1 -type d -not -newermt $_older_then 2>/dev/null | cut -c 3-
+ )
+ (( ${#rubies[*]} )) ||
+ {
+ rvm_warn "No rubies older then ${_older_then}."
+ return 1
+ }
+ __rvm_ask_for "Are you SURE you wish to '$action' ${rubies[*]}?" yes || return $?
+ elif
[[ -n "${rubies_string:-}" && "${rubies_string}" != "all" ]]
then
__rvm_custom_separated_array rubies , "${rubies_string}"

0 comments on commit 81afa79

Please sign in to comment.