10 changed files with 793 additions and 0 deletions
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/awk -f |
||||
NR==1 {} |
||||
NR==2 { |
||||
head="" |
||||
color="" |
||||
format="" |
||||
for(i=1; i<=NF; i++) |
||||
{ |
||||
name=$i |
||||
col=$i |
||||
fmt=$i |
||||
gsub( /\|.*$/,"", name ) |
||||
head=head name"="i";" |
||||
|
||||
# gsub( /^name/, "", col ) |
||||
# gsub( /%.*$/, "", col ) |
||||
# color=color"c_"name"=\""col"\";" |
||||
|
||||
gsub( /^[^|]*\|/, "", fmt ) |
||||
format=format"f"name"=\""fmt"\";" |
||||
} |
||||
print "NR==1{} NR==2{"head" "format"}" |
||||
} |
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/awk -f |
||||
NR==1 {} |
||||
NR==2 { |
||||
names="" |
||||
colors="" |
||||
formats="" |
||||
for(i=1; i<=NF; i++) |
||||
{ |
||||
name=$i |
||||
col=$i |
||||
fmt=$i |
||||
gsub(/%[\-0-9.*a-z]*\s/,"",name) |
||||
head=head$i"="i";" |
||||
gsub(/^[^%]*%/,"%",col) |
||||
format=format"f"$i"=\""col"\";" |
||||
} |
||||
print "NR==1{} NR==2{"head" "format"}" |
||||
} |
@ -0,0 +1,138 @@
|
||||
#!/bin/bash |
||||
|
||||
## nesto v0.1.0 |
||||
## Copyright (C) p2p.legal, Thomas Di gregorio |
||||
## Licensed under MIT |
||||
## |
||||
## This is the tool to facilitate working on several small text databases. |
||||
## Usage: |
||||
## nesto [options] <file.db> COMMAND <data> |
||||
## <data> | nesto [options] <file.db> |
||||
## <file.db> COMMAND <data> |
||||
## <data> | <file.db> COMMAND |
||||
## |
||||
## Options: |
||||
## ( Long version are mandatory, and can be before or after short version ) |
||||
## |
||||
## -h, --help Show this help. |
||||
## -v, --verbose Show sub-task resolution and options parsed. |
||||
## -s, --silent Hide text output. |
||||
## -y, --yes Answer yes to questions (Dangerous). |
||||
## --all=<val> Display all VMs |
||||
## |
||||
## |
||||
|
||||
source $(dirname $0)/types.sh |
||||
_model="$(dirname $0)/model.awk" |
||||
|
||||
# Parse options and replace defaults |
||||
source easyoptions || exit |
||||
|
||||
verbose(){ [[ "$verbose" == "yes" ]] && echo $@; } |
||||
_debug(){ [[ "$verbose" == "yes" ]] && for arg in $@;do declare -p $arg 2>/dev/null; done; } |
||||
|
||||
_debug verbose silent yes all arguments |
||||
|
||||
|
||||
DB=${arguments[0]} |
||||
|
||||
|
||||
#if [ -t 1 ] ; then echo terminal; else echo "not a terminal"; fi |
||||
#returns "terminal", because the output is sent to your terminal, whereas |
||||
#(if [ -t 1 ] ; then echo terminal; else echo "not a terminal"; fi) | cat |
||||
|
||||
[[ -t 1 ]] && is_piped="" || is_piped="yes" |
||||
#[[ -n $piped ]] && echo "will be piped" |
||||
#[[ -z $piped ]] && echo "will be printed directly" |
||||
|
||||
|
||||
|
||||
|
||||
add() |
||||
{ |
||||
verbose "add row $@" |
||||
} |
||||
|
||||
upd() |
||||
{ |
||||
verbose "update $@" |
||||
} |
||||
|
||||
del() |
||||
{ |
||||
verbose "delete $@" |
||||
} |
||||
|
||||
_qry() |
||||
{ |
||||
case $1 in |
||||
*\&\&*|*\$*|*\|\|*) echo "$1" ;; |
||||
*=*) echo "\$$(echo $1 | sed 's/=/=="/')\"" ;; |
||||
*~*) echo "\$$(echo "$1" | sed 's|~|~/|')/" ;; |
||||
*[!0-9]*) echo "tolower(\$0) ~ /$1/" ;; |
||||
*[0-9]*) echo "\$1==$1" ;; |
||||
*) echo "$1" ;; |
||||
esac |
||||
} |
||||
|
||||
qry() |
||||
{ |
||||
verbose "search for $@" |
||||
|
||||
# Find if 1st arg is a number |
||||
# case $1 in |
||||
# *\&\&*|*\$*|*\|\|*) q="$1" ;; |
||||
# *=*) q="\$$(echo $1 | sed 's/=/=="/')\"" ;; |
||||
# *~*) q="\$$(echo "$1" | sed 's|~|~/|')/" ;; |
||||
# *[!0-9]*) q="tolower(\$0) ~ /$1/" ;; |
||||
# *[0-9]*) q="\$1==$1" ;; |
||||
# *) q="$1" ;; |
||||
# esac |
||||
q=$(_qry "$1") |
||||
_debug q |
||||
verbose "query: $q" |
||||
|
||||
verbose "model: $($_model $DB)" |
||||
|
||||
[[ -n $verbose ]] && declare -p arguments |
||||
verbose "(${@:2})" |
||||
|
||||
columns="$(for col in ${@:2}; do printf "\$$col," | sed 's/|.*,//'; done | sed 's/,$//')" |
||||
# columns=$(echo ${@:2} | awk 'BEGIN{RS=" ";ORS=",o"}{ print "$"$0 }') |
||||
verbose "[$columns]" |
||||
|
||||
format="$(for col in ${@:2}; do name=$(echo $col | sed 's/|.*//'); printf "cdefault f$name c\" \""; done)" |
||||
verbose "{$format}" |
||||
|
||||
verbose $($_model $DB)" NR > 2 && $q {printf $format\"\\n\", $columns}" cdefault=$c_light c=$c_ $DB |
||||
awk "$($_model $DB) NR > 2 && $q {printf $format\"\\n\", $columns}" cdefault=$c_light$c_black c=$c_ $DB |
||||
|
||||
#'{printf "%-10s %-30s %-10s\n", cp $1, cs $2, c ct $4 c }' cs=$c_status ct=$c_type cp=$c_purple cg=$c_green gr=$c_white cd=$c_dark c=$c_ |
||||
|
||||
|
||||
} |
||||
|
||||
_render() |
||||
{ |
||||
eval `Object cols= $1` |
||||
echo '_render' |
||||
exp cols |
||||
columns="$(for col in ${@:2}; do printf "\$$col," | sed 's/|.*,//'; done | sed 's/,$//')" |
||||
# columns=$(echo ${@:2} | awk 'BEGIN{RS=" ";ORS=",o"}{ print "$"$0 }') |
||||
verbose "[$columns]" |
||||
|
||||
|
||||
format="$(for col in ${@:2}; do name=$(echo $col | sed 's/|.*//'); printf "cdefault f$name c\" \""; done)" |
||||
verbose "{$format}" |
||||
|
||||
echo "{printf $format\"\\n\", $columns}" |
||||
} |
||||
|
||||
exp arguments |
||||
eval `Array rest= \( ${arguments[@]:2} \)` |
||||
exp rest |
||||
|
||||
|
||||
[[ $is_piped == "" ]] && qry ${arguments[1]} | _render "`exp rest`" |
||||
[[ $is_piped == "yes" ]] && qry ${arguments[1]} |
||||
#qry ${arguments[@]:1} |
@ -0,0 +1,4 @@
|
||||
#!/home/dig/dev/nesto/opener |
||||
id name status |
||||
1 root open |
||||
2 dig pété |
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env nestor |
||||
[num]= [name]= [status]= [type]= [domains]= |
||||
111 dig-docker running KVM (devingfx.com ipfs.io exemple.com *.devingfx.com git.p2p.legal) |
||||
147 odoo template LXC (odoo12-test.p2P.legal) |
||||
106 docker running KVM (accounts.p2P.legal) |
||||
888 aze stopped - () |
@ -0,0 +1,5 @@
|
||||
#!/home/dig/dev/nesto/opener |
||||
id|%3s name|\033[32m%-30s type|\033[33m%3s status|%-10s branch|%-10s domains|\033[36m%-100s |
||||
111 svp-docker-dig LXC running staff www.devingfx.com:ipfs.devingfx.com |
||||
106 p2p-docker KVM running docker dalp.p2p.legal:mail.samourai.coop |
||||
123 svp-odoo-fred-copylaradio LXC stopped |
@ -0,0 +1,159 @@
|
||||
#!/bin/bash |
||||
|
||||
verbose=yes |
||||
source ./types.sh |
||||
|
||||
echo '--Assoc--' |
||||
|
||||
sAss="([ert]= [dd]=\"toto\" [blo]=true)" |
||||
Map obj=( |
||||
[ert]= |
||||
[dd]="toto" |
||||
[blo]=true |
||||
) |
||||
Map ass=$sAss |
||||
debug obj ass |
||||
|
||||
echo '--Array--' |
||||
|
||||
sArr="(a b c d e f)" |
||||
Array arr1=(a b c d e f) |
||||
Array arr2=$sArr |
||||
|
||||
arrA=(a b c d e f) |
||||
arrB=( |
||||
a |
||||
b c |
||||
d |
||||
e |
||||
f |
||||
) |
||||
|
||||
debug arr1 arr2 arrA arrB |
||||
|
||||
sss=sss |
||||
debug sss |
||||
|
||||
echo '--String--' |
||||
|
||||
sss=sss |
||||
debug sss |
||||
|
||||
ss1=ss1 |
||||
ss2="ss2" |
||||
sStr="\"str\"" |
||||
String ss3="ss3" |
||||
String ss3b=ss3b |
||||
String ss4b=$sStr |
||||
String ss4="$sStr" |
||||
|
||||
debug ss1 ss2 ss3 ss3b ss4 ss4b |
||||
|
||||
echo '--Objects--' |
||||
|
||||
Map toto=( [id]= [velo]= [9]=9 ) |
||||
|
||||
Map vm=( [id]=111 [name]=dig-docker [status]=running ) |
||||
|
||||
aze=(toto titi tata) |
||||
declare -p aze |
||||
debug aze |
||||
echo 'laaa' |
||||
|
||||
Object hyb ${aze[@]} |
||||
|
||||
|
||||
Array list=(aze qsd wxc) |
||||
|
||||
debug list toto vm |
||||
|
||||
echo '--Function arguments--' |
||||
|
||||
my-func() |
||||
{ |
||||
echo "brut($#): $@" |
||||
echo "brut: $1" |
||||
echo "brut: $2" |
||||
|
||||
Object arg1=$1 |
||||
declare -p arg1 |
||||
arg1+=([rrr]=R [ttt]=T [yyy]=Y) |
||||
declare -p arg1 |
||||
arg1+=([name]=NAME) |
||||
declare -p arg1 |
||||
for a in "${!arg1[@]}"; do echo "elem: ${arg1[$a]}"; done |
||||
|
||||
Array arg2=$2 |
||||
declare -p arg2 |
||||
arg2+=(rrr ttt yyy) |
||||
declare -p arg2 |
||||
for a in "${!arg2[@]}"; do echo "elem: ${arg2[$a]}"; done |
||||
} |
||||
|
||||
my-func "`exp vm`" "`exp aze`" |
||||
|
||||
|
||||
|
||||
|
||||
#if [ -t 1 ] ; then echo terminal; else echo "not a terminal"; fi |
||||
#returns "terminal", because the output is sent to your terminal, whereas |
||||
#(if [ -t 1 ] ; then echo terminal; else echo "not a terminal"; fi) | cat |
||||
|
||||
[[ -t 1 ]] && is_piped="" || is_piped="yes" |
||||
#[[ -n $piped ]] && echo "will be piped" |
||||
#[[ -z $piped ]] && echo "will be printed directly" |
||||
|
||||
|
||||
array2map "(num* name status type)" "(111 dig-docker running KVM)" |
||||
model=(key* value) |
||||
array2map "`exp model`" "(active true)" |
||||
|
||||
#alias VM='declare -A ' |
||||
#VM vm_temp= "(111 dig-docker running KVM)" |
||||
|
||||
sVM="111 dig-docker running KVM" |
||||
_VM 111 dig-docker running KVM |
||||
_VM $sVM |
||||
Map vm1=`_VM $sVM` |
||||
debug vm1 |
||||
|
||||
|
||||
Object test=([key]=aze [value]=fooo) |
||||
#declare -A test=([key]=aze [value]=fooo) |
||||
debug test |
||||
echo looollo |
||||
|
||||
sTest=`declare -p test` |
||||
list=(aze qsd "${sTest#*=}" wxc) |
||||
exp list |
||||
exp list[0] |
||||
exp list[2] |
||||
exp list[2].value |
||||
|
||||
echo ho ho ho |
||||
|
||||
toString() |
||||
{ |
||||
printf "1) %s\n2) %s\n" $1 $2 |
||||
local aze=(); local foo=(coucou monde) |
||||
echo "${foo[@]} !" |
||||
} |
||||
Map obj=( |
||||
[num]=1 |
||||
[name]=bob |
||||
[status]=chill |
||||
[type]=KVN |
||||
[toString]='obj_toString() |
||||
{ |
||||
Object this=$1 |
||||
'"`declare -f toString | awk 'NR>1{print}'`; |
||||
obj_toString " |
||||
) |
||||
debug obj |
||||
|
||||
#obj[arrmap]='{ Object this=$1; '"${obj[arrmap]#{};"'obj_arrmap ' |
||||
echo "${obj[toString]}" |
||||
${obj[toString]} |
||||
echo "${obj[toString]} '([name]=toto)'" |
||||
eval "${obj[toString]} '([name]=toto)'" |
||||
|
@ -0,0 +1,134 @@
|
||||
shopt -s expand_aliases |
||||
|
||||
alias Object='declare -A' |
||||
alias Map='declare -A' |
||||
alias Array='declare -a' |
||||
alias Int='declare -i' |
||||
alias String='declare' |
||||
|
||||
debug() |
||||
{ |
||||
for var in "$@" |
||||
do echo -e $c_purple$var$c_="`exp $var`" |
||||
done |
||||
} |
||||
|
||||
#exp(){ src="$(declare -p $1)"; echo "${src#*=}"; } |
||||
exp() |
||||
{ |
||||
# echo "" |
||||
# echo "" |
||||
echo "Expose $@" |
||||
local path=($(echo "$@" | awk -F '[[\].]' '{for(i=1;i<=NF;i++){printf "%s ", $i}; printf "\n"}')) |
||||
# declare -p path |
||||
# local cur="$(declare -p ${path[0]})" |
||||
|
||||
local src="$(declare -p $path)" |
||||
src="${src#*=}" |
||||
Object obj=$src |
||||
# local cur=($path) |
||||
path=(${path[@]:1}) |
||||
# declare -p obj |
||||
|
||||
while [[ -n $path ]] |
||||
do |
||||
# echo "while) " $path "${obj[$path]}" |
||||
|
||||
# cur+=$path |
||||
src=${obj[$path]} |
||||
Object obj=$src |
||||
# declare -p obj |
||||
# src="$(declare -p obj)" |
||||
# src="${src#*=}" |
||||
# declare -p src |
||||
# obj=$src |
||||
path=(${path[@]:1}) |
||||
done |
||||
|
||||
# src="$(declare -p cur)" |
||||
echo "$src" |
||||
} |
||||
|
||||
function exp() |
||||
{ |
||||
declare -p $1 | sed 's/^declare -. [^=]*=//' # | sed 's/)$//' |
||||
} |
||||
|
||||
|
||||
|
||||
function Object() |
||||
{ |
||||
# echo o |
||||
case "${@:2}" in |
||||
\"*) String $1 ${@:2} ;; |
||||
\(\[[0-9]*) Array $1 ${@:2} ;; |
||||
\(\[*) Assoc $1 ${@:2} ;; |
||||
*) echo "declare $1${@:2}" |
||||
esac |
||||
} |
||||
|
||||
function tg() |
||||
{ |
||||
src="${@:2}" |
||||
is_str=`echo "${@:2}" | grep -v '^".*"$'` |
||||
is_arr=`echo "${@:2}" | grep -v '^\(\['` |
||||
is_arr=$is_arr`echo "${@:2}" | grep '^\[[0-9]*\]='` |
||||
[[ -z $is_arr ]] && echo "declare -A $1=(${@:2})" || echo "declare -a $1=(${@:2})" |
||||
} |
||||
|
||||
#Assoc() |
||||
#{ |
||||
# echo "declare -A $1${@:2}" |
||||
#} |
||||
|
||||
|
||||
#function Array() |
||||
#{ |
||||
# echo "declare -a $1${@:2}" |
||||
#} |
||||
|
||||
|
||||
#function String() |
||||
#{ |
||||
# echo "declare $1${@:2}" |
||||
#} |
||||
|
||||
map2keys() |
||||
{ |
||||
Map obj=$1 |
||||
for key in ${obj[@]} |
||||
do echo $key |
||||
done |
||||
} |
||||
|
||||
array2map() |
||||
{ |
||||
Array fields=$1 |
||||
Array values=$2 |
||||
Map result=() |
||||
for i in ${!fields[@]} |
||||
do |
||||
result[${fields[$i]}]=${values[$i]} |
||||
done |
||||
exp result |
||||
} |
||||
|
||||
map2json() |
||||
{ |
||||
# eval $1 |
||||
Map data=$1 |
||||
printf "{" |
||||
for key in ${!data[@]} |
||||
do |
||||
printf '"%s":' $key |
||||
case "${data[$key]}" in |
||||
true|false|yes|no)printf '%s' "${data[$key]}" ;; |
||||
[0-9.,]) printf '%s' "${data[$key]}" ;; |
||||
*) printf '"%s"' "${data[$key]}" ;; |
||||
esac |
||||
printf "," |
||||
# printf '"%s",' "${data[$key]}" |
||||
done | sed 's/,$//' |
||||
printf "}" |
||||
} |
||||
|
Loading…
Reference in new issue