Add fish completions #24611

pull willcl-ark wants to merge 3 commits into bitcoin:master from willcl-ark:fish_completions changing 10 files +313 −0
  1. willcl-ark commented at 1:38 pm on March 18, 2022: contributor

    The completions are dynamically generated from the respective binary help pages.

    Completions should be sourced into the shell or added to $XDG_CONFIG/fish/completions. See where to put completions for more information.

    As the completions are auto-generated they should only require as much maintenance as the bash equivalents, which is to say very little!

  2. DrahtBot added the label Scripts and tools on Mar 18, 2022
  3. willcl-ark force-pushed on Mar 18, 2022
  4. jessebarton commented at 9:30 pm on March 18, 2022: contributor

    Concept ACK b4db43a

    Tested using Fish Version 3.3.1 on FreeBSD 13.0 RELEASE I added the completion files to ~/.config/fish/completions Worked as expected and was able to autocomplete all command arguments.

  5. luke-jr changes_requested
  6. luke-jr commented at 2:22 am on March 19, 2022: member
    I realise we don’t have this for the existing bash-completion scripts, but I think we should probably have these in a new contrib/fish-completion subdirectory (or perhaps contrib/completion/{bash,fish} and move the bash-completion too)
  7. jessebarton commented at 5:01 am on March 19, 2022: contributor
    I agree. contrib/completion/{bash,fish} makes the most sense to me.
  8. willcl-ark commented at 4:55 pm on March 19, 2022: contributor

    I realise we don’t have this for the existing bash-completion scripts, but I think we should probably have these in a new contrib/fish-completion subdirectory (or perhaps contrib/completion/{bash,fish} and move the bash-completion too)

    Also agree with this.

    Unless there are any strong objections I will retouch with completions in subfolders.

  9. jessebarton approved
  10. fanquake commented at 11:56 am on March 21, 2022: member

    Unless there are any strong objections I will retouch with completions in subfolders.

    I think that’s fine to do.

    As the completions are auto-generated they should only require as much maintenance as the bash equivalents, which is to say very little!

    That’s good at least.

    Is there any reason you’ve excluded the other utilities?

    You could add yourself to the REVIEWERS file for contrib/completion/*.

  11. willcl-ark commented at 12:27 pm on March 21, 2022: contributor

    I think that’s fine to do.

    Great I will re-arrange like this then.

    Is there any reason you’ve excluded the other utilities?

    Which utilities to do you mean in this context? I included bitcoind, bitcoin-cli and bitcoin-tx here.

    You could add yourself to the REVIEWERS file for contrib/completion/*.

    Sure, ok

  12. willcl-ark force-pushed on Mar 21, 2022
  13. fanquake commented at 1:58 pm on March 21, 2022: member

    Which utilities to do you mean in this context? I included bitcoind, bitcoin-cli and bitcoin-tx here.

    We also have bitcoin-wallet, bitcoin-util.

  14. willcl-ark commented at 3:21 pm on March 21, 2022: contributor

    Which utilities to do you mean in this context? I included bitcoind, bitcoin-cli and bitcoin-tx here.

    We also have bitcoin-wallet, bitcoin-util.

    Ah right. I can certainly add those. I was just starting by essentially mirroring what we have in bash, but very happy to give fish superior completion support :)

    I will add it into the fish completions commit.

  15. josibake approved
  16. josibake commented at 3:41 pm on March 21, 2022: member

    Strong Concept ACK!

    Thanks for doing this. I use the bash completions so I haven’t tested this locally, but a big fan of having more autocomplete options, as it’s a big usability improvement for the tools.

    One suggestion regarding commit hygiene (feel free to ignore): prefix the commits with the relevant tags, e.g refactor: ... for the first, scripts: ... for the second, and doc: ... for the third

  17. lsilva01 commented at 11:11 pm on March 21, 2022: contributor
    Concept ACK
  18. laanwj commented at 5:27 pm on March 31, 2022: member

    Concept ACK, and agree the new directory structure is better.

    Edit: might want to add a small mention to contrib/README.md of the completions directory.

  19. jarolrod commented at 8:53 am on April 4, 2022: member

    Concept ACK

    paging @willcl-ark; this needs updating, and I want to get fishy 🐟

  20. willcl-ark commented at 8:54 am on April 4, 2022: contributor

    Concept ACK

    paging @willcl-ark; this needs updating, and I want to get fishy 🐟

    Ping received! I’ll update and finish this ASAP.

  21. laanwj added the label Waiting for author on Apr 15, 2022
  22. willcl-ark force-pushed on Jul 4, 2022
  23. willcl-ark force-pushed on Jul 4, 2022
  24. willcl-ark force-pushed on Jul 5, 2022
  25. willcl-ark commented at 10:45 am on July 5, 2022: contributor

    Finally updated, sorry about the delay.

    • Simplified all completions to simply provide commands and options (no path completions, which is kind of a shame as they are nice in fish, but they populated the top-level completion list making it longer by the number of files and directories in $CWD, which was annoying).
    • added the missing utilities
    • Added a note in contrib/README.md
  26. willcl-ark force-pushed on Jul 6, 2022
  27. DrahtBot commented at 11:24 pm on July 14, 2022: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK josibake, achow101
    Concept ACK jessebarton, lsilva01, laanwj, jarolrod

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    No conflicts as of last run.

  28. willcl-ark force-pushed on Jul 15, 2022
  29. willcl-ark commented at 10:23 am on July 15, 2022: contributor
    Dropped the REVIEWERS commit as the document looks to be imminently removed
  30. josibake commented at 5:44 pm on July 19, 2022: member
    while testing, i noticed that the bash completions allow you to do bitcoin-cli help <tab> and get completions, which is very helpful. doesn’t seem to work with the fish completions but im guessing it’s a fairly easy fix?
  31. willcl-ark commented at 5:57 pm on July 19, 2022: contributor

    while testing, i noticed that the bash completions allow you to do bitcoin-cli help <tab> and get completions, which is very helpful. doesn’t seem to work with the fish completions but im guessing it’s a fairly easy fix?

    Thanks for the nudge.

    Yes this should simply require adding help as a subcommand, which I shall try shortly.

  32. willcl-ark force-pushed on Jul 19, 2022
  33. willcl-ark commented at 7:52 pm on July 19, 2022: contributor
    Now added an exclusion for bitcoin-cli help <tab> in db85a5214894e813d4d7aad3dcf28dc19c2aa293 so that it shows completions.
  34. josibake commented at 7:51 am on July 20, 2022: member

    ACK https://github.com/bitcoin/bitcoin/pull/24611/commits/db85a5214894e813d4d7aad3dcf28dc19c2aa293

    tested by adding files to ~/.config/fish/completions/ and trying bitcoin-cli <tab> and bitcoin-cli help <tab>. works great, thanks for adding these! using bitcoin-cli help <tab> is a really great way to quickly check the docs on commands, making bitcoin-cli much more usable

  35. maflcko removed the label Waiting for author on Jul 20, 2022
  36. achow101 commented at 8:53 pm on October 25, 2022: member

    Concept ACK

    I use fish and would like to have completions. However the implementation here has some issues, although not necessarily blocking ones.

    • If either mainnet bitcoind of bitcoin-qt -server is not running, then the autocompletion for bitcoin-cli shows error: and Make as autocompletions. These are the first words of the error it gives when the RPC server is not found. They should probably be excluded from the completion.
    • The -help-debug options are missing. While these are debug options, some commonly used ones such as -regtest are part of them and I expect that the only people who would be using these completions are developers who also use those debug options. So it might make sense to include them as well.
    • bitcoin-qt should have completions
    • Attempting to get a completion with the relative path to the binary results in an error:
     0> src/bitcoind ~/.config/fish/completions/bitcoind.fish (line 1): Unknown command. '/home/andy/.pyenv/libexec/pyenv/bitcoind' exists but is not an executable file.
     1bitcoind --help | sed -n '/^  -/p' | sed -e 's/  -/-/;s/=.*/=/' | sed -n '/\?$/!p'
     2^
     3in command substitution
     4	called on line 5 of file ~/.config/fish/completions/bitcoind.fish
     5from sourcing file ~/.config/fish/completions/bitcoind.fish
     6~/.config/fish/completions/bitcoind.fish (line 5): Command not executable
     7set --local options (bitcoind --help | sed -n '/^  -/p' | sed -e 's/  -/-/;s/=.*/=/' | sed -n '/\?$/!p')
     8                    ^
     9from sourcing file ~/.config/fish/completions/bitcoind.fish
    10complete --no-files bitcoind
    
    • Completions that require user provided parameter (those that show up as ending with a =) put a space after the option which requires an additional backspace in order to be able to set the parameter.
  37. willcl-ark commented at 11:13 am on October 26, 2022: contributor

    Thanks for the ping on this, I will fix and rework it as suggested.

    A thought I had; might it be more useful (and faster runtime) to have a generate_fish_completions.fish script in this repo, which you could run once to generate completions once and install them wherever you choose? This way too we don’t poll e.g. bitcoin-cli help with each tab on autocomplete? You could just re-run the script after you compile, if you want to update completions.

    It would want to be run with bitcoind/bitcoin-qt running so that it generated all the correct completions, but other than that it would work better IMO, except from the fact that it would not be dynamic w.r.t. the current version of bitcoin installed automatically.

    I haven’t personally noticed any runtime performance issue tbh, but thinking about how to fix the error and Make autocompletions you mention above made me wonder if the above approach might be a little better…

  38. willcl-ark commented at 12:39 pm on October 26, 2022: contributor

    Status:

    • If either mainnet bitcoind of bitcoin-qt -server is not running, then the autocompletion for bitcoin-cli shows error: and Make as autocompletions. These are the first words of the error it gives when the RPC server is not found. They should probably be excluded from the completion.

      Note: This might be harder to fix than it seems, as it appears to me that fish autocomplete is calling bitcoin-cli in the background regardless of how I gate the call inside the completion file itself, still investigating further though.

    • The -help-debug options are missing. While these are debug options, some commonly used ones such as -regtest are part of them and I expect that the only people who would be using these completions are developers who also use those debug options. So it might make sense to include them as well.

    • bitcoin-qt should have completions

    • Attempting to get a completion with the relative path to the binary results in an error @achow101 do you mean that you are trying to get completions from e.g. a binary in a build dir? If so I am unsure that this will be easily possible without asking the user to remove all completions first (`complete -c binary_name -e) and then re-sourcing the completion file. And even then, there would need to be some logic to check CWD and see if we dynamically generate for binary in current dir, or on PATH. Even if we got all that working, user would need to re-generate each time they wanted to switch between a local dir binary and binary on PATH (to the best of my knowledge)…

    • Completions that require user provided parameter (those that show up as ending with a =) put a space after the option which requires an additional backspace in order to be able to set the parameter.

  39. willcl-ark force-pushed on Oct 26, 2022
  40. achow101 commented at 3:10 pm on October 26, 2022: member

    do you mean that you are trying to get completions from e.g. a binary in a build dir?

    Yes

    If so I am unsure that this will be easily possible without asking the user to remove all completions first (`complete -c binary_name -e) and then re-sourcing the completion file. And even then, there would need to be some logic to check CWD and see if we dynamically generate for binary in current dir, or on PATH. Even if we got all that working, user would need to re-generate each time they wanted to switch between a local dir binary and binary on PATH (to the best of my knowledge)…

    It doesn’t necessarily need to work with relative paths, it just can’t be throwing an error.

  41. willcl-ark force-pushed on Oct 29, 2022
  42. willcl-ark commented at 4:32 pm on October 29, 2022: contributor

    Hey @achow101 I think this is ready for a re-test now as I’ve addressed all your previous comments :)

    It should work with relative binaries, as well as not throw any errors if the RPC backend is offline. I also changed the style of the completions to use fish functions so that completions are always dynamically loaded against the current commandline contents which avoids vachine potentially stale completions as it was before.

  43. achow101 commented at 5:39 pm on November 10, 2022: member

    ACK 803223377c85668a80946a5d5bd22decd1bfd6a4

    Tested manually and completions appear to be as expected.

  44. willcl-ark force-pushed on Nov 11, 2022
  45. willcl-ark commented at 2:13 pm on November 11, 2022: contributor

    Sorry to change after an ACK, but I’ve found that this was swallowing help completions. This fix to only use the first token from the commandline in 15aafd3 fixes this for me.

    git range-diff 8032233...15aafd3ac

  46. achow101 commented at 8:47 pm on November 17, 2022: member
    There appear to be command completions for bitcoin-cli even if the command already has an RPC in it.
  47. josibake commented at 6:03 pm on November 21, 2022: member

    There appear to be command completions for bitcoin-cli even if the command already has an RPC in it.

    I also noticed this but it seems to only happen for RPC commands which also take arguments. For example:

    0bitcoin-cli abortrescan <TAB>
    

    does nothing (expected behavior).

    However:

    0bitcoin-cli abandontransaction <TAB>
    

    brings up the autocomplete list again. I also tested bitcoin-cli help <TAB> and this works as expected

  48. willcl-ark force-pushed on Nov 22, 2022
  49. willcl-ark force-pushed on Nov 22, 2022
  50. refactor: Sub-folder bash completions
    Move bash completions to
    contrib/completions/bash/*
    
    Precursor to adding fish completions
    a27a445b71
  51. willcl-ark force-pushed on Nov 28, 2022
  52. script: Add fish completions
    Completions are dynamically generated from the respective binary help
    pages.
    
    Completions should be sourced into the shell or added to
    $XDG_CONFIG/fish/completions.
    7075848f96
  53. doc: Add completion subdir to contrib/README.md ccba4fe7e3
  54. willcl-ark force-pushed on Nov 28, 2022
  55. josibake approved
  56. josibake commented at 2:39 pm on November 29, 2022: member

    ACK https://github.com/bitcoin/bitcoin/commit/ccba4fe7e3113f5d3bb2fbe54147b3a17e1bfa24

    manually tested, both bitcoin-cli <TAB> and bitcoin-cli help <TAB> bring up the options and verified that bitcoin-cli command <TAB> doesn’t keep bringing up the autocomplete.

  57. achow101 commented at 9:21 pm on December 5, 2022: member
    ACK ccba4fe7e3113f5d3bb2fbe54147b3a17e1bfa24
  58. achow101 merged this on Dec 7, 2022
  59. achow101 closed this on Dec 7, 2022

  60. sidhujag referenced this in commit f4cc1bff93 on Dec 8, 2022
  61. bitcoin locked this on Dec 7, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-21 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me