Revision 9050
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sh/local.sh | ||
---|---|---|
35 | 35 |
psql () # usage: [file=...] [dir=...] self |
36 | 36 |
{ |
37 | 37 |
echo_func |
38 |
if test -n "$file"; then
|
|
38 |
if test "$file"; then |
|
39 | 39 |
set -- --file "$file" "$@" |
40 | 40 |
local dir="${dir:-$(dirname "$file")}" |
41 | 41 |
fi |
lib/sh/util.sh | ||
---|---|---|
6 | 6 |
|
7 | 7 |
function extern () { (exec "$@") || return; } |
8 | 8 |
|
9 |
isset () { test -n "${!1+isset}"; }
|
|
9 |
isset () { test "${!1+isset}"; } |
|
10 | 10 |
|
11 | 11 |
realpath () { readlink -f -- "$1"; } |
12 | 12 |
|
... | ... | |
99 | 99 |
let! () { let "$@" || true; } # always returns true; safe to use for setting |
100 | 100 |
# "If the last ARG evaluates to 0, let returns 1" (`help let`) |
101 | 101 |
|
102 |
bool2int () { try test -z "$1"; echo "$e"; } # empty->0; non-empty->1
|
|
102 |
bool2int () { try test ! "$1"; echo "$e"; } # empty->0; non-empty->1
|
|
103 | 103 |
|
104 | 104 |
|
105 | 105 |
#### arrays |
... | ... | |
159 | 159 |
{ |
160 | 160 |
case "$1" in echo_run) shift; echo_cmd "$@";; esac |
161 | 161 |
(limit_stderr |
162 |
if test -n "$stdout2stderr"; then stdout2stderr; fi
|
|
162 |
if test "$stdout2stderr"; then stdout2stderr; fi |
|
163 | 163 |
"$@" |
164 | 164 |
) || return |
165 | 165 |
} |
... | ... | |
245 | 245 |
|
246 | 246 |
set_var () { eval "$1"'="$2"'; } |
247 | 247 |
|
248 |
set_inv () { set_var no_"$1" "$(test -n "${!1}" || echo 1)"; }
|
|
248 |
set_inv () { set_var no_"$1" "$(test "${!1}" || echo 1)"; } |
|
249 | 249 |
|
250 | 250 |
# usage: local var=...; local_inv |
251 |
alias local_inv='declare "no_$var=$(test -n "${!var}" || echo 1)"'
|
|
251 |
alias local_inv='declare "no_$var=$(test "${!var}" || echo 1)"' |
|
252 | 252 |
|
253 | 253 |
# usage: local prefix=..._; import_vars |
254 | 254 |
alias import_vars="$(cat <<'EOF' |
lib/sh/db.sh | ||
---|---|---|
31 | 31 |
echo_func |
32 | 32 |
local ssh_server="$(localize_url "$ssh_server")" |
33 | 33 |
local server="$(localize_url "$server")" |
34 |
if test -n "$ssh_server"; then
|
|
34 |
if test "$ssh_server"; then |
|
35 | 35 |
local ssh_dest="${ssh_dest-${ssh_user:+$ssh_user@}$ssh_server}" |
36 | 36 |
fi |
37 |
if test -n "$schema"; then local database="${database-$schema}"; fi
|
|
37 |
if test "$schema"; then local database="${database-$schema}"; fi |
|
38 | 38 |
|
39 | 39 |
local var=ssh_dest; local_inv |
40 | 40 |
extern ${ssh_dest:+ssh "$ssh_dest" }"${FUNCNAME[1]}" \ |
... | ... | |
70 | 70 |
pg_copy_to () |
71 | 71 |
{ |
72 | 72 |
echo_func |
73 |
if test -z "$source"; then
|
|
73 |
if test ! "$source"; then
|
|
74 | 74 |
: "${table:?}"; mk_table_esc |
75 |
if test -z "$limit"; then local source="$table_esc"
|
|
75 |
if test ! "$limit"; then local source="$table_esc"
|
|
76 | 76 |
else local source="(SELECT * FROM $table_esc LIMIT $limit)" |
77 | 77 |
fi |
78 | 78 |
fi |
Also available in: Unified diff
*{.sh,run}: use shorter `test` instead of `test -n` and `test !` instead of `test -z` (http://www.gnu.org/software/bash/manual/bash.html#Bourne-Shell-Builtins > test)