Skip to content

bash-completion: fix setsid sub-command completion#4398

Open
lzwind wants to merge 1 commit into
util-linux:masterfrom
lzwind:fix/setsid-bash-completion
Open

bash-completion: fix setsid sub-command completion#4398
lzwind wants to merge 1 commit into
util-linux:masterfrom
lzwind:fix/setsid-bash-completion

Conversation

@lzwind
Copy link
Copy Markdown
Contributor

@lzwind lzwind commented Jun 2, 2026

Summary

  • The setsid completion used the old manual COMP_WORDS/COMP_CWORD pattern and never delegated to the sub-command's own completion
  • When typing e.g. setsid -f rm -<Tab>, completion showed setsid options instead of rm options
  • Rewrote using _init_completion and _command_offset, matching the pattern used by unshare and other wrapper commands

Partially fixes: #4073

Test plan

  • setsid -f rm -<Tab> should complete with rm options
  • setsid --fork --wait ls -<Tab> should complete with ls options
  • Direct setsid -<Tab> should still show setsid options

Co-developed-by: Claude Sonnet 4.6 noreply@anthropic.com

Comment thread bash-completion/setsid Outdated
COMPREPLY=( $(compgen -c -- $cur) )

if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "${NOARGOPTS// /|}" -- $cur) )
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter expansion is actually not needed here, it will otherwise turn the original $NOARGOPT string into a new string --ctty|--wait|--fork|--help|--version, which will make the comp spec always complete the option to that new string.

Suggested change
COMPREPLY=( $(compgen -W "${NOARGOPTS// /|}" -- $cur) )
COMPREPLY=( $(compgen -W "$NOARGOPTS" -- $cur) )

@lzwind
Copy link
Copy Markdown
Contributor Author

lzwind commented Jun 4, 2026

Thanks @cgoesche for the catch! I've fixed the parameter expansion issue - replaced with in compgen -W.

The fix has been pushed to the branch.

The setsid completion used the old manual COMP_WORDS/COMP_CWORD pattern
and never delegated to the sub-command's own completion. When typing e.g.
"setsid -f rm -<Tab>", completion would show setsid options instead of rm
options.

Rewrite to use _init_completion and _command_offset, matching the pattern
used by unshare and other wrapper commands. This correctly detects where
the sub-command begins and delegates completion to it.

Fixes: util-linux#4073
Co-developed-by: Claude Sonnet 4.6 <noreply@anthropic.com>
@lzwind lzwind force-pushed the fix/setsid-bash-completion branch from abb819a to 0507236 Compare June 4, 2026 01:29
Copy link
Copy Markdown
Collaborator

@cgoesche cgoesche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bash-completion: unshare, setsid, etc are buggy

2 participants