-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprint.sh
59 lines (59 loc) · 1.94 KB
/
sprint.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
sprint()
{
flag_n='false'
flag_w='false'
flag_p='false'
if [[ $# -lt 1 ]]; then
echo 'script usage:'
echo 'sprint -[p/n/w <week number>] -r <line> -u -[s/a <task>]'
fi
# Triggers when no SPRINT_PATH variable exists
if [[ -z "${SPRINT_PATH}" ]]; then
# Creates new sprint_file
touch sprint_file
export SPRINT_PATH=$PWD/.sprint
else
CURRENT_WEEK=$(date +"%U") #Gets current week
while getopts "upcda:sr:nw:" FLAGS; do #Collets flags
case "$FLAGS" in
p) # Swith to the previous week
flag_p='true'
((CURRENT_WEEK -=1)) ;;
w) # Allows to chose a week
flag_w="true"
CURRENT_WEEK=${OPTARG} ;;
n) # Switch to the next week
flag_n="true"
((CURRENT_WEEK += 1)) ;;
a) # Adds a new task
echo "Week $CURRENT_WEEK : ${OPTARG}" >> $SPRINT_PATH
echo "sprint: task added to week $CURRENT_WEEK" ;;
s) #Shows current week
echo "Line : Week : Task"
grep $CURRENT_WEEK $SPRINT_PATH -n ;;
r) #Removes tasks based on the line
LINE=$2'd'
echo "sprint: removing task at the line $2"
sed -i "$LINE" "$SPRINT_PATH" ;;
d) # Delets the week
echo "Do you want to delete all tasks from $CURRENT_WEEK ?"
read ACTION
if [[ $ACTION == 'y' ]]; then
sed -i "/\b\(Week $CURRENT_WEEK\)\b/d" "$SPRINT_PATH"
echo "Delete all tasks from $CURRENT_WEEK"
fi ;;
u) # Moves tasks from a previous to the current
PREV_WEEK=$(date +"%U")
((PREV_WEEK -= 1))
echo $CURRENT_WEEK
grep 'Week $PREV_WEEK :' $SPRINT_PATH | xargs sed -i "s/Week $PREV_WEEK :/Week $CURRENT_WEEK :/g" "$SPRINT_PATH"
;;
*)
echo 'sprint -[p/n/w <week number>] -r <line> -u -[s/a <task>]'
esac
done
fi
if $flag_n && $flag_w && $flag_p; then
echo "Wrong flag combination"
fi
}