Skip to content

Commit

Permalink
Fixing fuzzycd to play nicely with other tools that re-define cd, suc…
Browse files Browse the repository at this point in the history
…h as RVM.
  • Loading branch information
harob committed Apr 23, 2011
1 parent 6f66a94 commit 1f7ae87
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fuzzycd_bash_wrapper.sh
Original file line number Diff line number Diff line change
@@ -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 $*
Expand All @@ -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 1f7ae87

Please sign in to comment.