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

add truffle cli bash completions #2107

Closed
wants to merge 5 commits into from
Closed

Conversation

tbhaxor
Copy link
Contributor

@tbhaxor tbhaxor commented Mar 5, 2022

Description

Truffle is a nodejs tool used for development of the blockchain projects by provide an features like scaffolding, testing and deployment

Motivation and Context

Couldn't find any completion over internet. So tried my own

How Has This Been Tested?

Manually on the local system in macOS

Screenshots (if appropriate):

Screenshot 2022-03-06 at 4 12 03 AM

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

@tbhaxor
Copy link
Contributor Author

tbhaxor commented Mar 5, 2022

@gaelicWizard Could you help me understand meaning of -X "!&*" option in complete command?

@gaelicWizard
Copy link
Contributor

meaning of -X "!&*" option in complete

@tbhaxor, usually lots of people do complicated use of compgen something like:

options=('--version' '--help' '--verbose')
COMPREPLY=( $(compgen -W "${options[*]} -- "$cur") )

The point of code like this is to filter the possible completions to only match what has already been typed, as opposed to all possible options. E.g., don't offer --help when the user has already typed --v.

BUT, that whole mess is unnecessary. The completion function can just always return all available options without filtering, and then adding -X '!&*' tells Bash to filter the returned completions based on what the user already typed.

-X means to exclude anything matching the pattern from completions, ! means not, & means "the word already typed", and * means anything. So, exclude anything matching "not the word already typed with anything after". I only learned this a month or so ago!


Bash manual:

complete [-abcdefgjksuv] [-o comp-option] [-DEI] [-A action] [-G globpat] [-W wordlist]
[-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] name [name ...]

-X filterpat
filterpat is a pattern as used for pathname expansion. It is applied to the list of possible
completions generated by the preceding options and arguments, and each completion matching fil-
terpat is removed from the list. A leading ! in filterpat negates the pattern; in this case,
any completion not matching filterpat is removed.

The ampersand is not documented in the manual, but the web site says this:

After all of the possible completions are generated, any filter specified with the -X option is applied to the list. The filter is a pattern as used for pathname expansion; a ‘&’ in the pattern is replaced with the text of the word being completed.

@NoahGorny
Copy link
Member

@gaelicWizard - can you take a look at the failing test? this also happens to me locally (test/run not executing any tests..)

@gaelicWizard
Copy link
Contributor

@NoahGorny I've been seeing this one intermittently of late, but can't reproduce on my own OSX 11.6. It's just skipping some tests!!!!

It's driving me batty. My best guess is that something in test_helper.bash is failing and exiting, but because it's not within a function it's not being reported. I'm going to try doing what BATS documentation recommends: load the common setup from within setup(), not the other way around. That way at least we'll get the error message...I think...

@tbhaxor
Copy link
Contributor Author

tbhaxor commented Mar 6, 2022

@gaelicWizard @NoahGorny This is kinda false positive as in this PR the test failed on macos 11 and in recent push it failed on macos 10.15. Check this

@tbhaxor
Copy link
Contributor Author

tbhaxor commented Feb 23, 2023

Not required

@tbhaxor tbhaxor closed this Feb 23, 2023
@tbhaxor tbhaxor deleted the patch-2 branch February 23, 2023 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants