Front-End_tester
Front-End_tester

Reputation: 51

Husky: pre-commit hook starts the bash script, but does not wait for user selection

When I do a commit, the bash script starts but doesn't wait for the user to choose

.huskyrc file

{
  "hooks": {
    "pre-commit": "bash scripts/pre_commit.sh"
  }
}

pre_commit.sh file

   #!/bin/bash

    PS3='Please enter your choice: '
    options=("X" "Y" "Z")
    select opt in "${options[@]}"
    do
        case $opt in
            "X")
                echo "works"
                exit 0                                            
                ;;
            "Y")
                npm run test
                exit 0  
                ;;
            "Z")
                echo "Option Z";
                exit 0                                               
                ;;
            *) echo "invalid option $REPLY";;
        esac
    done
    exit 0

Upvotes: 2

Views: 4675

Answers (1)

Front-End_tester
Front-End_tester

Reputation: 51

The answer was add befor PS3='Please enter your choice: '

Allows us to read user input below, assigns stdin to keyboard

if [ -t 1 ]; then
  exec < /dev/tty
fi

Upvotes: 3

Related Questions