Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve hooks, fix #1021

  • Loading branch information...
commit 996b8cc1a869118303670076da5b93cd89b48078 1 parent dfab5ee
Michal Papis mpapis authored
13 hooks/after_cd
View
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-after_cd_hooks=($(
- find -L "${rvm_path:-"$HOME/.rvm"}/hooks" -iname 'after_cd_*' -type f
-))
-
-for after_cd_hook in "${after_cd_hooks[@]}"
-do
- if [[ -x "${after_cd_hook}" ]]
- then
- __rvm_conditionally_do_with_env . "${after_cd_hook}" >&2
- fi
-done
13 hooks/after_use
View
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-after_use_hooks=($(
- find -L "${rvm_path:-"$HOME/.rvm"}/hooks" -iname 'after_use_*' -type f
-))
-
-for after_use_hook in "${after_use_hooks[@]}"
-do
- if [[ -x "${after_use_hook}" ]]
- then
- __rvm_conditionally_do_with_env . "${after_use_hook}" >&2
- fi
-done
32 scripts/functions/installer
View
@@ -250,19 +250,21 @@ install_rvm_files()
install_rvm_hooks()
{
- typeset hook_x_flag entry
+ typeset hook_x_flag entry name
+
for entry in $(find hooks 2>/dev/null)
do
- if [[ -f "$source_path/$entry" ]]
+ if
+ [[ -f "$source_path/$entry" ]]
then
# Target is supposed to be a file, remove if it is a directory.
if [[ -d "$rvm_path/$entry" ]]
- then
- __rvm_rm_rf "$rvm_path/$entry"
+ then __rvm_rm_rf "$rvm_path/$entry"
fi
# Source is first level hook (after_use) and target is custom user hook, preserve it
- if echo "$entry" | GREP_OPTIONS="" \grep -E '^hooks/[[:alpha:]]+_[[:alpha:]]+$' >/dev/null &&
+ if
[[ -f "$rvm_path/$entry" ]] &&
+ echo "$entry" | GREP_OPTIONS="" \grep -E '^hooks/[[:alpha:]]+_[[:alpha:]]+$' >/dev/null &&
! GREP_OPTIONS="" \grep "$(basename ${entry})_\*" "$rvm_path/$entry" >/dev/null
then
mv -f "$rvm_path/$entry" "$rvm_path/${entry}_custom"
@@ -290,14 +292,18 @@ install_rvm_hooks()
fi
done
- #fix broken copy of after_use to after_use_custom
- if [[ -f "$rvm_path/hooks/after_use_custom" ]] &&
- GREP_OPTIONS="" \grep "after_use_\*" "$rvm_path/hooks/after_use_custom" >/dev/null
- then
- rm -f "$rvm_path/hooks/after_use_custom"
- fi
-
- return 0
+ #remove unneeded files
+ for entry in after_use_custom after_use after_cd
+ do
+ name=${entry#after_}
+ name=${name%_*}
+ if
+ [[ -f "$rvm_path/hooks/$entry" ]] &&
+ GREP_OPTIONS="" \grep "after_${name}_\*" "$rvm_path/hooks/$entry" >/dev/null
+ then
+ rm -f "$rvm_path/hooks/$entry"
+ fi
+ done
}
setup_configuration_files()
33 scripts/hook
View
@@ -11,30 +11,27 @@ typeset rvm_verbose_flag rvm_debug_flag hooks >/dev/null 2>/dev/null
true rvm_verbose_flag:${rvm_verbose_flag:=${old_rvm_verbose_flag}} \
rvm_debug_flag:${rvm_debug_flag:=${old_rvm_debug_flag}} rvm_hook:${rvm_hook:=}
-if [[ -n "$rvm_hook" ]]
+if
+ [[ -n "$rvm_hook" ]]
then
- if [[ "$PWD/.rvm/hooks/$rvm_hook" == "$rvm_hooks_path/$rvm_hook" ]]
- then
- hooks=( "$rvm_hooks_path/$rvm_hook")
- else
- hooks=("$PWD/.rvm/hooks/$rvm_hook" "$rvm_hooks_path/$rvm_hook")
- fi
+ hooks=( "$rvm_hooks_path")
+ [[ "$PWD/.rvm/hooks" == "$rvm_hooks_path" ]] ||
+ hooks+=( "$PWD/.rvm/hooks" )
- for hook in "${hooks[@]}"
+ _hooks_list=($(
+ find -L "${hooks[@]}" -iname "$rvm_hook*" -type f 2>/dev/null
+ ))
+
+ for hook in "${_hooks_list[@]}"
do
- if [[ -s "$hook" ]]
+ if [[ -x "${hook}" || "${hook##*/}" == "$rvm_hook" ]]
then
- if (( rvm_verbose_flag > 0 )) || (( rvm_debug_flag > 0 ))
- then
- rvm_log "Running $hook"
+ if (( rvm_verbose_flag )) || (( rvm_debug_flag ))
+ then rvm_log "Running $hook"
fi
-
- source "$hook"
- else
- continue
+ __rvm_conditionally_do_with_env . "${hook}" >&2
fi
-
done
fi
-unset rvm_hook hooks
+unset rvm_hook hooks _hooks_list hook
Please sign in to comment.
Something went wrong with that request. Please try again.