Sets environment variables based on Git repo status for the use in shell scripts such as prompts. Using this method allows for decoupling of interpreting the output of git status
from logic and formatting. The behavior is defined by the tests to improve reliability and predictability.
Source the script then call the set_git_status_vars
function. An optional prefix can be provided as the first argument to avoid potentially collisions with other environment variables.
. git-status-in-env.sh
set_git_status_vars MY_PREFIX
echo "Git branch is $MY_PREFIX_BRANCH"
Testing is implemented using ShellSpec.
Test locally with defaults:
$ shellspec
Testing with other shell versions using Docker:
$ shellspec --docker docker.io/library/bash:4.4 --shell bash
$ shellspec --docker ghcr.io/zsh-users/zsh:4.3.11 --shell zsh