Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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`.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
13 changes: 1 addition & 12 deletions bash_osx
Original file line number Diff line number Diff line change
Expand Up @@ -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 '')
Expand All @@ -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
Expand All @@ -68,5 +58,4 @@ if [ -x /opt/homebrew/bin/brew ]; then
fi

unset brew_prefix
unset nvm_prefix
fi
92 changes: 81 additions & 11 deletions bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}

################################################################################
Expand Down Expand Up @@ -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"
Expand All @@ -156,7 +226,7 @@ fi
# Update Check
################################################################################

_urda_version_check
_urdabash_version_check "noop"

################################################################################
# Prompt Functions
Expand Down