diff --git a/AGENTS.md b/AGENTS.md index 85a595e..88e4859 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,5 +22,5 @@ These notes apply to work inside this repository. - Do not create temporary folders outside `./tmp`. - Approval tests may need a temporary writable `HOME` in constrained environments; if so, place it under `./tmp`. - Keep `cd -d` history rewrites tied to `FUZZYCD_HISTORY_FILE`; do not reintroduce fixed temp files under `$HOME`. -- Keep completion behavior aligned with this contract: fuzzy history matches first, native `cd` matches after, no duplicates, and preserve `cd` registration to `_fuzzycd_completions`. +- Keep completion behavior aligned with this contract: native `cd` matches first, fuzzy history matches after, no duplicates, and preserve `cd` registration to `_fuzzycd_completions`. - Installer behavior note: Bash completions may be installed automatically for Bash startup, but not for Zsh unless a native or explicitly supported compatibility path exists. diff --git a/README.md b/README.md index 8962c51..f73cf27 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ instantly using a fuzzy match, with or without an interactive menu. - Minimal - cd to best match - Interactive - Interactive with `ls` preview -- Optional fuzzy bash completions. +- Optional bash completions that prefer native `cd` matches before fuzzy history. ## Prerequisites @@ -131,6 +131,9 @@ If you install manually, add the following line to your `~/.bashrc`: eval "$(fuzzycd -c)" ``` +These completions keep Bash's native `cd` matches first and then append fuzzy +history matches without duplicates. + This works best when tab completion is configured for inline completions, which you can set by adding/updating the `~/.inputrc` file: diff --git a/fuzzycd b/fuzzycd index 701fb8d..813ef03 100644 --- a/fuzzycd +++ b/fuzzycd @@ -183,7 +183,7 @@ fuzzycd_run() { echo ' fi' echo ' [[ $(complete -p cd 2>/dev/null) == *"_fuzzycd_completions"* ]] || complete -o nosort -F _fuzzycd_completions cd' echo ' COMPREPLY=()' - echo ' for match in "${fuzzy_matches[@]}" "${native_matches[@]}"; do' + echo ' for match in "${native_matches[@]}" "${fuzzy_matches[@]}"; do' echo ' [[ -n $match ]] || continue' echo ' found=0' echo ' for existing in "${COMPREPLY[@]}"; do' diff --git a/test/approvals/cd_c b/test/approvals/cd_c index f1b3036..d0565a1 100644 --- a/test/approvals/cd_c +++ b/test/approvals/cd_c @@ -22,7 +22,7 @@ _fuzzycd_completions() { fi [[ $(complete -p cd 2>/dev/null) == *"_fuzzycd_completions"* ]] || complete -o nosort -F _fuzzycd_completions cd COMPREPLY=() - for match in "${fuzzy_matches[@]}" "${native_matches[@]}"; do + for match in "${native_matches[@]}" "${fuzzy_matches[@]}"; do [[ -n $match ]] || continue found=0 for existing in "${COMPREPLY[@]}"; do diff --git a/test/approve b/test/approve index c9b2a8c..fbb73d5 100755 --- a/test/approve +++ b/test/approve @@ -43,7 +43,7 @@ context "when the shell is interactive" [[ "${COMPREPLY[0]}" == "$PWD/tmp/space dir" ]] || fail "Expected spaced path completion" [[ "$(fuzzycd_run -c)" != *mapfile* ]] || fail "Expected completion function to avoid mapfile dependency" - it "puts fuzzy matches before standard cd completions and removes duplicates" + it "puts standard cd completions before fuzzy matches and removes duplicates" mkdir -p "tmp/fuzzy one" "tmp/fuzzy two" "tmp/native three" printf '%s\n%s\n' "$PWD/tmp/fuzzy one" "$PWD/tmp/fuzzy two" > "$FUZZYCD_HISTORY_FILE" eval "$(fuzzycd_run -c)" @@ -53,9 +53,9 @@ context "when the shell is interactive" COMPREPLY=() _fuzzycd_completions [[ ${#COMPREPLY[@]} == 3 ]] || fail "Expected three merged completions, got ${#COMPREPLY[@]}" - [[ "${COMPREPLY[0]}" == "$PWD/tmp/fuzzy one" ]] || fail "Expected first fuzzy match first" - [[ "${COMPREPLY[1]}" == "$PWD/tmp/fuzzy two" ]] || fail "Expected second fuzzy match second" - [[ "${COMPREPLY[2]}" == "$PWD/tmp/native three" ]] || fail "Expected native completion last" + [[ "${COMPREPLY[0]}" == "$PWD/tmp/native three" ]] || fail "Expected native completion first" + [[ "${COMPREPLY[1]}" == "$PWD/tmp/fuzzy two" ]] || fail "Expected duplicate fuzzy/native match second" + [[ "${COMPREPLY[2]}" == "$PWD/tmp/fuzzy one" ]] || fail "Expected remaining fuzzy match last" it "keeps fuzzycd registered as the cd completion function" printf '%s\n' "$PWD/tmp/one/two" > "$FUZZYCD_HISTORY_FILE"