diff --git a/commacd.bash b/commacd.bash index 18e052b..68867c9 100644 --- a/commacd.bash +++ b/commacd.bash @@ -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" @@ -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 diff --git a/shpec/commacd_shpec.sh b/shpec/commacd_shpec.sh index ae51167..a092212 100644 --- a/shpec/commacd_shpec.sh +++ b/shpec/commacd_shpec.sh @@ -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 @@ -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 ',,,'