Revision 8888
Added by Aaron Marcuse-Kubitza over 11 years ago
util.sh | ||
---|---|---|
29 | 29 |
# usage: try cmd...; ignore status; if catch status; then ...; fi; end_try |
30 | 30 |
|
31 | 31 |
try_ () { { "$@"; e="$?";} || true; } |
32 |
alias try='local e; try_ ' # trailing space alias-expands next word
|
|
32 |
alias try='declare e; try_ ' # trailing space alias-expands next word
|
|
33 | 33 |
|
34 | 34 |
catch () { test "$e" -eq "$1"; e=0; } |
35 | 35 |
|
... | ... | |
119 | 119 |
set_inv () { set_var no_"$1" "$(test -n "${!1}" || echo 1)"; } |
120 | 120 |
|
121 | 121 |
# usage: local var=...; local_inv |
122 |
alias local_inv='local "no_$var=$(test -n "${!var}" || echo 1)"'
|
|
122 |
alias local_inv='declare "no_$var=$(test -n "${!var}" || echo 1)"'
|
|
123 | 123 |
|
124 | 124 |
# usage: local prefix=..._; import_vars |
125 | 125 |
alias import_vars="$(cat <<'EOF' |
... | ... | |
214 | 214 |
#### databases |
215 | 215 |
|
216 | 216 |
# using prefixed connection vars |
217 |
alias use_local="local prefix=local_; import_vars"
|
|
218 |
alias use_remote="local prefix=remote_; import_vars"
|
|
217 |
alias use_local="declare prefix=local_; import_vars"
|
|
218 |
alias use_remote="declare prefix=remote_; import_vars"
|
|
219 | 219 |
alias use_local_remote="use_local; use_remote" |
220 | 220 |
|
221 | 221 |
quote='"' |
... | ... | |
224 | 224 |
|
225 | 225 |
mk_esc_name () { set_var "$1"_esc "$(esc_name "${!1}")"; } |
226 | 226 |
|
227 |
alias mk_schema_esc="local schema_esc; mk_esc_name schema"
|
|
228 |
alias mk_table_esc="local table_esc; mk_esc_name table"
|
|
227 |
alias mk_schema_esc="declare schema_esc; mk_esc_name schema"
|
|
228 |
alias mk_table_esc="declare table_esc; mk_esc_name table"
|
|
229 | 229 |
|
230 | 230 |
fi # load new aliases |
231 | 231 |
if self_being_included; then |
Also available in: Unified diff
lib/util.sh: use declare instead of local in aliases so that the aliases can also be used outside a function (declare will create a local var when used inside a function, and a global var otherwise)