Inquirer.js: Running under a git hook auto answers

Created on 22 Mar 2017  路  6Comments  路  Source: SBoudrias/Inquirer.js

I'm using inquirer to build a little CLI tool, great library!

I have a script that's my pre-push hook for git below

#!/bin/bash
node ~/my-script.js || exit

When running under git it auto-populates the answer in inquirer, when I run the script manually it works and asks me the question. I've been reading through the issues but I can't figure out why this might happen.

Most helpful comment

@bapti Brilliant!!! this thread saved the day.

Since my team uses Husky to manage githooks it was as simple as:

    "postcommit": "my-script < /dev/tty"

thanks again!!

All 6 comments

Inquirer won't run in non-tty environment. The git hook is probably called in a sub process or a process without access to the prompt tty.

Thanks @SBoudrias for the quick response, more googling required from me then! Thanks for the hint

Thanks again @SBoudrias - this was the hint I needed

Adding the following command to my pre-hook has made my tool work as expected

exec < /dev/tty #allow interactive shell commands

@bapti Brilliant!!! this thread saved the day.

Since my team uses Husky to manage githooks it was as simple as:

    "postcommit": "my-script < /dev/tty"

thanks again!!

On our Windows (git bash) development machines, having"< /dev/tty" inside the package.json Husky command failed with: "The system cannot find the path specified."

This alternate approach worked:

package.json:
"pre-push": "sh hooks/prepush.sh"

prepush.sh:

!/bin/sh

exec < /dev/tty

node ./hooks/prepush/script.js

@bapti @SBoudrias @eitah it took me hours to solve this problem, thanks guys you are my heroes!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PierBover picture PierBover  路  6Comments

Mrooze-zeng picture Mrooze-zeng  路  5Comments

adalinesimonian picture adalinesimonian  路  6Comments

dantasfiles picture dantasfiles  路  3Comments

ro31337 picture ro31337  路  5Comments