ntxt 1.0.1 → 1.0.2
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/ntxt +35 -5
- metadata +10 -9
data/bin/ntxt
CHANGED
@@ -3,12 +3,27 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'optparse'
|
5
5
|
require 'ntxt'
|
6
|
+
require 'yaml'
|
6
7
|
|
7
8
|
$configs = {
|
8
9
|
:cmd => 'tag',
|
9
|
-
:tag_string => ''
|
10
|
+
:tag_string => '',
|
11
|
+
:filename => "#{ENV['HOME']}/notes.txt"
|
10
12
|
}
|
11
13
|
|
14
|
+
DEFAULT_CONFIG_FILE="#{ENV['HOME']}/.ntxtrc"
|
15
|
+
|
16
|
+
# Create or load a configuration file.
|
17
|
+
if File.exists?(DEFAULT_CONFIG_FILE)
|
18
|
+
File.open(DEFAULT_CONFIG_FILE) do |io|
|
19
|
+
$configs.merge!(YAML::load(io))
|
20
|
+
end
|
21
|
+
else
|
22
|
+
File.open(DEFAULT_CONFIG_FILE, 'w') do |io|
|
23
|
+
YAML::dump($configs, io)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
12
27
|
OptionParser.new do |opt|
|
13
28
|
|
14
29
|
opt.on('--trace', 'Trace through the file printing summaries.' ) do |v|
|
@@ -19,6 +34,10 @@ OptionParser.new do |opt|
|
|
19
34
|
$configs[:cmd] = 'print'
|
20
35
|
end
|
21
36
|
|
37
|
+
opt.on('-e','--edit', 'Edit using $NTXT_EDITOR or $EDITOR.' ) do |v|
|
38
|
+
$configs[:cmd] = 'edit'
|
39
|
+
end
|
40
|
+
|
22
41
|
opt.on('-T', '--print_tags', 'Print all tags in the document.') do |v|
|
23
42
|
$configs[:cmd] = 'print_tags'
|
24
43
|
end
|
@@ -42,9 +61,6 @@ end.parse! ARGV
|
|
42
61
|
|
43
62
|
if ARGV.length > 0
|
44
63
|
$configs[:filename] = ARGV.shift
|
45
|
-
else
|
46
|
-
puts "No file specified. Exiting"
|
47
|
-
exit 1
|
48
64
|
end
|
49
65
|
|
50
66
|
# Remove empty lines from blocks and print. Guards against nils and empty lines.
|
@@ -57,7 +73,12 @@ end
|
|
57
73
|
|
58
74
|
$configs[:tag_string] = ARGV.shift if ARGV.length > 0
|
59
75
|
|
60
|
-
|
76
|
+
begin
|
77
|
+
ntxt = File.open($configs[:filename]) { |io| Ntxt::Ntxt.new(io.read) }
|
78
|
+
rescue Errno::ENOENT => e
|
79
|
+
puts "The file #{$configs[:filename]} was not found. Exiting."
|
80
|
+
exit 1
|
81
|
+
end
|
61
82
|
|
62
83
|
case $configs[:cmd]
|
63
84
|
when 'print_tags'
|
@@ -84,6 +105,15 @@ when 'last'
|
|
84
105
|
ntxt.rootBlock.children[-$configs[:last].. -1].each do |blk|
|
85
106
|
puts blk.text
|
86
107
|
end
|
108
|
+
when 'edit'
|
109
|
+
editor = ENV['NTXT_EDITOR'] || ENV['EDITOR']
|
110
|
+
|
111
|
+
if editor.nil?
|
112
|
+
puts "Environment variable NTXT_EDITOR and EDITOR are not defined."
|
113
|
+
else
|
114
|
+
system("#{editor} \"#{$configs[:filename]}\"")
|
115
|
+
end
|
116
|
+
|
87
117
|
when 'trace'
|
88
118
|
ntxt.walkText(
|
89
119
|
lambda { |txt, depth, block| print txt },
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntxt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Sam Baskinger
|
@@ -14,8 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-
|
18
|
-
default_executable:
|
18
|
+
date: 2011-12-07 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: |
|
@@ -30,12 +30,11 @@ extra_rdoc_files: []
|
|
30
30
|
|
31
31
|
files:
|
32
32
|
- README.rdoc
|
33
|
+
- lib/ntxt.rb
|
34
|
+
- lib/ntxt/ntxt.rb
|
33
35
|
- lib/ntxt/block.rb
|
34
36
|
- lib/ntxt/parser.rb
|
35
|
-
- lib/ntxt/ntxt.rb
|
36
|
-
- lib/ntxt.rb
|
37
37
|
- bin/ntxt
|
38
|
-
has_rdoc: true
|
39
38
|
homepage: http://coffeesgone.wordpress.com
|
40
39
|
licenses: []
|
41
40
|
|
@@ -49,6 +48,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
48
|
requirements:
|
50
49
|
- - ">="
|
51
50
|
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
52
|
segments:
|
53
53
|
- 0
|
54
54
|
version: "0"
|
@@ -57,13 +57,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements:
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
60
61
|
segments:
|
61
62
|
- 0
|
62
63
|
version: "0"
|
63
64
|
requirements: []
|
64
65
|
|
65
66
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.
|
67
|
+
rubygems_version: 1.8.11
|
67
68
|
signing_key:
|
68
69
|
specification_version: 3
|
69
70
|
summary: A parser and some tools for the ntxt text block format.
|