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

docs/Shell-Completion: read both types of bash completions. #5625

Merged
merged 1 commit into from
Jan 28, 2019
Merged

docs/Shell-Completion: read both types of bash completions. #5625

merged 1 commit into from
Jan 28, 2019

Conversation

MikeMcQuaid
Copy link
Member

And guard against either of them being missing.

Fixes #5610

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

And guard against either of them being missing.

Fixes #5610
@MikeMcQuaid MikeMcQuaid merged commit 424d5a1 into Homebrew:master Jan 28, 2019
@MikeMcQuaid MikeMcQuaid deleted the shell-completion branch January 28, 2019 17:32
@ikatza
Copy link

ikatza commented Feb 21, 2019

Hey for whatever reason the first if doesn't evaluate to true on my case:

if type brew 2&>/dev/null; then echo "inside"; fi prints nothing.

Doing:

if type brew &>/dev/null; then echo "inside"; fi yields
inside

echo $BASH_VERSION
5.0.2(1)-release

and also tried on Linux with bash version 4.2.+.

@MikeMcQuaid
Copy link
Member Author

@ikatza What does which brew output on your system?

@ikatza
Copy link

ikatza commented Feb 21, 2019

$ which brew
/usr/local/bin/brew

$ type brew
brew is /usr/local/bin/brew

@MikeMcQuaid
Copy link
Member Author

@ikatza You'll need to figure this out yourself, then, that all looks like it should work.

@ikatza
Copy link

ikatza commented Feb 21, 2019

Well that's kinda of what I did.

I've been googling for the 2&> redirection idiom, but can't find that specific combination.
I found the &> idiom that redirects STDOUT and STDERR.

$ if type brew &>/dev/null; then echo "inside"; fi
inside
 
$ if type brewwww &>/dev/null; then echo "inside"; fi

@maxim-belkin
Copy link
Member

2&> is not a valid redirection instruction in Bash.
You don't need to google stuff that you can find with man bash:

   Redirecting Standard Output and Standard Error
       This construct allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be  redi-
       rected to the file whose name is the expansion of word.

       There are two formats for redirecting standard output and standard error:

              &>word
       and
              >&word

       Of the two forms, the first is preferred.  This is semantically equivalent to

              >word 2>&1

       When using the second form, word may not expand to a number or -.  If it does, other redirection operators apply (see Duplicating
       File Descriptors below) for compatibility reasons.

@maxim-belkin
Copy link
Member

Oh! There is a typo in instructions!

@@ -12,13 +12,19 @@ To make Homebrew's completions available in `bash`, you must source the definiti

```sh
if type brew 2&>/dev/null; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the typo

MikeMcQuaid added a commit that referenced this pull request Feb 21, 2019
Fixes the issue noted in #5625.
@MikeMcQuaid
Copy link
Member Author

I also misread that typo, my apologies @ikatza. Opened a PR in #5781

@raldred
Copy link

raldred commented Mar 1, 2019

I get masses of errors when using this snippet in my bashrc

-bash: have: command not found
-bash: /usr/local/etc/bash_completion.d/ant: line 45: syntax error in conditional expression: unexpected token `('
-bash: /usr/local/etc/bash_completion.d/ant: line 45: syntax error near `-@(?'
-bash: /usr/local/etc/bash_completion.d/ant: line 45: `            if [[ "${COMP_WORDS[i]}" == -@(?(build)file|f) ]]; then'
-bash: have: command not found
-bash: /usr/local/etc/bash_completion.d/apt: line 12: syntax error in conditional expression: unexpected token `('
....[clipped]

Full output here: https://gist.github.com/raldred/098801f9ea47bd37c64652af2ef35baf

@maxim-belkin
Copy link
Member

This means you have bash-completion installed and your Bash is newer. Uninstall bash-completion.

@lock lock bot added the outdated PR was locked due to age label Mar 31, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants