-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathzzpgsql.sh
61 lines (58 loc) · 1.84 KB
/
zzpgsql.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# ----------------------------------------------------------------------------
# Lista os comandos SQL no PostgreSQL, numerando-os.
# Pesquisa detalhe dos comando, ao fornecer o número na listagem a esquerda.
# E filtra a busca se fornecer um texto.
#
# Uso: zzpgsql [ código | filtro ]
# Ex.: zzpgsql # Lista os comandos disponíveis
# zzpgsql 20 # Consulta o comando ALTER SCHEMA
# zzpgsql alter # Filtra os comandos que possuam alter na declaração
#
# Autor: Itamar <itamarnet (a) yahoo com br>
# Desde: 2013-05-11
# Versão: 4
# Requisitos: zzzz zztool zzjuntalinhas zzsqueeze zztrim zzxml
# Tags: internet, consulta
# ----------------------------------------------------------------------------
zzpgsql ()
{
zzzz -h pgsql "$1" && return
local url='http://www.postgresql.org/docs/current/static'
local cache=$(zztool cache pgsql)
local comando
if ! test -s "$cache"
then
zztool source "${url}/sql-commands.html" |
awk '/<dt>/,/<\/dt>/' |
zzjuntalinhas -i '<dt>' -f '</dt>' |
zzsqueeze |
zztrim |
awk '{sub(/.*sql-/,"sql-");sub(/">/,":");print ++i ":" $0}' |
zzxml --untag > $cache
fi
if test -n "$1"
then
if zztool testa_numero $1
then
comando=$(sed -n "/^ *${1}:/{s///;s/:.*//;p;}" $cache)
texto=$(sed -n "/^ *${1}:/{s/.*://;s/ . .*//;p;}" $cache)
zztool dump "${url}/${comando}" |
awk '
$0 ~ /^$/ { branco++; if (branco == 3) { print "----------"; branco = 0 } }
$0 !~ /^$/ { for (i=1;i<=branco;i++) { print "" }; print ; branco = 0 }
' |
sed -n '/^ *[_-][_-][_-][_-]*$/,/^ *[_-][_-][_-][_-]*$/p' |
sed "1,/${texto}/{/${texto}/!d};$d;" |
zztrim -V |
sed '
s/ */ /
/^ *[_-][_-][_-][_-]*$/d
/.*Prev \{1,\} Up \{1,\}Next/,$d
'
else
grep -i $1 $cache | awk -F: '{printf "%3s %s\n", $1, $3}'
fi
else
awk -F: '{printf "%3s %s\n", $1, $3}' "$cache"
fi
}