Husky: The pre-commit hook initiates the bash script, yet it does not pause for user input

Whenever I initiate a commit, the bash script starts running without waiting for user input

.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

Answer №1

Before requesting input from the user, the prompt "Please enter your choice: " was added to make it clear.

This code snippet enables reading user input and sets stdin to the keyboard.

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

challenges encountered while trying to incorporate browserify

I have a situation where I have two .js files located in the same folder. File app.js : import {foo} from 'custom'; foo(); File custom.js : function foo(){ $('.nav.navbar-nav > li').on('click', function(e) { $(&ap ...

Using the jq tool to randomly select strings from a list and replace values in a JSON structure

I have come across many questions that are similar but none specifically addressing the dynamic merging of 2 files. My goal is to dynamically modify the structure below: { "features": [ { "type": "Feature", "properties": { "name" ...

Why am I still receiving the error message "Incorrect username or password" even after successfully logging in with the correct credentials using `npm login` command?

Running npm login in terminal is unsuccessful when using my username and password, even though I can successfully log into npmjs.com website with the same credentials. Upon executing npm login, the following error is displayed: npm WARN adduser Incorrec ...

Having difficulties with running npm run, install, or rebuild on Ubuntu 16.04

After running npm install rebuild or npm install, I encountered the following error message: 1, followed by 2 This is the error that occurred when I executed npm run [my project] Error: uncaughtException: The gRPC binary module was not installed. T ...

Revamping an npm package on GitHub

Currently, I am managing a project that has gained popularity among users and has received contributions from multiple individuals. The next step I want to take is to convert the entire library into TypeScript, but I am unsure of the best approach to ach ...

Utilizing JavaScript to Incorporate Node Packages

Sorry for the basic question, as I am fairly new to web development and JavaScript. I am trying to utilize a package that I installed via npm called shopify-buy by following the instructions provided at: The package is located in my node_modules director ...

Raspberry Pi experiences issues with PM2

I attempted to set up pm2 on a Raspberry Pi. I used the command sudo npm install -g pm2: pi@raspberrypi:~ $ sudo npm install -g pm2 /usr/bin/pm2 -> /usr/lib/node_modules/pm2/bin/pm2 /usr/bin/pm2-dev -> /usr/lib/node_modules/pm2/bin/pm2-dev /usr/bin/ ...

I'm having trouble with getting npm start to function properly. I've exhausted all my options and I'm feeling lost

Every time I execute npm start in my React project, an error pops up: [email protected] start C:\Users\AyaLe\Desktop\React\myapp react-scripts start It seems there might be a problem with the project's dependency tre ...

NPM Error: Module 'balanced-match' Not Found

After updating the node and npm using nvm, I encountered an error when starting the node server. Despite trying various solutions suggested in stack overflow, none seemed to work for me. Below are the steps I tried: 1. Removed node modules and installed t ...

"Encountering an issue with Expo CLI and ADB: Unable to establish connection with daemon

Having trouble setting up expo CLI and ADB on my Windows 10 64-bit PC with the Genymotion emulator Google Pixel 3. When I try to run "on android device/emulator from expo cli," I encounter the following logs: Cannot initiate project on Android: Issue r ...

Is the inclusion of @vue/composition-api in devDependencies warranted?

Is it recommended to add @vue/composition-api to the dependencies section of the package.json instead of devDependencies? I noticed that on the npm registry it is listed under dependencies. ...

Timber: The prompt 'timber' is nowhere to be found

I have successfully set up a Rails Application on my Ubuntu 18 machine. Now, I am eager to connect it with Forest Admin - an essential requirement for which is the installation of Node Application using npm. For this purpose, I need to install the Lumber C ...

Optimal method for parsing URLs using ES6

There have been many remarkable inquiries regarding this topic, such as: how to parse a url. However, as time has gone by, the answers I come across are outdated. I am looking for a more modern and flexible method to parse URLs, without relying on regular ...

Is it possible to include comments in mocha.opts?

Is there a way to include a comment in mocha.opts file? js test --recursive --reporter spec --require ./test/test.bootstrap --require ./test/server.bootstrap --slow 200 # --delay What is the best way to disable or comment out the last line? ...

Retrieve the value from the initial element of the JSON array received from the GitAPI response within a shell script

I'm trying to retrieve the browser download URL for the latest release from a specific Git repository using the GitHub API. Sample command: curl -i https://api.github.com/repos/$owner/$repo/releases The response is in the form of a JSON array. Assu ...

Using the standard.js configuration for code linting within Intellij IDEA

I have been trying to implement standard.js for linting in my Intellij editor. Despite following the installation instructions for the node module and manually enabling linting as per Webstorm's guidance since it didn't enable automatically, I am ...

Stop processing the current websocket connection once a new websocket request is received

Currently, I am utilizing the npm ws module (or its wrapper named isomorphic-ws) for establishing a websocket connection. NPM Module: isomorphic-ws This setup allows me to retrieve an array of data from a websocket++ server situated on the same local mac ...

Make sure to add the local private NPM dependency before running the prepublish script

Within my application package.json file, I am referencing a local private NPM dependency like this: "core-module": "file:///Users/myuser/Documents/projects/core_module" My goal is to have the local private dependencies (such as core-module) automatically ...

The npm encountered an error with code ENOENT and an error number of 34

Here is my initial script setup for a React project. "scripts": { "prestart": "babel-node tools/startMessage.js", "start": "npm-run-all --parallel test:watch open:src lint:watch", "open:src": "babel-node tools/srcServer.js", "lint": "node_ ...

The function 'makeDecorator' does not support function calls when being accessed

Resolved by @alexzuza. Check out his solution below - major props! The issue was with the node_modules folder in the ng2-opd-popup directory, it needed to be removed and the src/tsconfig.app.json file had to be adjusted accordingly. Make sure to also refer ...