├── README.md └── t /README.md: -------------------------------------------------------------------------------- 1 | # t # 2 | 3 | ## Description ## 4 | 5 | t is a shell script for working with [ledger][]'s [timelog][] format. 6 | 7 | ## Install ## 8 | 9 | Download and install the script to a `bin` directory that exists in your `$PATH`. For example, `$HOME/bin`: 10 | 11 | curl --silent -L -G https://raw.github.com/nuex/t/master/t -o ~/bin/t 12 | chmod +x ~/bin/t 13 | 14 | Set the location of your timelog file: 15 | 16 | export $TIMELOG=$HOME/.timelog.ldg 17 | 18 | The default location is `$HOME/.timelog.ldg`. 19 | 20 | ## Usage ## 21 | 22 | Usage: `t ` 23 | 24 | ### Actions ### 25 | 26 | - `t in` - clock into project or last project 27 | - `t out` - clock out of project 28 | - `t sw,switch` - switch projects 29 | - `t bal` - show balance 30 | - `t hours` - show balance for today 31 | - `t edit` - edit timelog file 32 | - `t cur` - show currently open project 33 | - `t last` - show last closed project 34 | - `t grep` - grep timelog for argument 35 | - `t cat` - show timelog 36 | - `t less` - show timelog in pager 37 | - `t timelog` - show timelog file 38 | 39 | ## References ## 40 | 41 | Even though this works with [ledger][] 3, the [timelog][] format is only referenced in the [ledger][] v2 documents. Here are a few resources about the [timelog][] format: 42 | 43 | - [Using timeclock to record billable time][timelog] 44 | - [timelog files][htl] - from the [hledger][] project 45 | 46 | [ledger]: http://ledger-cli.org 47 | [timelog]: http://ledger-cli.org/2.6/ledger.html#Using-timeclock-to-record-billable-time 48 | [htl]: http://hledger.org/MANUAL.html#timelog-files 49 | [hledger]: http://hledger.org/ 50 | -------------------------------------------------------------------------------- /t: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Show current timelog 4 | _t_timelog() { 5 | echo "$timelog" 6 | } 7 | 8 | # Run a ledger command on the timelog 9 | _t_ledger() { 10 | ledger -f "$timelog" "$@" 11 | } 12 | 13 | # do something in unix with the timelog 14 | _t_do() { 15 | action=$1; shift 16 | ${action} "$@" "${timelog}" 17 | } 18 | 19 | # Clock in to the given project 20 | # Clock in to the last project if no project is given 21 | _t_in() { 22 | [ ! "$1" ] && set -- "$@" "$(_t_last)" 23 | echo i `date '+%Y-%m-%d %H:%M:%S'` "$*" >> "$timelog" 24 | } 25 | 26 | # Clock out 27 | _t_out() { 28 | echo o `date '+%Y-%m-%d %H:%M:%S'` "$*" >> "$timelog" 29 | } 30 | 31 | # switch projects 32 | _t_sw() { 33 | echo o `date '+%Y-%m-%d %H:%M:%S'` >> "$timelog" 34 | echo i `date '+%Y-%m-%d %H:%M:%S'` "$*" >> "$timelog" 35 | } 36 | 37 | # Show the currently clocked-in project 38 | _t_cur() { 39 | sed -e '/^i/!d;$!d' "${timelog}" | __t_extract_project 40 | } 41 | 42 | # Show the last checked out project 43 | _t_last() { 44 | sed -ne '/^o/{g;p;};h;' "${timelog}" | tail -n 1 | __t_extract_project 45 | } 46 | 47 | # Show usage 48 | _t_usage() { 49 | # TODO 50 | cat << EOF 51 | Usage: t action 52 | actions: 53 | in - clock into project or last project 54 | out - clock out of project 55 | sw,switch - switch projects 56 | bal - show balance 57 | hours - show balance for today 58 | edit - edit timelog file 59 | cur - show currently open project 60 | last - show last closed project 61 | grep - grep timelog for argument 62 | cat - show timelog 63 | less - show timelog in pager 64 | timelog - show timelog file 65 | EOF 66 | } 67 | 68 | # 69 | # INTERNAL FUNCTIONS 70 | # 71 | 72 | __t_extract_project() { 73 | awk '$1 != "o" { 74 | line = $4 75 | for (i=5; i<=NF; i++) 76 | line = line " " $i; 77 | print line 78 | }' 79 | } 80 | 81 | action=$1; shift 82 | [ "$TIMELOG" ] && timelog="$TIMELOG" || timelog="${HOME}/.timelog.ldg" 83 | 84 | case "${action}" in 85 | in) _t_in "$@";; 86 | out) _t_out "$@";; 87 | sw) _t_sw "$@";; 88 | bal) _t_ledger bal "$@";; 89 | hours) _t_ledger bal -p "since today" "$@";; 90 | switch) _t_sw "$@";; 91 | edit) _t_do $EDITOR "$@";; 92 | cur) _t_cur "$@";; 93 | last) _t_last "$@";; 94 | grep) _t_do grep "$@";; 95 | cat) _t_do cat "$@";; 96 | less) _t_do less;; 97 | timelog) _t_timelog "$@";; 98 | 99 | h) _t_usage;; 100 | *) _t_usage;; 101 | esac 102 | 103 | exit 0 104 | --------------------------------------------------------------------------------