Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit 77e830b

Browse files
committed
Initial Public Release
0 parents  commit 77e830b

15 files changed

+1176
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.png filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
info.plist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 nxt Engineering GmbH
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Alfred Workflow for Hakuna
2+
3+
This is a workflow in [Alfred][alfred] that allows to start and stop timers in [Hakuna][hakuna].
4+
5+
[alfred]: https://www.alfredapp.com
6+
[hakuna]: https://www.hakuna.ch
7+
8+
## Setup
9+
10+
To configure this workflow you need to define the following two variables as follows:
11+
12+
* `hakuna_api_key`, which you get by clicking on your name in the top right corner of Hakuna and then choosing "API".
13+
* `hakuna_base_url`, which is your Hakuna URL until the first slash ('/'), e.g. "https://companyname.hakuna.ch"
14+
15+
## License
16+
17+
This workflow is released under [MIT license][license].
18+
19+
[license]: https://github.com/nxt-engineering/alfred-hakuna/blob/master/LICENSE
20+
21+
## Contributions
22+
23+
The source code is available at [Github][gh]. Pull requests are welcome.
24+
25+
[gh]: https://github.com/nxt-engineering/alfred-hakuna
26+
27+
## Development
28+
29+
Clone this repository.
30+
Copy the `info.plist.template` file to `info.plist`.
31+
32+
The update the variables `hakuna_api_key` and `hakuna_base_url` to match your Hakuna instance.
33+
34+
**Before you push, make sure to copy `info.plist` to `info.plist.template` and remove all sensitive information!**
35+
36+
## Release
37+
38+
To release, export the workflow in Alfred and adjust the version.
39+
Then create a git tag with the same version.
40+
41+
Finally, go to Github and create a new release and upload the exported workflow file.
42+
43+
## Sponsor
44+
45+
The creation of this workflow was sponsored by [nxt Engineering GmbH][nxt].
46+
47+
[nxt]: https://nxt.engineering

action_get_overview.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
. utils.sh
4+
5+
load overview
6+
7+
overtime=$(filter .overtime)
8+
remaining_days=$(filter .vacation.remaining_days)
9+
10+
echo "Your overtime as of yesterday is $overtime and you have $remaining_days vacation days remaining."
11+
12+
cleanup

action_get_timer.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
. utils.sh
4+
5+
load timer
6+
7+
if ! start_time=$(filter .start_time); then
8+
echo "Currently there is no running timer to show."
9+
exit 1
10+
fi
11+
12+
duration=$(filter .duration)
13+
task=$(filter .task.name)
14+
project=$(filter .project.name)
15+
16+
if code=$(filter .project.code); then
17+
project="[$code] $project"
18+
fi
19+
20+
echo "You've spent $duration on $task for $project since $start_time."
21+
22+
cleanup

action_project_list.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
3+
. utils.sh
4+
5+
load projects
6+
7+
filter \
8+
'{ "items": [
9+
.[] | select(.archived == false) |
10+
{
11+
"uid": .id,
12+
"type": "default",
13+
"title": .name,
14+
"arg": .id,
15+
"autocomplete": .name
16+
}
17+
]
18+
}'
19+
20+
cleanup

action_start_timer.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
3+
. utils.sh
4+
5+
format_time() {
6+
if expr "$1" : '^[0-2][0-9]:[0-5][0-9]:[0-5][0-9]$' > /dev/null; then
7+
echo "${1%:*}"
8+
return 0
9+
elif ! expr "$start_time" : '^[0-2][0-9]:[0-5][0-9]$' > /dev/null; then
10+
echo "$1"
11+
return 1
12+
else
13+
echo "$1"
14+
return 0
15+
fi
16+
}
17+
18+
project_id=${hakuna_project_id-$1}
19+
task_id=${hakuna_task_id-$2}
20+
if ! start_time=$(format_time "${start_time-$3}"); then
21+
echo "The given time '$start_time' is not valid. The expected format is 'hh:mm' or 'hh:mm:ss'."
22+
fi
23+
note=${hakuna_note-${4-}}
24+
25+
echo \
26+
"{
27+
\"project_id\": \"$project_id\",
28+
\"task_id\": \"$task_id\",
29+
\"start_time\": \"$start_time\",
30+
\"note\": \"$note\"
31+
}" \
32+
| load timer POST @-
33+
34+
if filter .status > /dev/null; then
35+
echo "Error starting timer: $(filter .status, .message)" 1>&2
36+
echo "It was not possible to start the timer. Is one already running?"
37+
exit 1
38+
fi
39+
40+
start_time=$(filter .start_time)
41+
task=$(filter .task.name)
42+
project=$(filter .project.name)
43+
44+
if code=$(filter .project.code); then
45+
project="[$code] $project"
46+
fi
47+
48+
echo "The timer was started."
49+
echo "Since $start_time you're now working on $task for $project."
50+
51+
cleanup

action_stop_timer.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
. utils.sh
4+
5+
load timer PUT
6+
7+
if filter .error > /dev/null; then
8+
echo "Currently there is no running timer to stop."
9+
exit 1
10+
fi
11+
12+
start_time=$(filter .start_time)
13+
end_time=$(filter .end_time)
14+
duration=$(filter .duration)
15+
task=$(filter .task.name)
16+
project=$(filter .project.name)
17+
18+
if code=$(filter .project.code); then
19+
project="[$code] $project"
20+
fi
21+
22+
echo "The timer was stopped."
23+
echo "You've spent $duration on $task for $project from $start_time until $end_time."
24+
25+
cleanup

action_task_list.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
project_id=${hakuna_project_id-$1}
4+
5+
. utils.sh
6+
7+
load projects
8+
9+
filter \
10+
"{ \"items\": [
11+
.[] | select(.id == $project_id) |
12+
.tasks[] | select(.archived == false) |
13+
{
14+
\"uid\": .id,
15+
\"type\": \"default\",
16+
\"title\": .name,
17+
\"arg\": .id,
18+
\"autocomplete\": .name
19+
}
20+
]
21+
}"
22+
23+
cleanup

0 commit comments

Comments
 (0)