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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ This will source a file `lib/file.sh` under the package `username/repo`.
To change the behavior of basher, you can set the following variables either
globally or before each command:

- If `$XDG_DATA_HOME/basher` is a directory, then `$BASHER_ROOT` will be set to `$XDG_DATA_HOME/basher` instead of the usual `$HOME/.basher`. If `$XDG_DATA_HOME` is not set or is empty, then it defaults to `~/.local/share`.
- `BASHER_FULL_CLONE=true` - Clones the full repo history instead of only the last commit (useful for package development)
- `BASHER_PREFIX` - set the installation and package checkout prefix (default is `$BASHER_ROOT/cellar`). Setting this to `/usr/local`, for example, will install binaries to `/usr/local/bin`, manpages to `/usr/local/man`, completions to `/usr/local/completions`, and clone packages to `/usr/local/packages`. This allows you to manage "global packages", distinct from individual user packages.

Expand Down
3 changes: 3 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ die() {
exit 1
}

xdg_basher_dir="${XDG_DATA_HOME:-$HOME/.local/share}/basher"

## stop if basher is already installed
[[ -d "$HOME/.basher" ]] && die "basher is already installed on [$HOME/.basher]"
[[ -d "$xdg_basher_dir" ]] && die "basher is already installed on [$xdg_basher_dir]"

## stop if git is not installed
git version >/dev/null 2>&1 || die "git is not installed on this machine"
Expand Down
4 changes: 4 additions & 0 deletions libexec/basher
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ abs_dirname() {

if [ -z "$BASHER_ROOT" ]; then
BASHER_ROOT="$HOME/.basher"

if [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/basher" ]; then
BASHER_ROOT="${XDG_DATA_HOME:-$HOME/.local/share}/basher"
fi
fi
export BASHER_ROOT

Expand Down
12 changes: 12 additions & 0 deletions tests/basher.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ load test_helper
assert_output "/tmp/basher"
}

@test "inherited XDG_DATA_HOME" {
mkdir -p "/tmp/local/share/basher"
BASHER_ROOT= XDG_DATA_HOME=/tmp/local/share run basher echo BASHER_ROOT
assert_output "/tmp/local/share/basher"
}

@test "inherited XDG_DATA_PREFIX overriden by inherited BASHER_ROOT" {
mkdir -p "/tmp/local/share/basher"
BASHER_ROOT=/tmp/basher XDG_DATA_HOME=/tmp/local/share run basher echo BASHER_ROOT
assert_output "/tmp/basher"
}

@test "default BASHER_PREFIX" {
BASHER_ROOT= BASHER_PREFIX= run basher echo BASHER_PREFIX
assert_output "$HOME/.basher/cellar"
Expand Down
1 change: 1 addition & 0 deletions tests/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export BASHER_ORIGIN_DIR="${BASHER_TEST_DIR}/origin"
export BASHER_CWD="${BASHER_TEST_DIR}/cwd"
export BASHER_TMP_BIN="${BASHER_TEST_DIR}/bin"

export XDG_DATA_HOME=""
export BASHER_ROOT="${BATS_TEST_DIRNAME}/.."
export BASHER_PREFIX="${BASHER_TEST_DIR}/prefix"
export BASHER_INSTALL_BIN="${BASHER_PREFIX}/bin"
Expand Down
7 changes: 5 additions & 2 deletions uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ die() {
exit 1
}

xdg_basher_dir="${XDG_DATA_HOME:-$HOME/.local/share}/basher"

## stop if basher is not installed
[[ ! -d "$HOME/.basher" ]] && die "basher doesn't seem to be installed on [$HOME/.basher]"
[[ -d "$HOME/.basher" || -d "$xdg_basher_dir" ]] || die "basher doesn't seem to be installed on [$HOME/.basher] or [$xdg_basher_dir]"
echo ". remove basher code and installed packages"
basher list
sleep 2
rm -fr "$HOME/.basher"
[ -d "$HOME/.basher" ] && rm -fr "$HOME/.basher"
[ -d "$xdg_basher_dir" ] && rm -fr "$xdg_basher_dir"

## now check what shell is running
shell_type=$(basename "$SHELL")
Expand Down