pday 0.1.0
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/bin/pday +3 -0
- data/lib/pday.rb +87 -0
- metadata +49 -0
data/bin/pday
ADDED
data/lib/pday.rb
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'methadone'
|
|
4
|
+
require 'date'
|
|
5
|
+
require 'yaml'
|
|
6
|
+
|
|
7
|
+
include Methadone::Main
|
|
8
|
+
include Methadone::CLILogging
|
|
9
|
+
|
|
10
|
+
def isdate testdate
|
|
11
|
+
begin
|
|
12
|
+
Date.parse(testdate)
|
|
13
|
+
true
|
|
14
|
+
rescue
|
|
15
|
+
false
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Default to a Header 1 in Markdown:
|
|
20
|
+
def prepopulate headertext
|
|
21
|
+
return "# "+headertext
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
main do
|
|
26
|
+
default_options=Hash.new
|
|
27
|
+
default_options['suffix-delimit'] = ' - '
|
|
28
|
+
default_options['format'] = 'md'
|
|
29
|
+
default_options['editor'] = 'vim'
|
|
30
|
+
# Load the .dayconfig file and merge in options there:
|
|
31
|
+
CONFIG_FILE = File.join(ENV['HOME'],'.dayconfig')
|
|
32
|
+
if File.exists? CONFIG_FILE
|
|
33
|
+
config_options = YAML.load_file(CONFIG_FILE)
|
|
34
|
+
default_options.merge!(config_options)
|
|
35
|
+
else
|
|
36
|
+
# No config file found, prompt user to create one
|
|
37
|
+
puts "Could not find your .dayconfig file. You need one that at least contains your default path to the diary."
|
|
38
|
+
end
|
|
39
|
+
default_options.merge!(options)
|
|
40
|
+
options.merge!(default_options)
|
|
41
|
+
# Check if the diary directory is found:
|
|
42
|
+
unless options['path']
|
|
43
|
+
puts "Could not find path to your diary. Did you configure the .dayconfig file?"
|
|
44
|
+
exit
|
|
45
|
+
end
|
|
46
|
+
# Use today's date unless there is one supplied
|
|
47
|
+
unless options[:date]
|
|
48
|
+
entrydate=Time.now.strftime("%Y.%m.%d")
|
|
49
|
+
else
|
|
50
|
+
entrydate=options['date']
|
|
51
|
+
end
|
|
52
|
+
# Check to see if there is a suffix, and if so, add the suffix delimiter:
|
|
53
|
+
if options[:suffix]
|
|
54
|
+
suffix=options['suffix-delimit']+options['suffix']
|
|
55
|
+
else
|
|
56
|
+
suffix=''
|
|
57
|
+
end
|
|
58
|
+
# Build the command:
|
|
59
|
+
filepath=options['path']+entrydate+suffix+'.'+options['format']
|
|
60
|
+
puts "Creating new entry for: "+entrydate
|
|
61
|
+
`echo '#{prepopulate(entrydate)}' > #{filepath}`
|
|
62
|
+
puts "Editing entry..."
|
|
63
|
+
`#{options['editor']} #{filepath}`
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
version '0.1'
|
|
67
|
+
description 'Simple plain text diary management script.'
|
|
68
|
+
|
|
69
|
+
opts.on("-d DATE","--date","Supply an explicit date. Also accepts 'yesterday' or 'y'") do |date|
|
|
70
|
+
if date=='yesterday' || date=='y'
|
|
71
|
+
date=(Time.now-86400).strftime("%Y.%m.%d")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
unless isdate(date)
|
|
75
|
+
puts "DATE must be a valid date. For example \
|
|
76
|
+
'2013.1.15' or '01/15/2013' or 'Jan 1, 2013' or \
|
|
77
|
+
'yesterday'"
|
|
78
|
+
end
|
|
79
|
+
options[:date]=true
|
|
80
|
+
options['date']=Date.parse(date).strftime("%Y.%m.%d")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
on("-f FORMAT","--format","Set format suffix")
|
|
84
|
+
on("-s SUFFIX","--suffix","Add suffix")
|
|
85
|
+
on("-e EDITOR","--editor","Set the editor, vim, emacs, nano, etc.")
|
|
86
|
+
|
|
87
|
+
go!
|
metadata
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pday
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Konrad M. Lawson
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-04-13 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: Simple shortcut script for creating a new plain text diary entry with
|
|
15
|
+
today's date.
|
|
16
|
+
email: regs@huginn.net
|
|
17
|
+
executables:
|
|
18
|
+
- pday
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files: []
|
|
21
|
+
files:
|
|
22
|
+
- lib/pday.rb
|
|
23
|
+
- bin/pday
|
|
24
|
+
homepage: http://github.com/kmlawson/plain-day/
|
|
25
|
+
licenses:
|
|
26
|
+
- MIT
|
|
27
|
+
post_install_message:
|
|
28
|
+
rdoc_options: []
|
|
29
|
+
require_paths:
|
|
30
|
+
- lib
|
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
|
+
none: false
|
|
33
|
+
requirements:
|
|
34
|
+
- - ! '>='
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
|
+
none: false
|
|
39
|
+
requirements:
|
|
40
|
+
- - ! '>='
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
requirements: []
|
|
44
|
+
rubyforge_project:
|
|
45
|
+
rubygems_version: 1.8.25
|
|
46
|
+
signing_key:
|
|
47
|
+
specification_version: 3
|
|
48
|
+
summary: Simple plain text diary management script.
|
|
49
|
+
test_files: []
|