From 6c2ad1e74b947b49fbb55c52da5cd29fccd238a0 Mon Sep 17 00:00:00 2001 From: Evan Purcer Date: Thu, 7 Dec 2023 10:53:50 -0800 Subject: [PATCH] 1.0.4 :: add NX_EXTEND_ALIASES feature --- nx.sh | 8 +++++--- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/nx.sh b/nx.sh index 8f7264f..6d169b3 100755 --- a/nx.sh +++ b/nx.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# :: nx 1.0.3 :: +# :: nx 1.0.4 :: # shellcheck disable=SC2139 # shellcheck.net/wiki/SC2139 # allow parameter expansion within alias strings # function nx() ( local pkg="" cmd="" npmcmds="" npmcmds="$( npm -h | awk '/access/,/whoami/' | sed -E 's/ (help|start|test),//g' | xargs | sed 's/, /|/g' )" || true @@ -17,9 +17,11 @@ function nx() ( local pkg="" cmd="" npmcmds="" done # :: call "nvm use" automatically before running commands :: to enable auto-nvm behavior, export NX_NVM=1; source "$HOME/nx/nx.sh" :: [[ "${NX_NVM}" =~ ^(1|true|TRUE)$ ]] && nvm use &>/dev/null - # :: await confirmation of current node+npm versions before executing command :: to enable await-confirm behavior, export NX_CONFIRM=1; source "$HOME/nx/nx.sh" :: + # :: await confirmation of current node+npm versions before executing command :: to enable await-confirm behavior, export NX_CONFIRM=1 source "$HOME/nx/nx.sh" :: if [[ "${NX_CONFIRM}" =~ ^(1|true|TRUE)$ ]]; then read -rsn1 -p "${cmd[*]} ${*}"$'\n'"${cmd[*]//?/˙} ${*//?/˙}"$'\n'"Press any key to run · CTRL+C to cancel · node $( node -v ) · npm $( npm -v )"$'\n\n' + elif ! [[ "${NX_QUIET}" =~ ^(1|true|TRUE)$ ]]; then + echo "${cmd[*]} ${*}"$'\n'"${cmd[*]//?/˙} ${*//?/˙}"$'\n'"node $( node -v | tr -d 'v' ) · npm $( npm -v | tr -d 'v' )"$'\n\n' fi if (( $# )); then "${cmd[@]}" "${@}" # :: execute npm command with additional args:: @@ -33,7 +35,7 @@ function nx() ( local pkg="" cmd="" npmcmds="" # ns -> npm start nk -> npm link ni -> npm install nu -> npm uninstall nis, nid, nus, nud -> npm [un]install --save[-dev] if ! [[ "${NX_ALIASES}" =~ ^(0|false|FALSE)$ ]]; then alias "${NX_COMMAND:-n}"='nx' - for word in $( tr -cs '[:alnum:]._-/' ' ' <<< "${NX_ALIASES:-install,uninstall,start,test,build,format,lint,k/link,publish,help}" ); do + for word in $( tr -cs '[:alnum:]._-/' ' ' <<< "${NX_ALIASES:-install,uninstall,start,test,build,format,lint,k/link,publish,help},${NX_EXTEND_ALIASES:-}" ); do [[ "${NX_COMMAND}" =~ ^(0|false|FALSE)$ ]] && NX_COMMAND='nx' alias "${NX_COMMAND:-n}${word:0:1}"="nx ${word#[a-z]/}"; [[ -n "${NX_VERBOSE}" ]] && alias "${NX_COMMAND:-n}${word:0:1}" if [[ "${word}" =~ ^(un)?install$ ]]; then diff --git a/package-lock.json b/package-lock.json index 1b4b383..a9cb55c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nx.sh", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "nx.sh", - "version": "1.0.3", + "version": "1.0.4", "license": "MIT", "bin": { "nx": "nx" diff --git a/package.json b/package.json index e130886..9a04ef4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nx.sh", - "version": "1.0.3", + "version": "1.0.4", "description": "A minimalist command runner for npm packages, with a focus on developer ergonomics.", "main": "nx.sh", "files": [