dcdb.bash 4.5 KB
Newer Older
1
DCDB_PREFIX=%DCDB_PREFIX%
Axel Auweter's avatar
Axel Auweter committed
2
3
UN=$(uname)

4
# Set LD_LIBRARY_PATH (DYLD_LIBRARY_PATH on MacOs)
Axel Auweter's avatar
Axel Auweter committed
5
6
7
8
9
10
if [ "${UN}" = "Darwin" ]; then
	export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:${DCDB_PREFIX}/lib/
else
	export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${DCDB_PREFIX}/lib/
fi

11
# Set PATH
12
13
export PATH=$PATH:${DCDB_PREFIX}/bin/

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
# Enable bash completion for dcbdconfig
_dcdbconfig_options()
{
	local curr_arg num_args hostname_str toplevel_command_at comrep
	curr_arg=${COMP_WORDS[COMP_CWORD]}
	num_args=${#COMP_WORDS[@]}
	
	comrep=""
	hostname_str=""
	toplevel_command_at=1
	
	if [ "${COMP_WORDS[1]:0:2}" = "-h" ]; then
		if [ "${COMP_WORDS[1]}" = "-h" ]; then
			toplevel_command_at=3
			hostname_str="-h ${COMP_WORDS[2]}"
		else
			toplevel_command_at=2
			hostname_str="${COMP_WORDS[1]}"
		fi
	else
		if [ "${num_args}" -le "2" ]; then
			comrep+="-h "
		fi
	fi
	
	if [ "${num_args}" -le "$((${toplevel_command_at}+1))" ]; then
40
		comrep+="help sensor db "
41
42
43
	else
		if [ "${COMP_WORDS[${toplevel_command_at}]}" = "help" ]; then
			if [ ! "${COMP_WORDS[$((${COMP_CWORD}-1))]}" = "sensor" ]; then
44
				comrep="sensor db "
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
			fi
		elif [ "${COMP_WORDS[${toplevel_command_at}]}" = "sensor" ]; then
			if [ "${num_args}" -eq "$((${toplevel_command_at}+2))" ]; then
				comrep="publish list listpublic show scalingfactor unit integrable unpublish"
			fi
			if [ "${COMP_WORDS[$((${toplevel_command_at}+1))]}" = "show" ] && [ "${num_args}" -eq "$((${toplevel_command_at}+3))" ]; then
				comrep=$(dcdbconfig ${hostname_str} sensor list 2> /dev/null)
			fi
			if [ "${COMP_WORDS[$((${toplevel_command_at}+1))]}" = "scalingfactor" ] && [ "${num_args}" -eq "$((${toplevel_command_at}+3))" ]; then
				comrep=$(dcdbconfig ${hostname_str} sensor list 2> /dev/null)
			fi
			if [ "${COMP_WORDS[$((${toplevel_command_at}+1))]}" = "unit" ] && [ "${num_args}" -eq "$((${toplevel_command_at}+3))" ]; then
				comrep=$(dcdbconfig ${hostname_str} sensor list 2> /dev/null)
			fi
			if [ "${COMP_WORDS[$((${toplevel_command_at}+1))]}" = "integrable" ] && [ "${num_args}" -eq "$((${toplevel_command_at}+3))" ]; then
				comrep=$(dcdbconfig ${hostname_str} sensor list 2> /dev/null)
			fi
			if [ "${COMP_WORDS[$((${toplevel_command_at}+1))]}" = "integrable" ] && [ "${num_args}" -eq "$((${toplevel_command_at}+4))" ]; then
				comrep="on off"
			fi
			if [ "${COMP_WORDS[$((${toplevel_command_at}+1))]}" = "unpublish" ] && [ "${num_args}" -eq "$((${toplevel_command_at}+3))" ]; then
				comrep=$(dcdbconfig ${hostname_str} sensor list 2> /dev/null)
			fi
68
69
70
71
        elif [ "${COMP_WORDS[${toplevel_command_at}]}" = "db" ]; then
            if [ "${num_args}" -eq "$((${toplevel_command_at}+2))" ]; then
                comrep="insert fuzzytrunc"
            fi
72
73
74
75
76
77
		fi
	fi

	COMPREPLY=( $(compgen -W '${comrep}' -- $curr_arg ) )
}
complete -F _dcdbconfig_options dcdbconfig
78
79
80
81
82
83
84
85
86
87
88
89
90
91

# Enable bash completion on dcdbquery
_dcdbquery_options()
{
	local i curr_arg num_args hostname_str sensorlist_at rawreq localreq comrep
	
	curr_arg=${COMP_WORDS[COMP_CWORD]}
	num_args=${#COMP_WORDS[@]}
	
	comrep=""
	hostname_str=""
	sensorlist_at=1
	rawreq=0
	localreq=0
Axel Auweter's avatar
Axel Auweter committed
92
	floatreq=0
93
94
95
96
97
98
99
	i=0
	
	# Go through all possible options until first non-option (i.e. sensor) is found
	while [ "$i" -le "$num_args" ] && [ "$i" -le "5" ]; do
		if [ "${COMP_WORDS[$i]}" = "-r" ]; then
			rawreq=1
			sensorlist_at=$((sensorlist_at+1))
Axel Auweter's avatar
Axel Auweter committed
100
101
102
103
104
105
        elif [ "${COMP_WORDS[$i]}" = "-l" ]; then
            localreq=1
            sensorlist_at=$((sensorlist_at+1))
        elif [ "${COMP_WORDS[$i]}" = "-f" ]; then
            floatreq=1
            sensorlist_at=$((sensorlist_at+1))
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
		elif [ "${COMP_WORDS[$i]:0:2}" = "-h" ]; then
			if [ "${COMP_WORDS[$i]}" = "-h" ]; then
				i=$((i+1))
				sensorlist_at=$((sensorlist_at+2))
				hostname_str="-h ${COMP_WORDS[$i]}"
			else
				hostname_str="${COMP_WORDS[$i]}"
				sensorlist_at=$((sensorlist_at+1))
			fi
		fi

		i=$((i+1))
	done
	
	if [ "$((${num_args}-1))" -le "${sensorlist_at}" ]; then
		if [ ! "${rawreq}" -eq "1" ]; then
			comrep+=" -r"
		fi
		if [ ! "${localreq}" -eq "1" ]; then
			comrep+=" -l"
		fi
Axel Auweter's avatar
Axel Auweter committed
127
128
129
        if [ ! "${floatreq}" -eq "1" ]; then
            comrep+=" -f"
        fi
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
		if [ "${hostname_str}" = "" ]; then
			comrep+=" -h"
		fi
	fi
	
	comrep+=" "
	comrep+=$(dcdbconfig ${hostname_str} sensor list 2> /dev/null)
	
#	echo
#	echo "Num args: $num_args"
#	echo "Sensorlist at: $sensorlist_at"
#	echo "Hostname_str: $hostname_str"
#	echo "Hostname_missing: $hostname_missing"
	
	if [ "${hostname_str}" = "-h " ]; then
		comrep=""
	fi
	
	COMPREPLY=( $(compgen -W '${comrep}' -- $curr_arg ) )
}
complete -F _dcdbquery_options dcdbquery