-
Notifications
You must be signed in to change notification settings - Fork 6
/
auto_complete.sh
executable file
·68 lines (59 loc) · 1.55 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
67
68
#! /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
# use the bash-builtin to provide basic package-completions.
#
# note that zsh for example does not know this commend.
if [ -n "$BASH_VERSION" ]; then
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
fi
popd > /dev/null 2>&1