Since you are using bash-completion, the easiest solution is probably to ask it how nohup
is completed1:
$ complete -p nohup
complete -F _command nohup
and then apply the same completion recipe to detach
:
$ complete -F _command detach
Refer to "Where should I install my own local completions?" in bash-completion's FAQ for the most suitable place for this command.
The _command
function in turn invokes _command_offset
, which is, according to a comment in bash_completion
:
# A meta-command completion function for commands like sudo(8), which need to
# first complete on a command, then complete according to that command's own
# completion definition.
1 Assuming an interactive bash
shell in which bash_completion
has been sourced. If you are using Arch Linux, as a comment of yours seemed to suggest, this is true by default for every interactive Bash session (/etc/bash.bashrc
sources /usr/share/bash-completion/bash_completion
).