Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 28 lines (25 sloc) 1.103 kb
ebaebaa @philc Initial import
authored
1 # This displaces the normal bash "cd" builtin command. cd needs to be redefined this way because it's not
2 # a normal binary, but rather a Bash builtin.
1f7ae87 @harob Fixing fuzzycd to play nicely with other tools that re-define cd, such a...
harob authored
3
4 # The "cd" command may have already been redefined by another script (RVM does this, for example):
5 if [ x`type -t cd` == "xfunction" ]; then
77316ef @philc Change some variable names in the latest rvm-compatibility patch
authored
6 # In this case, we define a new "original_cd" function with the same body as the previously defined "cd"
7 # function.
8 eval $(type cd | grep -v 'cd is a function' | sed 's/^cd/original_cd/' | sed 's/^}/;}/' )
1f7ae87 @harob Fixing fuzzycd to play nicely with other tools that re-define cd, such a...
harob authored
9 else
10 # Otherwise, we just define "__cd" to directly call the builtin.
77316ef @philc Change some variable names in the latest rvm-compatibility patch
authored
11 eval "original_cd() { builtin cd \$*; }"
1f7ae87 @harob Fixing fuzzycd to play nicely with other tools that re-define cd, such a...
harob authored
12 fi
13
ebaebaa @philc Initial import
authored
14 cd() {
15 # This assumes that fuzzycd.rb is available somewhere in your PATH.
16 fuzzycd.rb $*
ef83c06 @philc Add some header documentation to fuzzycd.rb
authored
17 # fuzzycd.rb communicates to this bash wrapper through a temp file, because it uses STDOUT for other purposes.
ebaebaa @philc Initial import
authored
18 output=`cat /tmp/fuzzycd.rb.out`
19 `rm /tmp/fuzzycd.rb.out`
20 if [ "$output" = "@nomatches" ]; then
21 echo "No files match \"$*\""
22 elif [ "$output" = "@passthrough" ]; then
77316ef @philc Change some variable names in the latest rvm-compatibility patch
authored
23 original_cd "$*"
ebaebaa @philc Initial import
authored
24 elif [ "$output" != "@exit" ]; then
77316ef @philc Change some variable names in the latest rvm-compatibility patch
authored
25 original_cd "$output"
ebaebaa @philc Initial import
authored
26 fi
27 }
Something went wrong with that request. Please try again.