From 296b3544224251a3b3581384b51740d910c7e4c0 Mon Sep 17 00:00:00 2001 From: Guido Longoni Date: Fri, 23 Jan 2026 18:33:03 +0100 Subject: [PATCH] funzioni *_feat_ensure con sourcing bashrc.before e validazione pyenv global - pip_feat_ensure: ricarica .bashrc.before, verifica che pyenv global sia valido (non system, non vuoto, non versione rimossa), fallback a ultima installata - npm_feat_ensure: ricarica .bashrc.before prima di verificare npm - poetry: sourcing .bashrc.before in poetry_feat_missing e poetry_feat_needed --- featlib/npm.sh | 19 +++++++++++++++++-- featlib/pip.sh | 35 +++++++++++++++++++++++++++++++++-- featlib/poetry.sh | 10 ++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/featlib/npm.sh b/featlib/npm.sh index 1c2cbd2..919687c 100755 --- a/featlib/npm.sh +++ b/featlib/npm.sh @@ -70,8 +70,23 @@ function npm_feat_add() { npm install "$1" } -function npm_feat_needed() { +function npm_feat_ensure() { + # Ricarica .bashrc.before per eventuali modifiche al PATH + if [ -f "$HOME/.bashrc.before" ]; then + source "$HOME/.bashrc.before" + fi + + # Se npm funziona, ok + if npm --version >/dev/null 2>&1; then + return + fi + + # Altrimenti installiamo tutto feat_needed "npm" +} + +function npm_feat_needed() { + npm_feat_ensure FEAT="$1" npm_feat_ensure_ncu if ! npm_initialized; then @@ -88,7 +103,7 @@ function npm_feat_needed() { } function npm-g_feat_needed() { - feat_needed "npm" + npm_feat_ensure FEAT="$1" if ! npm-g_feat_added "$FEAT"; then if type "npm-g_feat_add_$FEAT" > /dev/null 2>&1 ; then diff --git a/featlib/pip.sh b/featlib/pip.sh index 110d8ae..a7e6e16 100755 --- a/featlib/pip.sh +++ b/featlib/pip.sh @@ -46,9 +46,40 @@ function feat_add_pip() { pip install --upgrade pip } +function pip_feat_ensure() { + # Ricarica .bashrc.before per eventuali modifiche al PATH + if [ -f "$HOME/.bashrc.before" ]; then + source "$HOME/.bashrc.before" + fi + + # Se abbiamo pyenv, assicuriamoci che il global sia valido + if ! feat_missing "pyenv"; then + local current latest installed + current="$(pyenv global 2>/dev/null)" + installed="$(pyenv versions --bare 2>/dev/null | grep -v '^system$')" + + # Cambia global se: vuoto, system, o versione non più installata + if [ -z "$current" ] || [ "$current" = "system" ] || ! echo "$installed" | grep -qxF "$current"; then + latest="$(echo "$installed" | tail -1)" + if [ -n "$latest" ]; then + pyenv global "$latest" + pyenv rehash >/dev/null 2>&1 || true + fi + fi + fi + + # Se pip funziona, ok + if pip --version >/dev/null 2>&1; then + return + fi + + # Altrimenti installiamo tutto + feat_needed "pip" +} + function pip_feat_missing() { - if feat_missing "pip"; then + if ! pip --version >/dev/null 2>&1; then true else ! ( pip freeze | grep -q "$1=" ) @@ -60,7 +91,7 @@ function pip_feat_add() { } function pip_feat_needed() { - feat_needed "pip" + pip_feat_ensure FEAT="$1" if pip_feat_missing "$FEAT"; then if type "pip_feat_add_$FEAT" > /dev/null 2>&1 ; then diff --git a/featlib/poetry.sh b/featlib/poetry.sh index 921fec0..8aea138 100644 --- a/featlib/poetry.sh +++ b/featlib/poetry.sh @@ -24,6 +24,11 @@ function poetry_feat_added() { } function poetry_feat_missing() { + # Ricarica .bashrc.before per eventuali modifiche al PATH + if [ -f "$HOME/.bashrc.before" ]; then + source "$HOME/.bashrc.before" + fi + if feat_missing "pip"; then true else @@ -39,6 +44,11 @@ function poetry_feat_missing() { } function poetry_feat_needed() { + # Ricarica .bashrc.before per eventuali modifiche al PATH + if [ -f "$HOME/.bashrc.before" ]; then + source "$HOME/.bashrc.before" + fi + feat_needed "poetry" FEAT="$1" if ! poetry_initialized; then