habiter 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README +17 -0
  2. data/bin/habiter +81 -0
  3. metadata +56 -0
data/README ADDED
@@ -0,0 +1,17 @@
1
+ habiter is a simple tool for maintaining good habits
2
+
3
+ It can be used with the 'don't break the chain' technique, like
4
+ Joe's Goals or Sciral Consistency, but adopts more positive
5
+ techniques and uses a readable and editable YAML text file as
6
+ storage.
7
+
8
+ Demo
9
+ ----
10
+
11
+ ~$ habiter did clean_room
12
+ clean_room is not a habit yet. create and complete it? (y/n) y
13
+ ~$ habiter did jog
14
+ jog is not a habit yet. create and complete it? (y/n) y
15
+ ~$ habiter log
16
+ jog | ------------------------------+
17
+ clean_room | ------------------------------+
data/bin/habiter ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+ # Habiter: simple habit tracking
3
+ # add or update habit:
4
+ # 'habiter did clean_room'
5
+ # view habit graph:
6
+ # 'habiter graph'
7
+
8
+ require 'yaml'
9
+ require 'optparse'
10
+
11
+ # Stolen from ActiveSupport
12
+ class Time
13
+ def to_date
14
+ ::Date.new(year, month, day)
15
+ end unless method_defined?(:to_date)
16
+ end
17
+
18
+ class String
19
+ def colorize(color_code)
20
+ "\e[#{color_code}m#{self}\e[0m"
21
+ end
22
+ end
23
+
24
+
25
+
26
+ @habiter_file = File.expand_path('~/.habiter.yaml')
27
+
28
+ begin
29
+ @habits = YAML::load_file(@habiter_file)
30
+ rescue
31
+ File.open(@habiter_file, 'w').close()
32
+ end
33
+
34
+ @habits = {} unless @habits
35
+
36
+ options = {}
37
+ OptionParser.new do |opts|
38
+ opts.banner = "Usage: habiter.rb [options]"
39
+ end
40
+ def did(key)
41
+ if not @habits.has_key?(key)
42
+ print "#{key} is not a habit yet. create and complete it? (y/n) "
43
+ if STDIN.gets.chomp == 'y'
44
+ @habits[key] = [Time.now]
45
+ end
46
+ else
47
+ @habits[key] << Time.now
48
+ end
49
+ File.open(@habiter_file, 'w') do |f|
50
+ YAML.dump(@habits, f)
51
+ end
52
+ end
53
+
54
+
55
+ def log(options={})
56
+ options[:days] = 30 unless options[:days]
57
+ name_column_width = @habits.max {|a,b| a.length <=> b.length}[0].length
58
+ @habits.each do |habit, times|
59
+ day = Date.today - options[:days] * 86400
60
+ print sprintf("%#{name_column_width}s ", habit)
61
+ print "|".colorize(32)
62
+ times.collect! do |time|
63
+ time.to_date
64
+ end
65
+ (0..options[:days]).each do |i|
66
+ if times.include? day
67
+ print "+".colorize(32)
68
+ else
69
+ print "-".colorize(31)
70
+ end
71
+ day += 86400
72
+ end
73
+ puts
74
+ end
75
+ end
76
+
77
+ if ARGV[0] == 'did'
78
+ did(ARGV[1])
79
+ elsif ARGV[0] == 'log'
80
+ log()
81
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: habiter
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Tom MacWright
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-03 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Provides a command-line tool, habiter, which lets you manage a YAML of habit history
17
+ email: tom@developmentseed.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - bin/habiter
26
+ - README
27
+ has_rdoc: true
28
+ homepage: http://www.workingidea.com/
29
+ licenses: []
30
+
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.3.5
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: A simple text-based habit tracker
55
+ test_files: []
56
+