From e48e7ff6fb8b93721da4d2ceb6a9a9f915bc8027 Mon Sep 17 00:00:00 2001 From: Peter Urda Date: Tue, 25 Nov 2025 22:32:02 -0800 Subject: [PATCH] Version 1.1.0 release --- .github/workflows/testing.yaml | 3 ++ CHANGELOG.md | 13 +++++ Makefile | 2 +- README.md | 37 ++++++++++++++ VERSION | 2 +- bash_osx | 13 +---- bashrc | 92 ++++++++++++++++++++++++++++++---- 7 files changed, 137 insertions(+), 25 deletions(-) diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index aea627f..c05817d 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -19,5 +19,8 @@ jobs: - name: Checkout ⬇️ uses: actions/checkout@v5 + - name: Report `shellcheck` Version 🔍 + run: shellcheck --version + - name: urda.bash Testing 🧪 run: make test diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bd8996..ebdba74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # CHANGELOG +## 1.1.0 + +- `bashrc` + - Added support for `direnv`. + - Unified `nvm` tooling setup. Checks for `~/.nvm/nvm.sh` first, then `brew --prefix nvm`, then gives up. + - Created a `_postpend_path_once` function for `PATH` operations. + - Added additional checks to prevent errors when resourcing bash files and `readonly` values. + - Added additional checks and environment variables to prevent tooling reconfiguration when resourcing bash files. + - Added an internal `_urdabash_info` function to show information about `urda.bash`. + - Added the option to add a `now` flag to `_urdabash_version_check` to allow on-demand version checks. +- `bash_osx` + - `nvm` setup moved to `bashrc`. + ## 1.0.0 - In late 2025, `urda.bash` got a fresh coat of paint. diff --git a/Makefile b/Makefile index d343616..2ede562 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,7 @@ test: version-check # Test and check shell scripts for issues. .PHONY: version-check version-check: # Check the reported version and code version. @file_ver=$$(cat VERSION); \ - var_ver=$$(awk -F\" '/^readonly URDABASH_VERSION=/{print $$2}' bashrc); \ + var_ver=$$(awk -F\" '/^ readonly URDABASH_VERSION=/{print $$2}' bashrc); \ if [ "$$file_ver" = "$$var_ver" ]; then \ echo "VERSION matches '$$var_ver'"; \ exit 0; \ diff --git a/README.md b/README.md index 117dbeb..b555997 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,31 @@ This is a collection of my bash prompt settings, aliases, exports, and other related shell scripts. +# `urda.bash` Features + +- Exposes the [`XDG Base Directory`](https://specifications.freedesktop.org/basedir/latest/) specification variables. +- Supports loading `bash` shell parts based on host operating system: + - `bash_linux` - For Linux platforms. + - `bash_osx` - For macOS platforms. +- Displays "information lines" in shell: + - `git` working state information. + - `screen` session name. + - `virtualenv` / `pyenv` environment names. +- Understands various tools and tooling in shell: + - [`direnv`](https://direnv.net/) support. + - [`nvm`](https://github.com/nvm-sh/nvm) support. + - [`pyenv`](https://github.com/pyenv/pyenv) support. +- Weekly `VERSION` check against GitHub remote. + - Also supports on-demand version checking with `_urdabash_version_check now` + +Should work with `bash 3.2` or higher. + +# Working with `urda.bash` project files + +## Get `Makefile` help + +You can run a bare `make` or `make help` to display the help screen. + ## Comparing to your local bash After you clone this repo, you can also run a quick `diff` that will compare your local `bash` files against the repo files: @@ -17,3 +42,15 @@ This will also run a `make version-check`. ```bash make test ``` + +## Copying files to your `${HOME}` + +**WARNING!** This is a **DESTRUCTIVE** operation and copies `bash` files from the project into your `${HOME}`. + +```bash +make copy +``` + +## Project version check + +Just run `make version-check`. diff --git a/VERSION b/VERSION index 3eefcb9..9084fa2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.1.0 diff --git a/bash_osx b/bash_osx index ac6a241..b8e7715 100644 --- a/bash_osx +++ b/bash_osx @@ -32,9 +32,6 @@ if [ -x /opt/homebrew/bin/brew ]; then # Hide Homebrew Env Hints export HOMEBREW_NO_ENV_HINTS=true - brew_prefix="$(brew --prefix 2>/dev/null)" - nvm_prefix="$(brew --prefix nvm 2>/dev/null)" - # Custom Homebrew updater function update_brew() { bold=$(tput bold 2>/dev/null || printf '') @@ -50,14 +47,7 @@ if [ -x /opt/homebrew/bin/brew ]; then # ------------------------------ # Homebrew extras # ------------------------------ - - # ------------------------------ - # NVM (via Homebrew) - # ------------------------------ - if [ -n "${nvm_prefix}" ] && [ -f "${nvm_prefix}/nvm.sh" ]; then - # shellcheck source=/dev/null - source "${nvm_prefix}/nvm.sh" - fi + brew_prefix="$(brew --prefix 2>/dev/null)" # ------------------------------ # Bash completions @@ -68,5 +58,4 @@ if [ -x /opt/homebrew/bin/brew ]; then fi unset brew_prefix - unset nvm_prefix fi diff --git a/bashrc b/bashrc index e974b83..942e2f4 100644 --- a/bashrc +++ b/bashrc @@ -30,10 +30,20 @@ fi # Critical Environment Variables ################################################################################ -readonly URDABASH_VERSION="1.0.0" -readonly URDABASH_OS="$(uname -s)" -export URDABASH_OS -export URDABASH_VERSION +if [[ -z ${URDABASH_VERSION+x} ]]; then + readonly URDABASH_VERSION="1.1.0" + export URDABASH_VERSION +fi + +if [[ -z ${URDABASH_VERSION_URL+x} ]]; then + readonly URDABASH_VERSION_URL="https://raw.githubusercontent.com/urda/urda.bash/refs/heads/master/VERSION" + export URDABASH_VERSION_URL +fi + +if [[ -z ${URDABASH_OS+x} ]]; then + readonly URDABASH_OS="$(uname -s)" + export URDABASH_OS +fi export XDG_CONFIG_HOME="${HOME}/.config" export XDG_CACHE_HOME="${HOME}/.cache" @@ -44,7 +54,7 @@ export XDG_STATE_HOME="${HOME}/.local/state" # Functions ################################################################################ -# Private bins at the front, only once +# Add to the FRONT of the PATH (unless already present). _prepend_path_once() { local dir=${1} [[ -d ${dir} ]] || return @@ -56,22 +66,54 @@ _prepend_path_once() { esac } +# Add to the END of the PATH (unless already present). +_postpend_path_once() { + local dir=${1} + [[ -d ${dir} ]] || return + case ":${PATH}:" in + # Already present + *":${dir}:"*) ;; + # Postpend once + *) PATH="${PATH}:${dir}" ;; + esac +} + _source_if_exists() { # shellcheck source=/dev/null [[ -n "${1}" && -r "${1}" ]] && source "${1}" } -_urda_version_check() { +_urdabash_info() { + local direnv_status="0" + local nvm_status="0" + local pyenv_status="0" + + [[ -n ${URDABASH_LOADED_DIRENV+x} ]] && direnv_status="${URDABASH_LOADED_DIRENV}" + [[ -n ${URDABASH_LOADED_NVM+x} ]] && nvm_status="${URDABASH_LOADED_NVM}" + [[ -n ${URDABASH_LOADED_PYENV+x} ]] && pyenv_status="${URDABASH_LOADED_PYENV}" + + echo "URDABASH_VERSION ......... ${URDABASH_VERSION}" + echo "URDABASH_VERSION_URL ..... ${URDABASH_VERSION_URL}" + echo "URDABASH_OS .............. ${URDABASH_OS}" + echo "URDABASH_LOADED_DIRENV ... ${direnv_status}" + echo "URDABASH_LOADED_NVM ...... ${nvm_status}" + echo "URDABASH_LOADED_PYENV .... ${pyenv_status}" +} + +_urdabash_version_check() { local interval=604800 # 7 days local state_dir="${XDG_STATE_HOME:-${HOME}/.local/state}/urda.bash" local stamp="${state_dir}/last_check" now last=0 - local version_url="https://raw.githubusercontent.com/urda/urda.bash/refs/heads/master/VERSION" + local version_url="${URDABASH_VERSION_URL}" + local force_check_now=${1:-} now=$(date +%s) if [ -f "${stamp}" ]; then last=$(stat -f %m "${stamp}" 2>/dev/null || stat -c %Y "${stamp}" 2>/dev/null || echo 0) fi - (( now - last < interval )) && return + if [[ ${force_check_now} != now ]] && (( now - last < interval )); then + return + fi # Update state timestamp if ! mkdir -p "${state_dir}"; then @@ -95,7 +137,7 @@ _urda_version_check() { remote=${remote//[[:space:]]/} [ -z "${remote}" ] && return [ "${remote}" != "${URDABASH_VERSION}" ] && \ - printf "An urda.bash update is available: '%s' -> '%s'\n" "${URDABASH_VERSION}" "${remote}" >&2 + printf "An urda.bash update is available:\nLocal version: '%s'\nRemote version: '%s'\n" "${URDABASH_VERSION}" "${remote}" >&2 } ################################################################################ @@ -134,10 +176,38 @@ _prepend_path_once "${HOME}/bin" # ------------------------------ _source_if_exists "${XDG_CONFIG_HOME}/op/plugins.sh" +# ------------------------------ +# direnv +# ------------------------------ +if command -v direnv >/dev/null 2>&1 && [[ -z ${URDABASH_LOADED_DIRENV+x} ]]; then + readonly URDABASH_LOADED_DIRENV=1 + eval "$(direnv hook bash)" +fi + +# ------------------------------ +# NVM (via ~/.nvm or Homebrew) +# ------------------------------ +if [[ -z ${URDABASH_LOADED_NVM+x} ]]; then + readonly URDABASH_LOADED_NVM=1 + export NVM_DIR="${HOME}/.nvm" + command -v brew >/dev/null 2>&1 && nvm_brew_prefix="$(brew --prefix nvm 2>/dev/null)" + + if [ -s "${HOME}/.nvm/nvm.sh" ]; then + _source_if_exists "${NVM_DIR}/nvm.sh" + _source_if_exists "${NVM_DIR}/bash_completion" + elif [ -n "${nvm_brew_prefix}" ] && [ -f "${nvm_brew_prefix}/nvm.sh" ]; then + _source_if_exists "${nvm_brew_prefix}/nvm.sh" + _source_if_exists "${nvm_brew_prefix}/etc/bash_completion.d/nvm" + fi + + unset nvm_brew_prefix +fi + # ------------------------------ # pyenv # ------------------------------ -if command -v pyenv >/dev/null 2>&1; then +if command -v pyenv >/dev/null 2>&1 && [[ -z ${URDABASH_LOADED_PYENV+x} ]]; then + readonly URDABASH_LOADED_PYENV=1 export PYENV_ROOT="${HOME}/.pyenv" _prepend_path_once "${PYENV_ROOT}/bin" @@ -156,7 +226,7 @@ fi # Update Check ################################################################################ -_urda_version_check +_urdabash_version_check "noop" ################################################################################ # Prompt Functions