-
Notifications
You must be signed in to change notification settings - Fork 1
/
breathe.sh
executable file
·110 lines (91 loc) · 1.78 KB
/
breathe.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
source frames.sh
CURSOR_ORIGIN="\033[0;0H"
RELAXING_TRACK="spotify:track:039xzKjVgqdnmoUOCXuEI2"
MAX_VOLUME=50
breathe() {
frame_count=${#FRAMES[@]}
# inhale
for((b=0;b<frame_count;b++)){
echo -ne "$CURSOR_ORIGIN"
echo -e "${FRAMES[b]}"
sleep 0.3
}
sleep 1
# exhale
for((b=frame_count-1;b>=0;b--)){
echo -ne "$CURSOR_ORIGIN"
echo -e "${FRAMES[b]}"
sleep 0.5
}
}
breathe_n_times() {
local n=$1
for((i=0;i<n;i++)){
breathe
}
}
exit_with_usage() {
printf "Usage: %s: [-n value]\n" "$0"
exit 2
}
intro() {
printf "Get comfortable..."
start_spotify &
sleep 5
printf "\rBegin breathing in... "
for((i=3;i>=1; i--)){
printf "%s\b" "$i"
sleep 1.5
}
clear
}
parse_arguments() {
local OPTIND
while getopts n: option ; do
case $option in
n ) OPTNUM=$OPTARG;;
? ) exit_with_usage ;;
esac
done
}
run()
{
if [ -n "$OPTNUM" ]
then
intro
breathe_n_times "$OPTNUM"
COMPLETE=1
else
exit_with_usage
fi
}
say_goodbye() {
if [ -n "$OPTNUM" ]
then
stop_spotify
clear
echo -e "\033[0m\n🧘 Goodbye :) 🧘"
fi
}
start_spotify() {
osascript -e "tell application \"Spotify\" to set sound volume to 0"
osascript -e "tell application \"Spotify\" to play track \"$RELAXING_TRACK\""
for((v=0;v<=MAX_VOLUME; v++)){
osascript -e "tell application \"Spotify\" to set sound volume to $v"
}
}
stop_spotify() {
if [ -n "$COMPLETE" ]
then
for((v=MAX_VOLUME;v>0; v--)){
osascript -e "tell application \"Spotify\" to set sound volume to $v"
}
fi
osascript -e "tell application \"Spotify\" to pause"
# reset spotify volume
osascript -e "tell application \"Spotify\" to set sound volume to 100"
}
trap say_goodbye EXIT
parse_arguments "$@"
run