├── bin └── activetimer └── README.md /bin/activetimer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="${0%/*}" 4 | MARKFILE="$HOME/.cache/activetimer" 5 | UPTIMEFILE="/proc/uptime" 6 | 7 | # Resets the counter. 8 | mark () { 9 | mkdir -p $(dirname "$MARKFILE") 10 | touch $MARKFILE 11 | } 12 | 13 | # Echo the current uptime, if available. (eg, "23") 14 | get_uptime () { 15 | if [ -e "$UPTIMEFILE" ]; then 16 | cat "$UPTIMEFILE" | sed 's/\..*$//' 17 | fi 18 | } 19 | 20 | # Echoes number of seconds. (eg, "23") 21 | get_seconds () { 22 | NOW=$(date +"%s") 23 | UPTIME=$(get_uptime) 24 | 25 | if [ -e "$MARKFILE" ]; then 26 | THEN=$(stat -c "%Y" $MARKFILE) 27 | DELTA=$(echo $NOW - $THEN | bc) 28 | 29 | # If it's an old markfile, use the uptime 30 | if [ -n "$UPTIME" ] && (( $UPTIME < $DELTA )); then 31 | echo $UPTIME 32 | else 33 | echo $DELTA 34 | fi 35 | elif [ -n "$UPTIME" ]; then 36 | echo $UPTIME 37 | fi 38 | } 39 | 40 | # Echoes duration as a string. ("2h 32m") 41 | get_duration () { 42 | SECS=$(get_seconds) 43 | if [ -n "$SECS" ]; then 44 | if (( $SECS >= 3600 )); then 45 | echo $SECS | awk '{print int($1/3600)"h "int(($1%3600)/60)"m"}' 46 | elif (( $SECS >= 60 )); then 47 | echo $SECS | awk '{print int(($1%3600)/60)"m"}' 48 | else 49 | echo "${SECS}s" 50 | fi 51 | fi 52 | } 53 | 54 | # Run 55 | case $1 in 56 | start|mark) 57 | mark 58 | ;; 59 | 60 | seconds) 61 | get_seconds 62 | ;; 63 | 64 | duration) 65 | get_duration 66 | ;; 67 | 68 | *) 69 | echo "usage: $0 {start|seconds|duration}" 70 | ;; 71 | esac 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # activetimer 2 | 3 | > Track how long you've been working 4 | 5 | activetimer is a shell script. 6 | 7 | ## Install 8 | 9 | Use [bin/activetimer](bin/activetimer) however you like. You can also install me via npm (`npm install -g rstacruz/activetimer` - it's a shell script, npm is only used as an installer). 10 | 11 | ## Usage 12 | 13 | ```sh 14 | # Mark the current time as you started working 15 | activetimer start 16 | ``` 17 | 18 | ```sh 19 | # After some time, show how long you've been working since 20 | # you've typed the command above 21 | activetimer duration # => `2m 4s` 22 | ``` 23 | 24 | ## Practical usage 25 | 26 | **activetimer** is geared towards those who like to DIY their own desktop experience. It has no GUI, but you can integrate it into your desktop into whatever way you like. 27 | 28 | 1. **Show an indicator** — Show `activetimer duration` in your desktop somewhere. You can do this in many ways: 29 | 30 | > - [BitBar](https://bitbar.com/) (macOS) 31 | > - [GeekTool](https://www.tynsoe.org/v2/geektool/) (macOS) 32 | > - [Conky](https://github.com/brndnmtthws/conky) (Linux) 33 | > - [Polybar](https://github.com/jaagr/polybar) (Linux) 34 | > - your shell prompt 35 | > - your tmux status bar 36 | > - your vim status bar 37 | > - your emacs status bar 38 | > - _...and so on_ 39 | 40 | 2. **Auto-reset on idle** _(Optional)_ — Run `activetimer start` after your computer gets out of screensaver mode. This will reset the work timer after you've been away from your computer. Here's a few ways to do it: 41 | 42 | > - [Sleepwatcher](http://brewformulas.org/Sleepwatcher) (macOS) 43 | > - [xautolock](https://linux.die.net/man/1/xautolock) (Linux) 44 | 45 | 3. **Manual reset** _(Optional)_ — you can also make a shortcut to `activetimer start`, preferrably when you click on the indicator that you've set up in step 1. 46 | 47 | If you don't do either 2 or 3, simply run `activetimer start` manually to mark your time. 48 | 49 | ## Thanks 50 | 51 | **activetimer** © 2018, Rico Sta. Cruz. Released under the [MIT] License.
52 | Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]). 53 | 54 | > [ricostacruz.com](http://ricostacruz.com)  ·  55 | > GitHub [@rstacruz](https://github.com/rstacruz)  ·  56 | > Twitter [@rstacruz](https://twitter.com/rstacruz) 57 | 58 | [![](https://img.shields.io/github/followers/rstacruz.svg?style=social&label=@rstacruz)](https://github.com/rstacruz)   59 | [![](https://img.shields.io/twitter/follow/rstacruz.svg?style=social&label=@rstacruz)](https://twitter.com/rstacruz) 60 | 61 | [MIT]: http://mit-license.org/ 62 | [contributors]: http://github.com/rstacruz/activetimer/contributors 63 | --------------------------------------------------------------------------------