bullet_journal 0.0.1.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/jo +30 -0
- data/lib/bullet_journal.rb +67 -0
- data/lib/bullet_journal/config.rb +67 -0
- data/lib/bullet_journal/day.rb +37 -0
- data/lib/bullet_journal/logger.rb +18 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3dc11e763d39307602e0df60912439b1ee28d60d1dec9e4ee0472c09368ff659
|
4
|
+
data.tar.gz: 886df135acffc8c6ac48fa14c12228fc5edf9d83eec66a6fdd46b782cac2d422
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ac2723e346c3be1f79c237d972f0d7d5bc9a113c39ea82ceb248816ccd2870a05591f3b59a26c0392462aeeb6766a65dc12ce91f17ac370717f290b645373e9
|
7
|
+
data.tar.gz: f84a93df1cd82de5c2d98530481e9f0824ef913f713a651822b4ceb7f17156c76730e3674221f501e1161a68d92a1c7f06aed6608ca294a75ed8994975018a6f
|
data/bin/jo
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bullet_journal'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
journal = BulletJournal.new(args: ARGV)
|
7
|
+
|
8
|
+
# So, you're probably wondering...
|
9
|
+
# `system` vs `exec`
|
10
|
+
# Well, exec effectively ends this process and
|
11
|
+
# launches your new one. System returns back to
|
12
|
+
# ruby once it's finished. This may have a memory/cpu
|
13
|
+
# penalty but I'm not sure. I can worry about that later.
|
14
|
+
# (there may be an upcoming reason why I would like to
|
15
|
+
# return to ruby once vim has closed, but I'm forgetting
|
16
|
+
# it right now)
|
17
|
+
|
18
|
+
#exec "nvim #{file_name}"
|
19
|
+
|
20
|
+
puts "Bullet journal file:"
|
21
|
+
puts " #{journal.full_path}"
|
22
|
+
|
23
|
+
# we can't open a file until it exists, so
|
24
|
+
# let's make sure it does
|
25
|
+
if (journal.editor == 'open')
|
26
|
+
`touch #{journal.full_path}` unless Pathname.new(journal.full_path).exist?
|
27
|
+
end
|
28
|
+
|
29
|
+
system "#{journal.editor} #{journal.full_path}" unless journal.editor == "none"
|
30
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class BulletJournal
|
2
|
+
def initialize(args: [],
|
3
|
+
day: BulletJournal::Day.new,
|
4
|
+
config: BulletJournal::Config.new)
|
5
|
+
|
6
|
+
@day = day
|
7
|
+
@someday = false
|
8
|
+
@config = config
|
9
|
+
parse_args(args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def full_path
|
13
|
+
File.join(@config.journal_location(name), path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def path
|
17
|
+
return "#{name}_Someday.md" if @someday
|
18
|
+
|
19
|
+
"#{name}_#{@day}.md"
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
@name ||= @config.default_journal_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def editor
|
27
|
+
@config.editor(name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def weekdays
|
31
|
+
#todo i18n
|
32
|
+
%w[monday tuesday wednesday thursday friday saturday sunday]
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def parse_args(args)
|
37
|
+
return if args.empty?
|
38
|
+
|
39
|
+
first_arg = args.shift.downcase
|
40
|
+
case first_arg
|
41
|
+
when "someday"
|
42
|
+
@someday = true
|
43
|
+
when "today"
|
44
|
+
when "yesterday"
|
45
|
+
@day.yesterday!
|
46
|
+
when "tomorrow"
|
47
|
+
@day.tomorrow!
|
48
|
+
when "last"
|
49
|
+
@day.previous!(args.shift.downcase)
|
50
|
+
when "next"
|
51
|
+
@day.next!(args.shift.downcase)
|
52
|
+
when *weekdays
|
53
|
+
@day.next!(first_arg)
|
54
|
+
else
|
55
|
+
args.unshift(first_arg)
|
56
|
+
end
|
57
|
+
parse_name(args)
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_name(name_args)
|
61
|
+
return if name_args.length == 0
|
62
|
+
@name = name_args.join('-').upcase
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
require 'bullet_journal/day.rb'
|
67
|
+
require 'bullet_journal/config.rb'
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'pathname'
|
3
|
+
require 'bullet_journal/logger'
|
4
|
+
|
5
|
+
class BulletJournal::Config
|
6
|
+
def initialize(
|
7
|
+
file: "~/.config/bullet_journal/config.yml",
|
8
|
+
logger: BulletJournal::Logger.new)
|
9
|
+
|
10
|
+
@logger = logger
|
11
|
+
file = File.expand_path(file) # macOS needs this
|
12
|
+
|
13
|
+
unless Pathname.new(file).exist?
|
14
|
+
create_initial_config(file)
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
@config_file = YAML.load_file(file)
|
19
|
+
@logger.info "Loaded config:\n #{file}"
|
20
|
+
rescue
|
21
|
+
@config_file = {}
|
22
|
+
@logger.error "Unable to load config file."
|
23
|
+
end
|
24
|
+
|
25
|
+
@logger.info "Default journal name:\n #{default_journal_name}"
|
26
|
+
@logger.info "Default journal location:\n #{journal_location}"
|
27
|
+
@logger.info "Default editor:\n #{editor}"
|
28
|
+
@logger.info
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_journal_name
|
32
|
+
journal.fetch('journal_name', 'JOURNAL')
|
33
|
+
end
|
34
|
+
|
35
|
+
def journal_location(journal_name = nil)
|
36
|
+
journal_name ||= "default"
|
37
|
+
journal(journal_name)
|
38
|
+
.fetch('journal_location',
|
39
|
+
journal.fetch('journal_location', "."))
|
40
|
+
end
|
41
|
+
|
42
|
+
def editor(journal_name = "default")
|
43
|
+
journal_name == "default" if journal_name == default_journal_name
|
44
|
+
journal(journal_name)
|
45
|
+
.fetch('editor',
|
46
|
+
journal.fetch('editor', 'vim'))
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def journal(name = "default")
|
51
|
+
@config_file.fetch(name.downcase, {})
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_initial_config(file)
|
55
|
+
@logger.info "Writing default config file."
|
56
|
+
pathname = Pathname(file)
|
57
|
+
pathname.dirname.mkpath
|
58
|
+
pathname.write(%{default:
|
59
|
+
journal_name: "JOURNAL"
|
60
|
+
journal_location: "."
|
61
|
+
editor: "vim"
|
62
|
+
})
|
63
|
+
@logger.info "Default config file written."
|
64
|
+
rescue
|
65
|
+
@logger.error "Unable to write default config file."
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class BulletJournal::Day
|
2
|
+
def initialize(time = Time.now)
|
3
|
+
@time = time
|
4
|
+
end
|
5
|
+
|
6
|
+
def to_s
|
7
|
+
@time.strftime("%Y-%m-%d_%A")
|
8
|
+
end
|
9
|
+
|
10
|
+
def day_name
|
11
|
+
@time.strftime("%A")
|
12
|
+
end
|
13
|
+
|
14
|
+
def yesterday!
|
15
|
+
@time -= 86400
|
16
|
+
end
|
17
|
+
|
18
|
+
def tomorrow!
|
19
|
+
@time += 86400
|
20
|
+
end
|
21
|
+
|
22
|
+
def previous!(requested_day_name)
|
23
|
+
#todo fix i18n
|
24
|
+
requested_day_name = "friday" if requested_day_name == "week"
|
25
|
+
begin
|
26
|
+
yesterday!
|
27
|
+
end while day_name.downcase != requested_day_name
|
28
|
+
end
|
29
|
+
|
30
|
+
def next!(requested_day_name)
|
31
|
+
#todo fix i18n
|
32
|
+
requested_day_name = "monday" if requested_day_name == "week"
|
33
|
+
begin
|
34
|
+
tomorrow!
|
35
|
+
end while day_name.downcase != requested_day_name
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class BulletJournal::Logger
|
2
|
+
def initialize(enabled: true)
|
3
|
+
@enabled = enabled
|
4
|
+
end
|
5
|
+
|
6
|
+
def info(message = "")
|
7
|
+
log(message)
|
8
|
+
end
|
9
|
+
|
10
|
+
def error(message = "")
|
11
|
+
log "[error] #{message}"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def log(message)
|
16
|
+
puts message if @enabled
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bullet_journal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Gough
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Helper utility for managing bullet journal style markdown files via the
|
14
|
+
terminal
|
15
|
+
email: bullet_journal@robgough.net
|
16
|
+
executables:
|
17
|
+
- jo
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/jo
|
22
|
+
- lib/bullet_journal.rb
|
23
|
+
- lib/bullet_journal/config.rb
|
24
|
+
- lib/bullet_journal/day.rb
|
25
|
+
- lib/bullet_journal/logger.rb
|
26
|
+
homepage: https://robgough.net/bullet-journal
|
27
|
+
licenses: []
|
28
|
+
metadata:
|
29
|
+
source_code_uri: https://github.com/robgough/bullet_journal
|
30
|
+
changelog_uri: https://github.com/robgough/bullet_journal/changelog.md
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.3.1
|
45
|
+
requirements: []
|
46
|
+
rubygems_version: 3.0.3
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Helper util for bullet journaling
|
50
|
+
test_files: []
|