-
Notifications
You must be signed in to change notification settings - Fork 3
/
project
executable file
·95 lines (76 loc) · 1.88 KB
/
project
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
#!/bin/bash
. _gotoutils # load common utility functions
STATEDIR=${HOME}/.goto
_usage() {
echo "Usage: project [add <projectname>] | [list]"
echo " other commands:"
echo " add <projectname> - adds a new project and makes it the active project."
echo " rm <projectname> - removes the project"
echo " list - lists all projects"
echo " help - if you want to read this one more time."
}
_addproject() {
touch "$STATEDIR/projects/$1"
}
_rmproject() {
if prompt "Are you sure you want to delete project $1? [y|n]: "; then
rm "$STATEDIR/projects/$1"
rm "$STATEDIR/projects/$1.json"
echo "Removed project $2"
else
echo
echo "Aborting delete of project $1"
fi
}
_listprojects() {
ls "$STATEDIR/projects" | grep -v .json
}
_changeproject() {
if [ -f "$STATEDIR/projects/$1" ]; then
echo "$1" > "$STATEDIR/active-project"
echo "active project is now: $1"
else
echo "Warning - tried to change to a non existing project."
echo "If you want to create it use the command:"
echo
echo " project add $1"
fi
}
_showactiveproject() {
cat "$STATEDIR/active-project"
}
# ---------------------------
# args parsing below
# ---------------------------
if [ $# -eq 0 ]
then _showactiveproject && exit
fi
if [ "$1" = "list" ]
then _listprojects && exit
fi
if [ "$1" = "help" ]
then _usage
exit 1
fi
if [ "$1" = "add" ]
then
if [ "$2" = "" ] ; then
_usage
else
_addproject "$2"
_changeproject "$2"
exit 0
fi
fi
if [ "$1" = "rm" ]
then
if [ "$2" = "" ] ; then
_usage
else
_rmproject "$2" "$3"
# TODO if active project == removed what to do? _changeproject "$2"
exit 0
fi
fi
# otherwise, activate project given
_changeproject "$1"