-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.functions
61 lines (52 loc) · 1.19 KB
/
common.functions
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
#!/bin/bash
function tabs2table() {
cat /dev/stdin | column -x -t -s $'\t' -o $'\t'
}
function read_nl () {
readme='add new line to read -n 1 unless Enter pressed (which adds new line)'
[[ -z $REPLY ]] || echo
}
function info_green () {
local GREP_COLOR
export GREP_COLOR="01;32"
cat /dev/stdin | egrep --color '.*'
}
function api_history () {
echo ${FUNCNAME[*]:1:11}
}
function error_red () {
local GREP_COLOR
export GREP_COLOR="01;31"
cat /dev/stdin | egrep --color '.*' 1>&2
}
function prn_col () {
local next
for next in $* ; do
echo $next
done
}
function tawk () {
local tmp=$(mktemp)
cat /dev/stdin > $tmp
local IFS=$'\t\n'
local cols=( $(head -1 $tmp | sed -r 's/\s*\t\s*/\t/g') )
awk_vars="$(
for ((i=0;i<${#cols[@]};i++)) ; do
echo -n ${cols[$i]}=\$$((i+1)) \;
done
)"
#sed -n '2,$p' $tmp |
cat $tmp |
awk -F ' *\t *' "{ $awk_vars { ${*:-print} } }"
rm -f $tmp
} # end function
function source_functions () {
local src_dir=$(readlink -e "${BASH_SOURCE[0]}")
src_dir="$(dirname $src_dir)"
local src_files=$(ls -1 "$src_dir"/*.functions | fgrep -v "${BASH_SOURCE[0]}")
local i
for i in $src_files ; do
source $i
done
}
source_functions