feat(\db-tool\): introduce unified db-tool package with postgres harness and tests (T0-T8)
This commit is contained in:
41
legacy/helper/posix-shell/change_namespace.sh
Normal file
41
legacy/helper/posix-shell/change_namespace.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
: "${OLD_NAMESPACE:=}"
|
||||
|
||||
nl=$(printf '\nx')
|
||||
nl=${nl%x}
|
||||
|
||||
___pop_namespace() {
|
||||
v=${OLD_NAMESPACE%%"$nl"*}
|
||||
|
||||
case $OLD_NAMESPACE in
|
||||
*"$nl"*)
|
||||
OLD_NAMESPACE=${OLD_NAMESPACE#*"$nl"}
|
||||
;;
|
||||
*)
|
||||
OLD_NAMESPACE=
|
||||
;;
|
||||
esac
|
||||
|
||||
printf '%s\n' "$v"
|
||||
}
|
||||
|
||||
___peek_namespace() {
|
||||
printf '%s\n' "${OLD_NAMESPACE%%"$nl"*}"
|
||||
}
|
||||
|
||||
___push_namespace() {
|
||||
if [ -n "$OLD_NAMESPACE" ]; then
|
||||
OLD_NAMESPACE=$1"$nl$OLD_NAMESPACE"
|
||||
else
|
||||
OLD_NAMESPACE=$1
|
||||
fi
|
||||
}
|
||||
|
||||
change_namespace() {
|
||||
___push_namespace "$HECTIC_NAMESPACE"
|
||||
export HECTIC_NAMESPACE="$1"
|
||||
}
|
||||
|
||||
restore_namespace() {
|
||||
HECTIC_NAMESPACE=$(___pop_namespace)
|
||||
export HECTIC_NAMESPACE
|
||||
}
|
||||
@@ -12,4 +12,13 @@ in {
|
||||
colors = hectic.writeDash "colors.sh" ''
|
||||
${builtins.readFile ./colors.sh}
|
||||
'';
|
||||
change_namespace = hectic.writeDash "change_namespace.sh" ''
|
||||
${builtins.readFile ./change_namespace.sh}
|
||||
'';
|
||||
quote = hectic.writeDash "quote.sh" ''
|
||||
${builtins.readFile ./quote.sh}
|
||||
'';
|
||||
pager_or_cat = hectic.writeDash "pager_or_cat.sh" ''
|
||||
${builtins.readFile ./pager_or_cat.sh}
|
||||
'';
|
||||
}
|
||||
|
||||
8
legacy/helper/posix-shell/pager_or_cat.sh
Normal file
8
legacy/helper/posix-shell/pager_or_cat.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
pager_or_cat_init() {
|
||||
# Pipe to pager only if stdout is a terminal, otherwise output directly
|
||||
if [ -t 1 ]; then
|
||||
PAGER_OR_CAT="${PAGER:-less}"
|
||||
else
|
||||
PAGER_OR_CAT=cat
|
||||
fi
|
||||
}
|
||||
1
legacy/helper/posix-shell/quote.sh
Normal file
1
legacy/helper/posix-shell/quote.sh
Normal file
@@ -0,0 +1 @@
|
||||
quote() { printf "'%s'" "$(printf %s "$1" | sed "s/'/'\\\\''/g")"; }
|
||||
Reference in New Issue
Block a user