Skip to content

Commit

Permalink
UNSTABLE: use ttscoff's where()
Browse files Browse the repository at this point in the history
    Add "where" from "https://github.com/gaelicWizard/where.git@main"

git-vendor-name: where
git-vendor-dir: vendor/github.com/gaelicWizard/where
git-vendor-repository: https://github.com/gaelicWizard/where.git
git-vendor-ref: main
  • Loading branch information
gaelicWizard committed Mar 5, 2022
1 parent 8989290 commit b05b572
Show file tree
Hide file tree
Showing 5 changed files with 697 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bash_it.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ for _bash_it_main_file_type in "" "aliases" "plugins" "completion"; do
_bash_it_log_section=reloader
_log_debug "Loading '${_bash_it_main_file_type}'..."
source "${BASH_IT}/scripts/reloader.bash" "${_bash_it_main_file_type:+skip}" "$_bash_it_main_file_type"
#_where_from "${BASH_IT}/scripts/reloader.bash"
done

# Load theme, if a theme was set
Expand All @@ -47,10 +48,12 @@ if [[ -n "${BASH_IT_THEME:-}" ]]; then
# shellcheck disable=SC1090
if [[ -f "${BASH_IT_THEME}" ]]; then
source "${BASH_IT_THEME}"
#_where_from "${BASH_IT_THEME}"
elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then
source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash"
elif [[ -f "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then
source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash"
#_where_from "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash"
fi
_bash_it_log_prefix_pop "theme"
fi
Expand All @@ -64,6 +67,7 @@ for _bash_it_main_file_type in "aliases" "completion" "plugins"; do
_log_debug "Loading component..."
# shellcheck disable=SC1090
source "${_bash_it_main_file_custom}"
#_where_from "${BASH_IT}/${file_type}/custom.${file_type}.bash"
fi
done

Expand All @@ -75,6 +79,7 @@ for _bash_it_main_file_custom in "${BASH_IT_CUSTOM}"/*.bash "${BASH_IT_CUSTOM}"/
_log_debug "Loading custom file..."
# shellcheck disable=SC1090
source "$_bash_it_main_file_custom"
#_where_from "$_bash_it_config_file"
fi
done
_bash_it_log_prefix_pop "custom"
Expand All @@ -94,6 +99,8 @@ else
fi

for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do
_log_debug "Finalize hook: $_bash_it_library_finalize_f"
eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`.
_log_debug "Finalized: $_bash_it_library_finalize_f"
done
unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}"
46 changes: 46 additions & 0 deletions lib/where.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# shellcheck shell=bash
#
# Load _where.bash from the vendors folder

: "${WHERE_HOOK_SOURCE:=false}"
: "${WHERE_EXPIRATION:=3600}"

# shellcheck source=../github.com/gaelicWizard/where/_where.bash
source "${BASH_IT}/vendor/github.com/gaelicWizard/where/_where.bash"

function _where_from_here()
{
local type="${BASH_COMMAND[1]:-${1:-}}"
type="${type%% *}"
# ${BASH_SOURCE[1]} is the file that called us,
# ${BASH_LINENO[0]} is the line number of that file.
_where_from_to_index+=( "${type:-thing} ${BASH_LINENO[0]:-NaN} ${BASH_SOURCE[1]:-/dev/stdin}" )
}
alias alias='_where_from_here alias && builtin alias'

function _where_from_here_process()
{
local -i i _where_from_caller_lineno
local _where_from_caller_type _where_from_caller_line_and_source _where_from_caller_source
for i in "${!_where_from_to_index[@]}"
do
_where_from_caller_type="${_where_from_to_index[i]%% *}"
_where_from_caller_line_and_source="${_where_from_to_index[i]#* }"
_where_from_caller_source="${_where_from_caller_line_and_source#* }"
_where_from_caller_lineno="${_where_from_caller_line_and_source%% *}"
[[ "${_where_from_caller_source:-/dev/stdin}" == "/dev/stdin" ]] && continue
_bash-it-array-contains-element "${_where_from_caller_source}" "${_where_from_aliases_to_index[@]}" \
|| _where_from_aliases_to_index+=( "${_where_from_caller_source}" )
unset '_where_from_to_index[i]'
done

for i in "${!_where_from_aliases_to_index[@]}"
do
_where_from "${_where_from_aliases_to_index[i]}"
unset '_where_from_aliases_to_index[i]'
done
}

_where_from_aliases_to_index+=( "${BASH_SOURCE[@]}" )

_bash_it_library_finalize_hook+=( '_where_from_here_process' )
113 changes: 113 additions & 0 deletions vendor/github.com/gaelicWizard/where/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b05b572

Please sign in to comment.