summaryrefslogtreecommitdiff
path: root/fish/conf.d/worktime.fish
blob: 2dfbe6b6e274a80015c5eb224abe32443a319bab (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
set -gx WORKTIME_DIR ~/git/worktime

if test (uname) = Darwin -a ! -f ~/.wtloggedin
    echo "Warn: Not logged in, run wtlogin"
end

function worktime
    ruby $WORKTIME_DIR/worktime.rb $argv
end

function worktime::sync
    cd $WORKTIME_DIR
    git commit -a -m sync
    git pull
    git push
    cd -
end

function worktime::wisdom_reminder
    if test -f $WORKTIME_DIR/work-wisdoms.md
        sed -n '/^\* / { s/\* //; p; }' $WORKTIME_DIR/work-wisdoms.md | sort -R | head -n 1
    end
end

function worktime::report
    if test -f ~/.wtloggedin
        if test -f ~/.wtmaster
            worktime --report | tee $WORKTIME_DIR/report.txt
        else
            worktime --report
        end
        worktime::wisdom_reminder
    end
end

function worktime::add
    set -l seconds $argv[1]
    set -l what $argv[2]
    set -l descr $argv[3]
    set -l epoch (date +%s)

    if test -z "$what"
        set what work
    end

    if test -z "$descr"
        worktime --add $seconds --epoch $epoch --what $what
    else
        worktime --add $seconds --epoch $epoch --what $what --descr "$descr"
    end

    worktime::report
end

function worktime::log
    set -l seconds $argv[1]
    set -l what $argv[2]
    set -l epoch (date +%s)

    if test -z "$what"
        set what work
    end

    worktime --log --epoch $epoch --what $what
    worktime::report
end

function worktime::login
    set -l what $argv[1]
    if test -z "$what"
        set what work
    end
    touch ~/.wtloggedin
    worktime --login --what $what
    worktime::wisdom_reminder
end

function worktime::logout
    set -l what $argv[1]

    if test -z "$what"
        set what work
    end

    if test -f ~/.wtloggedin
        rm ~/.wtloggedin
    end

    worktime --logout --what $what
    worktime::report
end

function worktime::status
    worktime::report

    if test -f ~/.wtloggedin
        echo "You are logged in"
        set -l num_worklog (ls $WORKTIME_DIR | grep wl- | wc -l)
        if test $num_worklog -gt 0
            echo "$num_worklog entries in the worklog in $WORKTIME_DIR/wl-*"
        end
    else
        echo "You are not logged in"
    end
end

abbr -a cdworktime "cd $WORKTIME_DIR"
abbr -a wt worktime
abbr -a wtedit 'worktime --edit'
abbr -a wtreport 'worktime --report'
abbr -a wtadd 'worktime::add'
abbr -a wtlog 'worktime::log'
abbr -a wtlogin 'worktime::login'
abbr -a wtlogout 'worktime::logout'
abbr -a wtstatus 'worktime::status'
abbr -a wtsync 'worktime::sync'
abbr -a wtf 'worktime --report'
abbr -a random_exercise "sort -R $WORKTIME_DIR/exercises.md | head -n 1"
abbr -a random_exercises "sort -R $WORKTIME_DIR/exercises.md | head -n 10"
abbr -a wl 'task add +work'
abbr -a ql 'task add +personal'
abbr -a pl 'task add +personal'