Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Shell completion #515

Open
Freed-Wu opened this issue Feb 20, 2023 · 6 comments
Open

[feature] Shell completion #515

Freed-Wu opened this issue Feb 20, 2023 · 6 comments
Labels
awaiting-followup Waiting for more input enhancement New feature or request

Comments

@Freed-Wu
Copy link
Contributor

Is it possible to provide completion for common shells (bash, zsh, ...)? TIA!

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Feb 20, 2023

Like this:

#compdef insights

if ((${${words[1, CURRENT - 1]}[(I)--]})); then # insights -- <TAB>
  service=clang _gcc
else # insights <TAB> or insights <TAB> --
  local options=(
    --alt-syntax-for"[Transform all for-loops into their equivalent while-loop]"
    --alt-syntax-subscription"[Transform array subscriptions E1(E2) into (*(E1 + E2))]"
    --extra-arg"[Additional argument to append to the compiler command line]:string"
    --extra-arg-before"[Additional argument to prepend to the compiler command line]:string"
    "(- : *)"-h"[Alias for --help]"
    "(- : *)"--help"[Display available options (--help-hidden for more)]"
    "(- : *)"--help-hidden"[Display all available options]"
    "(- : *)"--help-list"[Display list of available options (--help-list-hidden for more)]"
    "(- : *)"--help-list-hidden"[Display list of all available options]"
    -p"[Build path]: :_files"
    "(- : *)"--print-all-options"[Print all option values after command line parsing]"
    "(- : *)"--print-options"[Print non-default options after command line parsing]"
    --show-all-implicit-casts"[Show all implicit casts which can be noisy]"
    --stdin"[Override source file's content (in the overlaying virtual file system) with input from <stdin> and run the tool on the new content with the compilation options of the source file]"
    --use-libc++"[Use libc++]"
    --version"[Display the version of this program]"
    --
  )
  _arguments -s $options
fi

insights --<TAB> will complete insights options while insights -- <TAB> and insights -- -<TAB> will complete clang options. A better solution is use this file as a template like https://github.com/TeX-Live/texdoc/blob/master/script/texdoclib-const.tlu#L53-L75, then generate the completion script from a data structure like https://github.com/TeX-Live/texdoc/blob/master/script/texdoclib-const.tlu#L77-L260.

@andreasfertig
Copy link
Owner

Hello @Freed-Wu,

that is an interesting request. It looks like you also already presented a solution.

All C++ Insights options are defined here InsightsOptions.def. An automatic update of the shell completion script would be nice for future updates. There is a build step that uses OptionDocumentationGenerator.cpp. Currently, the program generates markdown files. I could imagine that it generates the completion script in addition to the markdown. Or of course, a data structure read by a completion template.

How do you think the completion script should be distributed?

Andreas

@andreasfertig andreasfertig added enhancement New feature or request awaiting-followup Waiting for more input labels Feb 20, 2023
@Freed-Wu
Copy link
Contributor Author

How do you think the completion script should be distributed?

Do you means install this completion script? https://github.com/lyokha/g3kb-switch/blob/master/CMakeLists.txt#L39-L45 should be a reference. (Although their shell completion script is written manually.)

@andreasfertig
Copy link
Owner

Hello @Freed-Wu

How do you think the completion script should be distributed?

Do you means install this completion script? https://github.com/lyokha/g3kb-switch/blob/master/CMakeLists.txt#L39-L45 should be a reference. (Although their shell completion script is written manually.)

sorry, I was imprecise. I meant where to store it. Only in git or also as part of the release download.

Andreas

@Freed-Wu
Copy link
Contributor Author

where to store it

The packagers of distributions usually build the package (.deb, .rpm, .pkg.tar.zst, ...) from source code, include the shell completion scripts, like https://github.com/archlinux/svntogit-community/blob/packages/trash-cli/trunk/PKGBUILD#L31-L34, so don't need to provide a pre-build shell completion scripts in git repo or in github release.

However, if you provide a pre-build shell completion scripts (such as create it by CI/CD then publish it in github release) is also OK.

@andreasfertig
Copy link
Owner

Hello @Freed-Wu,

thanks for sharing this. I'm looking for a way to reach people with the completion script. Since I'm not creating a package (at the moment), I'm looking for a way to make the script easily accessible. I have to think about this a bit more.

Andreas

@andreasfertig andreasfertig removed the awaiting-followup Waiting for more input label Feb 22, 2023
@andreasfertig andreasfertig added the awaiting-followup Waiting for more input label Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-followup Waiting for more input enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants