-
Notifications
You must be signed in to change notification settings - Fork 1
/
prj-env
executable file
·55 lines (47 loc) · 1.17 KB
/
prj-env
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
#!/bin/bash
## Usage:
##
## . prj-env alias,var1,etc...
##
## Example:
##
## . prj-env my,user,host
##
## Creates ~/.prj-env/my script. The my script sets
## the variables (var1,etc...). Intially, this script will
## prompt for variables that are not already found in the my
## environment. If all values are already available, this
## script runs silently.
##
## export user=john
## export host=johnDoe314.example.com
##
## Alias is a short word used to retrieve envirnonment.
## Prompts user then saves response in ~/.prj-env/my
##
IFS=',' read -ra ARRAY <<< "$1"
if test $# -ne 1 ||
test ${#ARRAY[*]} -lt 2 ||
test -z ${ARRAY[0]} ||
echo ${ARRAY[0]} | egrep "^-"
then
sh $(dirname $0)/prj-usage $0
host-aliases
exit 1
fi
alias=${ARRAY[0]}
unset ARRAY[0]
mkdir -p ~/.prj-env
touch ~/.prj-env/$alias
chmod u+x ~/.prj-env/$alias
for var in ${ARRAY[*]}
do
# If we do not have a variable for this, prompt and save one
if ! $(egrep "export $var=" ~/.prj-env/$alias > /dev/null)
then
read -p "~/.prj-env/$alias: export $var=" val
# Save the new variable
echo "export $var=$val" >> ~/.prj-env/$alias
fi
done
. ~/.prj-env/$alias