Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from harob/master.

fuzzycd + RVM = ♥
  • Loading branch information...
commit a27aa8b3aa6e2b41dc3d3f3746beb4172550b7bc 2 parents 6f66a94 + 1f7ae87
@philc authored
Showing with 12 additions and 2 deletions.
  1. +12 −2 fuzzycd_bash_wrapper.sh
View
14 fuzzycd_bash_wrapper.sh
@@ -1,5 +1,15 @@
# This displaces the normal bash "cd" builtin command. cd needs to be redefined this way because it's not
# a normal binary, but rather a Bash builtin.
+
+# The "cd" command may have already been redefined by another script (RVM does this, for example):
+if [ x`type -t cd` == "xfunction" ]; then
+ # In this case, we define a new "__cd" function with the same body as the previously defined "cd" function.
+ eval $(type cd | grep -v 'cd is a function' | sed 's/^cd/__cd/' | sed 's/^}/;}/' )
+else
+ # Otherwise, we just define "__cd" to directly call the builtin.
+ eval "__cd() { builtin cd \$*; }"
+fi
+
cd() {
# This assumes that fuzzycd.rb is available somewhere in your PATH.
fuzzycd.rb $*
@@ -9,8 +19,8 @@ cd() {
if [ "$output" = "@nomatches" ]; then
echo "No files match \"$*\""
elif [ "$output" = "@passthrough" ]; then
- builtin cd "$*"
+ __cd "$*"
elif [ "$output" != "@exit" ]; then
- builtin cd "$output"
+ __cd "$output"
fi
}

0 comments on commit a27aa8b

Please sign in to comment.
Something went wrong with that request. Please try again.