Bash-it / bash-it

A community Bash framework.
MIT License
14.14k stars 2.29k forks source link

[Feature]: allow customization of `CONFIG_FILE` during install.sh #2241

Open mvk opened 4 months ago

mvk commented 4 months ago

Expected behavior

as a "deployer" I'd like to be able to override CONFIG_FILE so that instead of directly updating ~/.bashrc, another file would be created, and then loaded into ~/.bashrc (or whatever).

for example, I'd like to have bash-it config file at ~/.bash.d/scripts/bash-it.bash, and load it from ~/.bashrc.

This "feature" has a side-effect of easily allowing to compare resulting .bashrc file with an expected value, thus allowing testing.

Current behavior

currently install.sh determines CONFIG_FILE value based on OSTYPE at line 188.

Possible solution

Introduce an env variable BASH_IT_CONFIG_FILE, if defined, set CONFIG_FILE to its value.

Context

currently (the lack of thereof requires me to):

dest="${HOME}/.bash.d/scripts"
BASHRC="${HOME}/.bashrc"
BASH_IT_CONFIG_FILE="${dest}/bash-it-config.bash"
ts="$(date +%s)"
mkdir -p "${dest}"
# backup current config
cp -p "${BASHRC}"{,.backup.$ts}
# create a "temporarily" ~/.bashrc file
./install.sh
mv "${BASHRC}" "${BASH_IT_CONFIG_FILE}"
cp -p "${BASHRC}"{.backup.$ts,}
{
  echo "## source bash-it config file";
  echo "source \"${BASH_IT_CONFIG_FILE}\"";
} >> "${BASHRC}"

hopefully I'd be able to:

dest="${HOME}/.bash.d/scripts"
BASHRC="${HOME}/.bashrc"
BASH_IT_CONFIG_FILE="${dest}/bash-it-config.bash"
ts="$(date +%s)"
mkdir -p "${dest}"
cp -p "${BASHRC}"{,.backup.$ts}
# create bash-it config file
BASH_IT_CONFIG_FILE="${BASH_IT_CONFIG_FILE}" ./install.sh
{
  echo "## source bash-it config file";
  echo "source \"${BASH_IT_CONFIG_FILE}\"";
} >> "${BASHRC}"

Notes

I can implement the above.