compgen usage error when attempting to complete “--” flags












0















I'm attempting to do bash completion for a command, and everything is working as normal with the full word commands, but when I try to complete the "--" flags, with the following code (following by a complete -F _keybase keybase) using any letter after the two tacks (i.e. keybase --h<TAB>) I get a compgen usage error. (keybase --<TAB> works as expected however). This is on Ubuntu 18.04. I'm sourcing this file in the current shell session and not as part of a logon script (yet).



_keybase() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

#...code removed for brevity

if [[ ${cur} == -* ]]; then
# complete the "--" parameters
opts=$(keybase help advanced | grep -Po '--[a-z-]+' | tr "n" " ")
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
fi
}


This is what prints out when I type keybase --h<TAB>



keybase --hbash: compgen: --: invalid option
compgen: usage: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]


I tweaked the escaping of the quotes, and added/removed the newlines in the defintion of $opt and added/removed the "--" as the second argument to compgen (I added these at the behest of a Debian article explaing bash completion
keybase help advanced | grep -Po '--[a-z-]+' | tr "n" " " outputs:



--api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version 


and when I echo the command that compgen is expected to run with echo "compgen -W "${opts}" -- ${cur}" I get the command I expect and indeed one that runs just fine at the terminal:



compgen -W "--api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version " -- --h
--home
--help


Halp plz?









share







New contributor




Christopher Morrow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I'm attempting to do bash completion for a command, and everything is working as normal with the full word commands, but when I try to complete the "--" flags, with the following code (following by a complete -F _keybase keybase) using any letter after the two tacks (i.e. keybase --h<TAB>) I get a compgen usage error. (keybase --<TAB> works as expected however). This is on Ubuntu 18.04. I'm sourcing this file in the current shell session and not as part of a logon script (yet).



    _keybase() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    #...code removed for brevity

    if [[ ${cur} == -* ]]; then
    # complete the "--" parameters
    opts=$(keybase help advanced | grep -Po '--[a-z-]+' | tr "n" " ")
    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    fi
    }


    This is what prints out when I type keybase --h<TAB>



    keybase --hbash: compgen: --: invalid option
    compgen: usage: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]


    I tweaked the escaping of the quotes, and added/removed the newlines in the defintion of $opt and added/removed the "--" as the second argument to compgen (I added these at the behest of a Debian article explaing bash completion
    keybase help advanced | grep -Po '--[a-z-]+' | tr "n" " " outputs:



    --api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version 


    and when I echo the command that compgen is expected to run with echo "compgen -W "${opts}" -- ${cur}" I get the command I expect and indeed one that runs just fine at the terminal:



    compgen -W "--api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version " -- --h
    --home
    --help


    Halp plz?









    share







    New contributor




    Christopher Morrow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I'm attempting to do bash completion for a command, and everything is working as normal with the full word commands, but when I try to complete the "--" flags, with the following code (following by a complete -F _keybase keybase) using any letter after the two tacks (i.e. keybase --h<TAB>) I get a compgen usage error. (keybase --<TAB> works as expected however). This is on Ubuntu 18.04. I'm sourcing this file in the current shell session and not as part of a logon script (yet).



      _keybase() {
      local cur prev opts
      COMPREPLY=()
      cur="${COMP_WORDS[COMP_CWORD]}"
      prev="${COMP_WORDS[COMP_CWORD-1]}"

      #...code removed for brevity

      if [[ ${cur} == -* ]]; then
      # complete the "--" parameters
      opts=$(keybase help advanced | grep -Po '--[a-z-]+' | tr "n" " ")
      COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
      fi
      }


      This is what prints out when I type keybase --h<TAB>



      keybase --hbash: compgen: --: invalid option
      compgen: usage: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]


      I tweaked the escaping of the quotes, and added/removed the newlines in the defintion of $opt and added/removed the "--" as the second argument to compgen (I added these at the behest of a Debian article explaing bash completion
      keybase help advanced | grep -Po '--[a-z-]+' | tr "n" " " outputs:



      --api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version 


      and when I echo the command that compgen is expected to run with echo "compgen -W "${opts}" -- ${cur}" I get the command I expect and indeed one that runs just fine at the terminal:



      compgen -W "--api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version " -- --h
      --home
      --help


      Halp plz?









      share







      New contributor




      Christopher Morrow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I'm attempting to do bash completion for a command, and everything is working as normal with the full word commands, but when I try to complete the "--" flags, with the following code (following by a complete -F _keybase keybase) using any letter after the two tacks (i.e. keybase --h<TAB>) I get a compgen usage error. (keybase --<TAB> works as expected however). This is on Ubuntu 18.04. I'm sourcing this file in the current shell session and not as part of a logon script (yet).



      _keybase() {
      local cur prev opts
      COMPREPLY=()
      cur="${COMP_WORDS[COMP_CWORD]}"
      prev="${COMP_WORDS[COMP_CWORD-1]}"

      #...code removed for brevity

      if [[ ${cur} == -* ]]; then
      # complete the "--" parameters
      opts=$(keybase help advanced | grep -Po '--[a-z-]+' | tr "n" " ")
      COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
      fi
      }


      This is what prints out when I type keybase --h<TAB>



      keybase --hbash: compgen: --: invalid option
      compgen: usage: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word]


      I tweaked the escaping of the quotes, and added/removed the newlines in the defintion of $opt and added/removed the "--" as the second argument to compgen (I added these at the behest of a Debian article explaing bash completion
      keybase help advanced | grep -Po '--[a-z-]+' | tr "n" " " outputs:



      --api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version 


      and when I echo the command that compgen is expected to run with echo "compgen -W "${opts}" -- ${cur}" I get the command I expect and indeed one that runs just fine at the terminal:



      compgen -W "--api-dump-unsafe --api-timeout --api-uri-path-prefix --app-start-mode --bg-identifier-disabled --chat-db --code-signing-kids --config-file --use-root-config-file --db --debug --display-raw-untrusted-output --features --gpg --gpg-options --home --leveldb-num-files --local-rpc-debug-unsafe --log-file --ek-log-file --log-format --log-prefix --merkle-kids --no-debug --debug --pgpdir --gpgdir --pid-file --pinentry --proof-cache-size --proxy --push-disabled --push-save-interval --push-server-uri --pvl-kit --paramproof-kit --prove-bypass --remember-passphrase --run-mode --scraper-timeout --secret-keyring --server --session-file --slow-gregor-conn --read-deleted-sigchain --socket-file --standalone --timers --tor-hidden-address --tor-mode --tor-proxy --updater-config-file --upgrade-per-user-key --use-default-log-file --user-cache-size --vdebug --disable-team-auditor --disable-merkle-auditor --disable-search-indexer --disable-bg-conv-loader --enable-bot-lite-mode --auto-fork --no-auto-fork --help --generate-bash-completion --version " -- --h
      --home
      --help


      Halp plz?







      bash ubuntu





      share







      New contributor




      Christopher Morrow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      Christopher Morrow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      Christopher Morrow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 min ago









      Christopher MorrowChristopher Morrow

      11




      11




      New contributor




      Christopher Morrow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Christopher Morrow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Christopher Morrow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Christopher Morrow is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499858%2fcompgen-usage-error-when-attempting-to-complete-flags%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Christopher Morrow is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Christopher Morrow is a new contributor. Be nice, and check out our Code of Conduct.













          Christopher Morrow is a new contributor. Be nice, and check out our Code of Conduct.












          Christopher Morrow is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499858%2fcompgen-usage-error-when-attempting-to-complete-flags%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          サソリ

          広島県道265号伴広島線

          Accessing regular linux commands in Huawei's Dopra Linux