News for hackers. Stuff that matters.
Re:Creating a bash completion script (2018) by m463 on Wednesday March 02, 2022 @02:35AM (#30524782)
completion scripts are very very useful, but writing them is a disorganized mess.

It would almost be easier to modify the bash source itself to read and use a regular grammar, say:

  foo [-p <pid>] [-f <configfile>]
  <pid>: {ps -eo pid}
  <configfile>: {ls -1 *.cfg}
or maybe something even nicer with help text
Re:Creating a bash completion script (2018) by sm_ts on Wednesday March 02, 2022 @03:44AM (#30525230)
I wrote long ago about writing competion scripts in any language: https://saveriomiroddi.github.io/Using-scripts-in-any-langua....

Although it's not ideal (one ends up duplicating the arguments parsing logic of the program), it's actually not complicated, just some boilerplate.

Re:Creating a bash completion script (2018) by toolslive on Wednesday March 02, 2022 @03:34AM (#30525173)
well, your completion script doesn't _need_ to be written in bash. If you're writing a completion script for an executable, that executable can be called with an option that generates the completions for bash to consume. You just need to generate the output in the expected format and install a softlink . Hope this can give you some comfort.
Re:Creating a bash completion script (2018) by Per_Bothner on Wednesday March 02, 2022 @10:20AM (#30528330)
Bash completion for the domterm command (a terminal emulator) calls the domterm command itself with a special "#complete-for-bash" option:

    complete -o nospace -C 'domterm "#complete-for-bash" "$COMP_LINE" "$COMP_POINT"' domterm
It works pretty well has the advantage that it automatically ties the completion to the executable, avoiding version mismatches.

It would be great if other shells could use a similar mechanism. Then you could use the same completion logic for multiple shells. A complication is that zsh and fish completion provide descriptive help text; there would need to be a mechanism for a "completion option" to provide such help text.

Re:Creating a bash completion script (2018) by harveywi on Wednesday March 02, 2022 @07:23AM (#30526538)
>It would almost be easier to modify the bash source itself to read and use a regular grammar

It's an interesting idea that we're using for zio-cli [1].

[1] https://github.com/zio/zio-cli/pull/119