-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevenv.sh
76 lines (59 loc) · 1.91 KB
/
devenv.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
#!/bin/bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Midhath Ahmed. All rights reserved.
# Licensed under the MIT License.
#-------------------------------------------------------------------------------------------------------------
#
# Syntax: ./devenv.sh [project name]
set -e
PROJECT=${1:-"new-project"}
GH_USER=mdhthahmd
GH_REPO=devcontainers
GH_BRANCH=main
GH_ENV_PATH=config
declare -a DEV_ENVIRONMENTS=(`echo $( curl -s https://raw.githubusercontent.com/$GH_USER/$GH_REPO/$GH_BRANCH/.environments) | sed 's/\n/\n/g'`)
ENV_NO=${#DEV_ENVIRONMENTS[@]}
while true; do
for (( i=0; i < ${ENV_NO}; i++ ));
do
echo "[$i] ${DEV_ENVIRONMENTS[$i]}"
done
echo ""; read -p "please choose an environment: `echo $'\n> '`" env
if [ "$env" -ge 0 ] && [ "$env" -le "$ENV_NO" ]; then
break
fi
done
read -p "project name? ($PROJECT): " name
if [ -n "$name" ]; then
PROJECT=$name
fi
# check if $PROJECT exists and prompt to overwrite
if [ -d "$PROJECT" ]; then
while true; do
read -p "path $PROJECT already exists, overwrite? [Y/N]: " confirm
case $confirm in
[Yy]* ) rm -rf $PROJECT; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
mkdir $PROJECT && cd $PROJECT
git init
git checkout -b main
REMOTE_DEVENV=https://github.com/$GH_USER/$GH_REPO.git
git remote add origin $REMOTE_DEVENV
git sparse-checkout init
git sparse-checkout set "$GH_ENV_PATH/${DEV_ENVIRONMENTS[env]}"
git pull origin $GH_BRANCH
# move all files and folders including dot prefixed ones
shopt -s dotglob nullglob
mv $GH_ENV_PATH/${DEV_ENVIRONMENTS[env]}/* .
shopt -u dotglob nullglob
# clean up
rm -rf $GH_ENV_PATH .git
git clone https://github.com/$GH_USER/$PROJECT.git temp
shopt -s dotglob nullglob
mv temp/* .
shopt -u dotglob nullglob
rm -rf temp