Skip to content
Open
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
14 changes: 14 additions & 0 deletions contrib/direnv-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

source ./shell-hook.sh

[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_ROOT: ${PRJ_ROOT}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_ID: ${PRJ_ID-none}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_CONFIG_HOME: ${PRJ_CONFIG_HOME#"${PRJ_ROOT}"/}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_RUNTIME_DIR: ${PRJ_RUNTIME_DIR#"${PRJ_ROOT}"/}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_CACHE_HOME: ${PRJ_CACHE_HOME#"${PRJ_ROOT}"/}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_DATA_HOME: ${PRJ_DATA_HOME#"${PRJ_ROOT}"/}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_PATH: ${PRJ_PATH#"${PRJ_ROOT}"/}"

# shellcheck disable=SC2034
direnv_layout_dir="${PRJ_DATA_HOME}/direnv"
24 changes: 8 additions & 16 deletions contrib/direnv → contrib/shell-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Discover PRJ_ROOT if not found via git (i.e. not in a git repository).
# Look for the .config folder in the current directory and up
find_prj_config() (
__find_prj_root_with_config_dir() (
local old_pwd
while [[ $old_pwd != "$PWD" ]]; do
if [[ -d .config && "$HOME" != "$PWD" ]]; then
Expand All @@ -18,7 +18,7 @@ find_prj_config() (
)

# Discover PRJ_ROOT if in a git repository.
find_prj_root_with_git() (
__find_prj_root_with_git() (
git rev-parse --show-toplevel 2>/dev/null
)

Expand All @@ -28,8 +28,8 @@ find_prj_root_with_git() (
: "${XDG_DATA_HOME:=${HOME}/.local/share}"

# PRJ_ROOT
_prj_root="$(find_prj_root_with_git)"
: "${PRJ_ROOT:=${_prj_root:=$(find_prj_config)}}"
_prj_root="$(__find_prj_root_with_git)"
: "${PRJ_ROOT:=${_prj_root:=$(__find_prj_root_with_config_dir)}}"

# PRJ_CONFIG_HOME - always local to the project
: "${PRJ_CONFIG_HOME:=${PRJ_ROOT}/.config}"
Expand Down Expand Up @@ -74,23 +74,15 @@ find_prj_root_with_git() (
mkdir -p "${PRJ_PATH}"
}

unset -f find_prj_config
unset -f __find_prj_root_with_config_dir
unset -f __find_prj_root_with_git

export PATH="${PRJ_PATH}:${PATH}"

PATH_add "${PRJ_PATH}"
export PRJ_ROOT
export PRJ_ID
export PRJ_PATH
export PRJ_CONFIG_HOME
export PRJ_CACHE_HOME
export PRJ_DATA_HOME
export PRJ_RUNTIME_DIR
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_ROOT: ${PRJ_ROOT}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_ID: ${PRJ_ID-none}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_CONFIG_HOME: ${PRJ_CONFIG_HOME#"${PRJ_ROOT}"/}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_RUNTIME_DIR: ${PRJ_RUNTIME_DIR#"${PRJ_ROOT}"/}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_CACHE_HOME: ${PRJ_CACHE_HOME#"${PRJ_ROOT}"/}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_DATA_HOME: ${PRJ_DATA_HOME#"${PRJ_ROOT}"/}"
[ -z ${DIRENV_PRJ_SILENCE+x} ] && log_status "PRJ_PATH: ${PRJ_PATH#"${PRJ_ROOT}"/}"

# shellcheck disable=SC2034
direnv_layout_dir="${PRJ_DATA_HOME}/direnv"