summaryrefslogtreecommitdiff
path: root/bos-namespaces.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bos-namespaces.sh')
-rw-r--r--bos-namespaces.sh29
1 files changed, 25 insertions, 4 deletions
diff --git a/bos-namespaces.sh b/bos-namespaces.sh
index 0cb794a..02f3df2 100644
--- a/bos-namespaces.sh
+++ b/bos-namespaces.sh
@@ -38,9 +38,25 @@ function bos-namespaces/store-dict-for-into() {
result="$name"
}
+declare -a bos_namespace_stack
+
+function bos-namespaces/current-namespace-into() {
+ local -n bos_namespace_current_namespace_result="$1"
+ local IFS=/
+ bos_namespace_current_namespace_result="${bos_namespace_stack[*]}"
+}
+
+function bos-namespaces/push() {
+ bos_namespace_stack+=( "$1" )
+}
+
+function bos-namespaces/pop() {
+ unset "bos_namespace_stack[-1]"
+}
+
# save all currently-visible functions in an associative array
-function bos-namespaces/start() {
- local namespace="$1";shift
+function bos-namespaces/save-funcs() {
+ local namespace; bos-namespaces/current-namespace-into namespace
local ns_store; bos-namespaces/store-dict-for-into ns_store saved_funcs "$namespace"
local -n saved_funcs="$ns_store"
local _ funcname
@@ -56,12 +72,17 @@ function bos-namespaces/start() {
# ones that differ
function bos-namespaces/list-new-funcs-into() {
local -n result="$1"
- local namespace="$2"
+ local namespace; bos-namespaces/current-namespace-into namespace
local ns_store; bos-namespaces/store-dict-for-into ns_store saved_funcs "$namespace"
local -n saved_funcs="$ns_store"
local _ funcname new_function
while read -r _ _ funcname; do
+ # if a function already belong to this namespace, it's not new
+ if [[ "$funcname" == "$namespace"/* ]]; then
+ continue
+ fi
+
new_function="$(declare -pf "$funcname")"
if [[ "$new_function" != "${saved_funcs["$funcname"]}" ]]; then
result+=( "${funcname}" )
@@ -74,7 +95,7 @@ function bos-namespaces/list-new-funcs-into() {
# rename a bunch of functions by prepending a prefix; restore the
# saved function of the same name, if it exists
function bos-namespaces/qualify-funcs() {
- local namespace="$1";shift
+ local namespace; bos-namespaces/current-namespace-into namespace
local ns_store; bos-namespaces/store-dict-for-into ns_store saved_funcs "$namespace"
local -n saved_funcs="$ns_store"
local _ funcname new_function