#729·autojump

Tab completion selects wrong directory when database contains non-existent paths

Author: kevinburkesegmentCreated Mar 19, 2026Updated Mar 19, 2026

Summary

When the autojump database contains paths that no longer exist on disk, selecting a numbered entry from tab completion jumps to the wrong directory. The tab menu and the jump resolution use different filtering, causing indices to shift.

Root Cause

handle_tab_completion generates the tab menu and resolves tab indices using find_matches(..., check_entries=False), which includes non-existent directories in the results. But when the user selects an entry by number, main() resolves the index using find_matches(..., check_entries=True) (the default), which filters out non-existent directories.

This means a deleted directory can occupy a slot in the menu (e.g., position 2), but the jump skips over it, so position 2 now resolves to what was position 3 in the menu.

Steps to Reproduce

  1. Visit several directories so they're recorded in the autojump database
  2. Delete one or more of those directories from disk (don't run autojump --purge)
  3. Type j <needle><tab> where the needle matches the deleted directory along with other existing ones
  4. Note the numbered list shown
  5. Select an entry whose number comes after a deleted directory's position
  6. Observe that autojump jumps to a different directory than the one shown at that position

Example

With a deleted path at position 2 in the menu:

Menu position Menu shows Jump actually goes to
1 /path/to/foo (exists) /path/to/foo (correct)
2 /path/to/deleted-bar (missing) /path/to/baz (wrong!)
3 /path/to/baz (exists) /path/to/qux (wrong!)

Fix

Change handle_tab_completion to use check_entries=True (the default) in all three find_matches calls, matching the behavior in main(). This ensures non-existent paths are excluded from both the tab menu and the jump resolution, keeping indices consistent.

Workaround

Running autojump --purge removes non-existent paths from the database, which eliminates the index mismatch until more paths are deleted.