forked from rock-simulation/mars_install_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_complete.sh
executable file
·66 lines (55 loc) · 1.42 KB
/
auto_complete.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
62
63
64
65
66
#! /bin/bash
SOURCES_FILE="sources.txt"
pushd . > /dev/null 2>&1
function setScriptDir {
if [[ x"${MARS_SCRIPT_DIR}" == "x" ]]; then
MARS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
fi
export MARS_SCRIPT_DIR=${MARS_SCRIPT_DIR}
}
setScriptDir
function parse_yaml {
local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034')
sed -ne "/.:./d" \
-e "/#/d" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\2|p" $1
}
packages1="bootstrap install rebuild clean fetch update diff"
packages=""
while read source_file; do
source_file=${source_file/\#*/}
if [[ x${source_file} = x ]]; then
continue
fi
p=$(parse_yaml "${MARS_SCRIPT_DIR}/${source_file}")
IFS='
'
set -f
for line in ${p}; do
if [[ x${packages} != x ]]; then
packages+=" "
fi
packages+=${line}
done
set +f
unset IFS
done < ${MARS_SCRIPT_DIR}/${SOURCES_FILE}
txt_files=$(ls ${MARS_SCRIPT_DIR} | grep ".txt")
IFS='
'
set -f
for line in ${txt_files}; do
if [[ x${packages} != x ]]; then
packages+=" "
fi
packages+=${line}
done
set +f
unset IFS
#echo "packages: ${packages1} ${packages}"
complete -o default -W "${packages1} ${packages}" mars.sh
complete -o default -W "${packages}" mars_install
complete -o default -W "${packages}" mars_bootstrap
complete -o default -W "${packages}" mars_rebuild
complete -o default -W "${packages}" mars_diff
popd > /dev/null 2>&1