-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmozconfigwrapper.sh
executable file
·121 lines (103 loc) · 3 KB
/
mozconfigwrapper.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- mode: shell-script -*-
function mozconfigwrapper_buildwith_home {
typeset buildwith_home=$BUILDWITH_HOME
if [ "$buildwith_home" = "" ]
then
buildwith_home="$HOME/.mozconfigs"
export BUILDWITH_HOME=$buildwith_home
fi
}
function buildwith {
mozconfigwrapper_buildwith_home
typeset name="$1"
if [ -z "$name" ]
then
echo "Usage: buildwith <name>"
return 1
fi
if [ ! -f "$BUILDWITH_HOME/$name" ]
then
echo "Error: $BUILDWITH_HOME/$name does not exist"
return 1
fi
typeset export_command=$BUILDWITH_COMMAND
if [ "$export_command" = "" ]
then
export_command="export MOZCONFIG=#1"
fi
if [ ! "$2" = "silent" ]
then
export_command="$export_command && echo #1"
fi
mozconfig="$BUILDWITH_HOME/$name"
echo "$name" >| "$BUILDWITH_HOME/.active"
eval ${export_command//\#1/$mozconfig}
return 0
}
function mkmozconfig {
mozconfigwrapper_buildwith_home
typeset name="$1"
if [ -z "$name" ]
then
echo "Usage: mkmozconfig <name>"
return 1
fi
mozconfig="$BUILDWITH_HOME/$name"
python3 -c "from mozconfigwrapper import mkmozconfig; mkmozconfig('$name')"
echo "Created: $mozconfig"
buildwith $name "silent"
}
function rmmozconfig {
mozconfigwrapper_buildwith_home
typeset name="$1"
if [ -z "$name" ]
then
echo "Usage: rmmozconfig <name>"
return 1
fi
if [ ! -f "$BUILDWITH_HOME/$name" ]
then
echo "Error: $BUILDWITH_HOME/$name does not exist"
return 1
fi
mozconfig="$BUILDWITH_HOME/$name"
rm $mozconfig
echo "Removed: $mozconfig"
}
# Set up tab completion
# Adapted from virtualenvwrapper (written by Doug Hellman and Arthur Koziel)
function mozconfigwrapper_setup_tab_completion {
if [ -n "$BASH" ] ; then
_mozconfigs() {
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "`mozconfigwrapper_list_mozconfigs`" -- ${cur}) )
}
complete -o default -o nospace -F _mozconfigs buildwith rmmozconfig
elif [ -n "$ZSH_VERSION" ] ; then
_mozconfigs() {
reply=( $(mozconfigwrapper_list_mozconfigs) )
}
compctl -K _mozconfigs buildwith rmmozconfig
fi
}
# List the available mozconfigs.
function mozconfigwrapper_list_mozconfigs {
# NOTE: DO NOT use ls here because colorized versions spew control characters
# into the output list.
# echo seems a little faster than find, even with -depth 3.
mozconfigwrapper_buildwith_home || return 1
(echo "$BUILDWITH_HOME"/*) 2>/dev/null \
| command \fmt -w 1 \
| command \sed -e "s!^$BUILDWITH_HOME\/!!" \
| (unset GREP_OPTIONS; command \egrep -v '^\*$') 2>/dev/null
}
mozconfigwrapper_buildwith_home
mozconfigwrapper_setup_tab_completion
if [ -f "$BUILDWITH_HOME/.active" ]
then
active=`cat "$BUILDWITH_HOME/.active"`
if [ ! $active = "" ]
then
buildwith "$active" "silent"
fi
fi