pday 0.3.2 → 0.4
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.
- data/lib/pday.rb +30 -11
- metadata +3 -3
data/lib/pday.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'date'
|
|
|
5
5
|
require 'yaml'
|
|
6
6
|
|
|
7
7
|
include Methadone::Main
|
|
8
|
+
include Methadone::CLILogging
|
|
8
9
|
|
|
9
10
|
def isdate testdate
|
|
10
11
|
begin
|
|
@@ -18,7 +19,11 @@ end
|
|
|
18
19
|
# REVISIT THIS TO MAKE THE HEADER TEXT CUSTOMIZABLE
|
|
19
20
|
# Default to a Header 1 in Markdown:
|
|
20
21
|
def prepopulate headertext
|
|
21
|
-
return "# "+headertext
|
|
22
|
+
return "# "+headertext+"\n\n"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def formatlog logtext
|
|
26
|
+
return "* "+logtext
|
|
22
27
|
end
|
|
23
28
|
|
|
24
29
|
def formatdate requesteddate, dateformat
|
|
@@ -42,12 +47,13 @@ end
|
|
|
42
47
|
|
|
43
48
|
main do
|
|
44
49
|
|
|
45
|
-
#
|
|
50
|
+
# DEFAULT OPTIONS HANDLING
|
|
46
51
|
default_options=Hash.new
|
|
47
52
|
default_options['suffix-delimit'] = '-'
|
|
48
53
|
default_options['format'] = 'md'
|
|
49
54
|
default_options['editor'] = 'vim'
|
|
50
55
|
default_options['date-format'] = "%Y.%m.%d"
|
|
56
|
+
default_options['timestamp'] = true
|
|
51
57
|
# Load the .dayconfig file and merge in options there:
|
|
52
58
|
CONFIG_FILE = File.join(ENV['HOME'],'.dayconfig')
|
|
53
59
|
if File.exists? CONFIG_FILE
|
|
@@ -59,7 +65,7 @@ main do
|
|
|
59
65
|
end
|
|
60
66
|
default_options.merge!(options)
|
|
61
67
|
options.merge!(default_options)
|
|
62
|
-
|
|
68
|
+
# END DEFAULT OPTIONS HANDLING
|
|
63
69
|
|
|
64
70
|
# Check if the diary directory is found:
|
|
65
71
|
unless options['path']
|
|
@@ -81,7 +87,7 @@ main do
|
|
|
81
87
|
end
|
|
82
88
|
end
|
|
83
89
|
|
|
84
|
-
#
|
|
90
|
+
# CHECK TO SEE IF THERE IS A SUFFIX, AND IF SO, ADD THE SUFFIX DELIMITER:
|
|
85
91
|
if options[:suffix]
|
|
86
92
|
suffix=options['suffix-delimit']+options['suffix']
|
|
87
93
|
else
|
|
@@ -89,31 +95,44 @@ main do
|
|
|
89
95
|
end
|
|
90
96
|
|
|
91
97
|
|
|
92
|
-
#
|
|
98
|
+
# BUILD THE COMMAND TO CREATE THE FILE WITH THE HEADER AND EDIT IT:
|
|
93
99
|
filepath=options['path']+entrydate+suffix+'.'+options['format']
|
|
94
100
|
if File.file?(filepath)
|
|
95
101
|
unless options[:force]
|
|
96
|
-
puts "File already exists. Will
|
|
102
|
+
puts "File already exists. Will use existing file."
|
|
97
103
|
else
|
|
98
104
|
puts "File already exists, replacing it."
|
|
99
105
|
`echo '#{prepopulate(entrydate)}' > "#{filepath}"`
|
|
100
106
|
end
|
|
101
107
|
else
|
|
102
108
|
puts "Creating new entry for: "+entrydate
|
|
103
|
-
`echo '#{prepopulate(entrydate)}' > "#{filepath}"`
|
|
109
|
+
`echo '#{prepopulate(entrydate)}' > "#{filepath}"`
|
|
110
|
+
end
|
|
111
|
+
unless options[:log]
|
|
112
|
+
puts "Editing entry: #{filepath}"
|
|
113
|
+
exec("#{options['editor']} '#{filepath}'")
|
|
114
|
+
else
|
|
115
|
+
# THE LOG OPTION IS ON SO JUST APPEND A LINE
|
|
116
|
+
if options['log']!=''
|
|
117
|
+
puts "Adding log entry to: #{filepath}"
|
|
118
|
+
if options[:timestamp]
|
|
119
|
+
options['log']=Time.new.strftime("%H:%M")+" "+options['log']
|
|
120
|
+
end
|
|
121
|
+
exec("echo '#{formatlog(options['log'])}' >> #{filepath}")
|
|
122
|
+
end
|
|
104
123
|
end
|
|
105
|
-
puts "Editing entry: #{filepath}"
|
|
106
|
-
exec("#{options['editor']} '#{filepath}'")
|
|
107
124
|
end
|
|
108
125
|
|
|
109
126
|
version '0.3'
|
|
110
127
|
description 'Simple plain text diary management script.'
|
|
111
128
|
|
|
112
129
|
on("-t FORMAT","--format","Set format suffix")
|
|
113
|
-
on("-f","--force","
|
|
130
|
+
on("-f","--force","Replace any existing file instead of editing it")
|
|
114
131
|
on("-s SUFFIX","--suffix","Add suffix to file name (before format suffix)")
|
|
115
132
|
on("-e EDITOR","--editor","Set the editor, vim, emacs, nano, etc.")
|
|
116
|
-
on("-d DATE","--date","Supply an explicit date
|
|
133
|
+
on("-d DATE","--date","Supply an explicit date (also y, yy, yyy, t) ")
|
|
134
|
+
on("-l LOG","--log","Instead of opening file, add a single log line")
|
|
135
|
+
on("-p","--timestamp","Add timestamp to single line log")
|
|
117
136
|
|
|
118
137
|
|
|
119
138
|
go!
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pday
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: '0.4'
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-04-
|
|
12
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: Simple shortcut script for creating a new plain text diary entry with
|
|
15
15
|
today's date.
|
|
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
42
42
|
version: '0'
|
|
43
43
|
requirements: []
|
|
44
44
|
rubyforge_project:
|
|
45
|
-
rubygems_version: 1.8.
|
|
45
|
+
rubygems_version: 1.8.25
|
|
46
46
|
signing_key:
|
|
47
47
|
specification_version: 3
|
|
48
48
|
summary: Simple plain text diary management script.
|