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

GNU make: grc causes shell builtin read -p "prompt text: " to not print to terminal in Makefile #82

Open
trinitronx opened this issue Feb 28, 2018 · 3 comments

Comments

@trinitronx
Copy link

trinitronx commented Feb 28, 2018

When using the read -r -p "some prompt here: " bash builtin and having grc loaded into the shell, it appears that the prompt is never displayed. This can cause confusion with things that spawn sub-shells such as make, and probably some bash scripts (maybe other tools too).

Here is a Makefile to reproduce the issue

To reproduce:

  1. Install & load grc into ~/.bashrc
  • For example: brew install grc , then add the following to ~/.bashrc: source "$(brew --prefix)/etc/grc.bashrc"
  1. Spawn a bash shell & cd to the directory with this Makefile
  2. Run make test
  3. Watch as you are not prompted by read (as the Makefile is written to do)
  4. Press enter and see that read was actually expecting input, which you were unaware of
  5. Try again, this time typing something and hitting enter... now it shows you it did read some input and set a variable.

Then, try commenting out the source line which loads grc into the shell. Retry the same make test and see the prompt is shown.

I'm stumped as to why loading grc is affecting shell builtins in this way... the entire contents of the file under $(brew --prefix)/etc/grc.bashrc only has alias definitions:

GRC=`which grc`
if [ "$TERM" != dumb ] && [ -n "$GRC" ]
then
    alias colourify="$GRC -es --colour=auto"
    alias configure='colourify ./configure'
    alias diff='colourify diff'
    alias make='colourify make'
    alias gcc='colourify gcc'
    alias g++='colourify g++'
    alias as='colourify as'
    alias gas='colourify gas'
    alias ld='colourify ld'
    alias netstat='colourify netstat'
    alias ping='colourify ping'
    alias traceroute='colourify /usr/sbin/traceroute'
    alias head='colourify head'
    alias tail='colourify tail'
    alias dig='colourify dig'
    alias mount='colourify mount'
    alias ps='colourify ps'
    alias mtr='colourify mtr'
    alias df='colourify df'
fi

I've tested this with:

bash --version = GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin15.6.0)
make --version = GNU Make 3.81
grc --version = Generic Colouriser 1.11.1 (from Homebrew)

And it also appears to affect the default shell /bin/sh on mac as well:

/bin/sh
sh-3.2$ source "`brew --prefix`/etc/grc.bashrc"
sh-3.2$ make test

You must specify SOME_ENV_VAR or set env variable SOME_ENV_VAR !
Enter SOME_ENV_VAR (eg 'bar') (set environment variable SOME_ENV_VAR to skip this prompt): make: *** [test] Error 1

/bin/sh --version = GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
make --version = GNU Make 3.81
grc --version = Generic Colouriser 1.11.1 (from Homebrew)

@trinitronx
Copy link
Author

Ah, I see why it's being used in this case... it's this: alias make='colourify make'

@trinitronx trinitronx changed the title grc causes shell builtin read -p "prompt text: " to not print to terminal GNU make: grc causes shell builtin read -p "prompt text: " to not print to terminal in Makefile Mar 6, 2018
@trinitronx
Copy link
Author

trinitronx commented Mar 6, 2018

FYI: I have validated that this behavior has something to do with the -es flags defined in the alias colourify="$GRC -es --colour=auto"

Editing the grc.bashrc file and taking these out for the make alias seems to fix the output from read:

vi $(brew --prefix)/etc/grc.bashrc:

Edits made:

GRC="$(which grc)"
if [ "$TERM" != dumb ] && [ -n "$GRC" ]; then
    alias colourify="$GRC -es --colour=auto"
# [...SNIP...]
# BEGIN EDIT
#    alias make='colourify make'
    alias colorspecial='$GRC --colour=auto'
    alias make='colorspecial make'
# END EDIT
# [...SNIP...]

@trinitronx
Copy link
Author

I have a hunch that this was related to pipe buffering, and could possibly be mitigated by stdbuf. Although it's untested on macOS, and I don't have the same system and particular Makefile setup from years ago to reproduce.

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

No branches or pull requests

1 participant