Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion fuzzycd
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion test/approvals/cd_c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/approve
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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"
Expand Down
Loading