-
Notifications
You must be signed in to change notification settings - Fork 0
/
creatpy
executable file
·79 lines (59 loc) · 1.35 KB
/
creatpy
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
createOption="--create"
addOption="--add"
rcFilePath="$HOME/bin/rcfiles/creatpy_rc"
pythonPath="#!$(which python3)"
usage()
{
echo "use the option $createOption to create the projects folder files"
echo "You can use a the option $addOption to add a new script file into the current project dir"
echo "The project folder created in the current directory"
}
noargsError()
{
argNum=$1
if test $argNum -eq 0; then
echo "No arguments enter the project(s) names(s)"
usage
exit -1
fi
}
addFile()
{
if ! grep -Eq "^$PWD$" $rcFilePath; then
echo "This dir is not registred as project directory"
exit -1
fi
for file in $@; do
fileWithExt=$file.py
if ! test -f $fileWithExt; then
echo $pythonPath > $fileWithExt
chmod 777 $fileWithExt
else
echo "file $fileWithExt already exists"
fi
done
}
createProjectFolder()
{
for file in $@; do
mkdir $file
echo $PWD/$file >> $rcFilePath
$EDITOR $file
done
}
if ! test -f $rcFilePath; then
echo "creating rc file"
touch $rcFilePath
fi
noargsError $#
firstArg=$1
shift
theRest=$@
if test $firstArg = $createOption; then
createProjectFolder $theRest
elif test $firstArg = $addOption; then
addFile $theRest
else
usage
fi