Skip to content

Commit

Permalink
Fixed ,, fuzzy mode fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
shyiko committed Nov 8, 2014
1 parent 2e2d934 commit ed493ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions commacd.bash
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ _commacd_backward_by_prefix() {
prev_dir="$dir"
dir="${dir%/*}"
matches=($(_commacd_expand "$dir/${1}*/"))
if [[ -z "$COMMACD_NOFUZZYFALLBACK" && ${#matches[@]} -eq 0 ]]; then
matches=($(_commacd_expand "$dir/*${1}*/"))
fi
for match in "${matches[@]}"; do
if [[ "$match" == "$prev_dir/" ]]; then
echo -n "$prev_dir"
Expand All @@ -137,7 +134,10 @@ _commacd_backward() {
local dir=
case $# in
0) dir=$(_commacd_backward_vcs_root);;
1) dir=$(_commacd_backward_by_prefix "$@");;
1) dir=$(_commacd_backward_by_prefix "$@")
if [[ -z "$COMMACD_NOFUZZYFALLBACK" && "$dir" == "$PWD" ]]; then
dir=$(_commacd_backward_by_prefix "*$@")
fi;;
2) dir=$(_commacd_backward_substitute "$@");;
*) return 1
esac
Expand Down
6 changes: 5 additions & 1 deletion shpec/commacd_shpec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ shopt -s expand_aliases

ROOT=/tmp/commacd.shpec
rm -rf $ROOT
mkdir -p $ROOT/projects/{jekyll,ghost,mysql-binlog-connector-java/src/main/java,mappify/{.git,src/test}}
mkdir -p $ROOT/projects/{jekyll/node_modules/tj/src,ghost,mysql-binlog-connector-java/src/main/java,mappify/{.git,src/test}}
mkdir -p $ROOT/space\ hell/{a\ a,b\ b,a\ b}

COMMACD_CD=cd # supress pwd
Expand Down Expand Up @@ -89,6 +89,10 @@ describe 'commacd'
cd $ROOT/projects/mysql-binlog-connector-java/src/main/java
,, binlog
assert equal "$PWD" "$ROOT/projects/mysql-binlog-connector-java"
it 'switches to fuzzy mode only after full path scan'
cd $ROOT/projects/jekyll/node_modules/tj/src
,, j
assert equal "$PWD" "$ROOT/projects/jekyll"
end_describe

describe ',,,'
Expand Down

0 comments on commit ed493ed

Please sign in to comment.