Skip to content

Commit 67e2fdd

Browse files
authored
Merge pull request #23 from DannyBen/change/completion-order
Change bash completion order to native before history
2 parents 100c7d2 + b591859 commit 67e2fdd

5 files changed

Lines changed: 11 additions & 8 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ These notes apply to work inside this repository.
2222
- Do not create temporary folders outside `./tmp`.
2323
- Approval tests may need a temporary writable `HOME` in constrained environments; if so, place it under `./tmp`.
2424
- Keep `cd -d` history rewrites tied to `FUZZYCD_HISTORY_FILE`; do not reintroduce fixed temp files under `$HOME`.
25-
- Keep completion behavior aligned with this contract: fuzzy history matches first, native `cd` matches after, no duplicates, and preserve `cd` registration to `_fuzzycd_completions`.
25+
- Keep completion behavior aligned with this contract: native `cd` matches first, fuzzy history matches after, no duplicates, and preserve `cd` registration to `_fuzzycd_completions`.
2626
- 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.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ instantly using a fuzzy match, with or without an interactive menu.
2727
- Minimal - cd to best match
2828
- Interactive
2929
- Interactive with `ls` preview
30-
- Optional fuzzy bash completions.
30+
- Optional bash completions that prefer native `cd` matches before fuzzy history.
3131

3232
## Prerequisites
3333

@@ -131,6 +131,9 @@ If you install manually, add the following line to your `~/.bashrc`:
131131
eval "$(fuzzycd -c)"
132132
```
133133

134+
These completions keep Bash's native `cd` matches first and then append fuzzy
135+
history matches without duplicates.
136+
134137
This works best when tab completion is configured for inline completions, which
135138
you can set by adding/updating the `~/.inputrc` file:
136139

fuzzycd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fuzzycd_run() {
183183
echo ' fi'
184184
echo ' [[ $(complete -p cd 2>/dev/null) == *"_fuzzycd_completions"* ]] || complete -o nosort -F _fuzzycd_completions cd'
185185
echo ' COMPREPLY=()'
186-
echo ' for match in "${fuzzy_matches[@]}" "${native_matches[@]}"; do'
186+
echo ' for match in "${native_matches[@]}" "${fuzzy_matches[@]}"; do'
187187
echo ' [[ -n $match ]] || continue'
188188
echo ' found=0'
189189
echo ' for existing in "${COMPREPLY[@]}"; do'

test/approvals/cd_c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _fuzzycd_completions() {
2222
fi
2323
[[ $(complete -p cd 2>/dev/null) == *"_fuzzycd_completions"* ]] || complete -o nosort -F _fuzzycd_completions cd
2424
COMPREPLY=()
25-
for match in "${fuzzy_matches[@]}" "${native_matches[@]}"; do
25+
for match in "${native_matches[@]}" "${fuzzy_matches[@]}"; do
2626
[[ -n $match ]] || continue
2727
found=0
2828
for existing in "${COMPREPLY[@]}"; do

test/approve

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ context "when the shell is interactive"
4343
[[ "${COMPREPLY[0]}" == "$PWD/tmp/space dir" ]] || fail "Expected spaced path completion"
4444
[[ "$(fuzzycd_run -c)" != *mapfile* ]] || fail "Expected completion function to avoid mapfile dependency"
4545

46-
it "puts fuzzy matches before standard cd completions and removes duplicates"
46+
it "puts standard cd completions before fuzzy matches and removes duplicates"
4747
mkdir -p "tmp/fuzzy one" "tmp/fuzzy two" "tmp/native three"
4848
printf '%s\n%s\n' "$PWD/tmp/fuzzy one" "$PWD/tmp/fuzzy two" > "$FUZZYCD_HISTORY_FILE"
4949
eval "$(fuzzycd_run -c)"
@@ -53,9 +53,9 @@ context "when the shell is interactive"
5353
COMPREPLY=()
5454
_fuzzycd_completions
5555
[[ ${#COMPREPLY[@]} == 3 ]] || fail "Expected three merged completions, got ${#COMPREPLY[@]}"
56-
[[ "${COMPREPLY[0]}" == "$PWD/tmp/fuzzy one" ]] || fail "Expected first fuzzy match first"
57-
[[ "${COMPREPLY[1]}" == "$PWD/tmp/fuzzy two" ]] || fail "Expected second fuzzy match second"
58-
[[ "${COMPREPLY[2]}" == "$PWD/tmp/native three" ]] || fail "Expected native completion last"
56+
[[ "${COMPREPLY[0]}" == "$PWD/tmp/native three" ]] || fail "Expected native completion first"
57+
[[ "${COMPREPLY[1]}" == "$PWD/tmp/fuzzy two" ]] || fail "Expected duplicate fuzzy/native match second"
58+
[[ "${COMPREPLY[2]}" == "$PWD/tmp/fuzzy one" ]] || fail "Expected remaining fuzzy match last"
5959

6060
it "keeps fuzzycd registered as the cd completion function"
6161
printf '%s\n' "$PWD/tmp/one/two" > "$FUZZYCD_HISTORY_FILE"

0 commit comments

Comments
 (0)