浏览代码

~/.bin/deadlines: record what you're working on.

needs a different name. turns out i either want to record what i want to
be working on _next_ or how far i got with what i was working on last.

random different idea: a music client that allows scheduling operations
at different points in time (before/after current song/album/playlist,
at a specific point in time, lots of others probably). on a mobile
device this is achieved by long tapping on the thing you wanted to do.
(e.g long tap on "enqueue" -> enqueue at some point).
Lucas Stadler 11 年之前
父节点
当前提交
6a84e69bb4
共有 1 个文件被更改,包括 48 次插入0 次删除
  1. 48 0
      .bin/deadlines

+ 48 - 0
.bin/deadlines

@ -0,0 +1,48 @@
1
#!/usr/bin/env ruby
2
3
require 'json'
4
5
def ask_for_task()
6
  `zenity --forms --add-entry 'Task name' --add-list 'Task duration' --list-values='15min|30min|1h|2h'`
7
end
8
9
def parse_task(task_answer)
10
  task_name, task_duration = task_answer.split('|')
11
  duration = parse_duration(task_duration)
12
  {name: task_name, end: Time.now + duration}
13
end
14
15
def parse_duration(duration)
16
  case duration
17
  when '15min'
18
    15 * 60
19
  when '30min'
20
    30 * 60
21
  when '1h'
22
    60 * 60
23
  when '2h'
24
    2 * 60 * 60
25
  else
26
    15 * 60
27
  end
28
end
29
30
class File
31
  def self.append(name, str)
32
    write(name, str, {mode: 'a'})
33
  end
34
end
35
36
def answer_once()
37
  answer = ask_for_task()
38
  task = parse_task(answer)
39
  puts("-- working on '#{task[:name]}' until #{task[:end]}")
40
  File.append("#{File.join(Dir.home, ".deadlines.json")}", JSON.dump(task) + "\n")
41
  sleep(task[:end] - Time.now)
42
end
43
44
if __FILE__ == $0
45
  while true
46
    answer_once()
47
  end
48
end