daily-txt 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -3
- data/lib/daily/txt/cli.rb +42 -3
- data/lib/daily/txt/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82fcae4cad96930a6289dde3fb38395fa441c9c3
|
4
|
+
data.tar.gz: b0bd112322c56f42246876be2f02f79c75870542
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9a49e690e5d6cf0a4f1880913d38f91b2ca39c13c628d4c81657f14684c12348ac91ae20a3ed51234d58c4751770152cce1a96b990428e387a4ce86f3f71e2d
|
7
|
+
data.tar.gz: 2c2f36efaadcf09782f57dbfce0470f3bc9b6043ee37cccd189cbc25fc8c770ec9f9b1682e9a13b0abfe980d2d409b1307934b6b290a9bb1c75b1087b6e61361
|
data/README.md
CHANGED
@@ -8,12 +8,12 @@ daily-txt is command line script for creating and listing text files that has a
|
|
8
8
|
$ daily-txt
|
9
9
|
```
|
10
10
|
|
11
|
-
|
12
|
-
and open it with default editor. If it already exists, just open it for
|
11
|
+
The command above creates text file at /${ROOT}/text/{$YYYY}/{$MM}/${YYYY}_${MM}_${DD}.txt
|
12
|
+
and open it with default editor. If it already exists, just open it for editing.
|
13
13
|
|
14
14
|
### Initialize
|
15
15
|
|
16
|
-
daily-txt command asks ROOT directory and default editor
|
16
|
+
At initial startup, daily-txt command asks ROOT directory and default editor. And it stores
|
17
17
|
setting to ~/.daily-txt.rc.
|
18
18
|
|
19
19
|
```
|
@@ -25,6 +25,14 @@ Default Editor? (/usr/bin/vim):
|
|
25
25
|
Setting stored to ~/.daily-txt.rc
|
26
26
|
```
|
27
27
|
|
28
|
+
### Open past file
|
29
|
+
|
30
|
+
-p 1 for yesterday, -p 2 for the day before yesterday.
|
31
|
+
|
32
|
+
```
|
33
|
+
$ daily-txt -p 1
|
34
|
+
```
|
35
|
+
|
28
36
|
### Listing
|
29
37
|
|
30
38
|
List text files
|
@@ -37,6 +45,12 @@ $ daily-txt -l
|
|
37
45
|
/your/root/text/2016/04/2016_05_04.txt
|
38
46
|
```
|
39
47
|
|
48
|
+
### Search files with text
|
49
|
+
|
50
|
+
```
|
51
|
+
$ daily-txt -s "search query"
|
52
|
+
```
|
53
|
+
|
40
54
|
## Installation
|
41
55
|
|
42
56
|
Add this line to your application's Gemfile:
|
data/lib/daily/txt/cli.rb
CHANGED
@@ -3,6 +3,8 @@ require "daily/txt/path_builder"
|
|
3
3
|
require 'date'
|
4
4
|
require 'optparse'
|
5
5
|
require 'file/visitor'
|
6
|
+
require 'term/ansicolor'
|
7
|
+
include Term::ANSIColor
|
6
8
|
|
7
9
|
class Daily::Txt::CLI
|
8
10
|
|
@@ -15,12 +17,23 @@ class Daily::Txt::CLI
|
|
15
17
|
parser.on('-f PATH', 'config file path') do |path|
|
16
18
|
option[:config_path] = path
|
17
19
|
end
|
20
|
+
parser.on('-s VAL', '--search VAL', 'search file including VAL') do |query|
|
21
|
+
option[:mode] = :search
|
22
|
+
option[:query] = query
|
23
|
+
end
|
18
24
|
parser.on('-l', '--list', 'list text files') do |path|
|
19
25
|
option[:mode] = :list
|
20
26
|
end
|
21
27
|
parser.on('--ascending', 'make list order ascending') do
|
22
28
|
option[:asc] = true
|
23
29
|
end
|
30
|
+
parser.on('-p VAL', 'open file for VAL day(s) ago') do |day|
|
31
|
+
past = day.to_i
|
32
|
+
if past <= 0
|
33
|
+
abort "invalid value for -p: #{day}"
|
34
|
+
end
|
35
|
+
option[:past] = past
|
36
|
+
end
|
24
37
|
|
25
38
|
begin
|
26
39
|
parser.parse!(argv)
|
@@ -55,8 +68,10 @@ class Daily::Txt::CLI
|
|
55
68
|
case option[:mode]
|
56
69
|
when :list
|
57
70
|
list(config, option)
|
71
|
+
when :search
|
72
|
+
search(config, option[:query])
|
58
73
|
else
|
59
|
-
open_today(config)
|
74
|
+
open_today(config, option[:past])
|
60
75
|
end
|
61
76
|
end
|
62
77
|
|
@@ -75,9 +90,33 @@ class Daily::Txt::CLI
|
|
75
90
|
end
|
76
91
|
end
|
77
92
|
|
78
|
-
def
|
93
|
+
def search(config, query)
|
94
|
+
visitor = File::Visitor.new
|
95
|
+
visitor.add_filter(:ext, Daily::Txt::PathBuilder::DEFAULT_EXT)
|
96
|
+
visitor.set_direction(:desc)
|
97
|
+
|
98
|
+
hilighted_query = "#{yellow}#{query}#{reset}"
|
99
|
+
visitor.visit(config["home"]) do |path|
|
100
|
+
header_printed = false
|
101
|
+
File.open(path) do |file|
|
102
|
+
header_printed = false
|
103
|
+
file.each_line do |line|
|
104
|
+
if line.match(/#{query}/)
|
105
|
+
unless header_printed
|
106
|
+
print "\n", green, path, reset, "\n"
|
107
|
+
header_printed = true
|
108
|
+
end
|
109
|
+
line = line.gsub(query, hilighted_query)
|
110
|
+
puts line
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def open_today(config, past)
|
79
118
|
path = Daily::Txt::PathBuilder.by_date(
|
80
|
-
config["home"], Date.today)
|
119
|
+
config["home"], (Date.today - (past || 0)))
|
81
120
|
Daily::Txt::PathBuilder.prepare_basedir(path)
|
82
121
|
Daily::Txt::System.exec(config["editor"], path)
|
83
122
|
end
|
data/lib/daily/txt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daily-txt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bonar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.5.1
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: command line tool for daily text file memo
|