Skip to content

Completion can change working directory #1426

@etiennebarrie

Description

@etiennebarrie

Describe the bug

Current working directory is not restored when using _comp_compgen -C in some cases.

To reproduce

Using removepkg as an example because it uses _comp_compgen -C:

  1. Run mkdir -p tmp/var/log/packages && touch tmp/var/log/packages/{foo,bar,baz} && cd tmp.
  2. Run ROOT=$PWD (that's setup for removepkg).
  3. Then try completing with a prefix that is not found, for example: removepkg a<TAB>.
  4. After that, you can type Ctrl-U or Ctrl-C to clear the line.
  5. Run pwd and see that your current working directory has changed to ./var/log/packages ($PWD hasn't changed).
  6. To clean-up: cd "$ROOT"/.. && unset ROOT && rm -rf tmp

Expected behavior

After step 3, the shell's working directory should be the same as before.

Versions (please complete the following information)

  • Operating system name/distribution and version: macOS 15.6.1
  • bash version, echo "$BASH_VERSION": 5.3.3(1)-release
  • bash-completion version, (IFS=.; echo "${BASH_COMPLETION_VERSINFO[*]}"): 2 16 0

Additional context

Debug trace

debug-trace.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions