recollect 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 305d66ecdca334b3935b8966bf334103cf91d77b
4
- data.tar.gz: c2a8e0aae304513710da049184540fb1521fffad
3
+ metadata.gz: 8c177e96f7e3949dbcef4f928ee87732e5d63236
4
+ data.tar.gz: 44d7d65b15fd1094cca08a241f803bb94b4d08eb
5
5
  SHA512:
6
- metadata.gz: d88b248012759ed8967d51aa516910e3a29c7e8c3ccf53f11b4f653e6c46ccbe8c5338d5e29bd4a755024c5b55853dcf2f0521952598ef6b17dce8865944def5
7
- data.tar.gz: aed5fdfe030853859b1c66cda69b037a371ab44ccdc5a0f0b867b833c9d558432db9ef5d0d957d12bda78c67d8853e40b9a8e363d8d94ffc57b0024f4362ba36
6
+ metadata.gz: 7ab03355d64eaa96130f471ba609c9bb25edefd3fd686869a13701318850357b91f2867b35267c3261d44aefbbce710a903c38ce2c81dd34ea37c9268209c954
7
+ data.tar.gz: c74cd30221dc64d570de0aa62d97e6d2e2f72bf9ec8f18feb9f185b861a62bf7ecdb7923b4c3a2f84ca89fe92059a890c94aa3f524ddef00cb44fe4e73583173
data/CHANGELOG CHANGED
@@ -0,0 +1,4 @@
1
+ 0.0.6
2
+ - add support for subdirectories
3
+ - add verbose mode via DEBUG environment variable
4
+ - list subdirectory contents when matching recollection not found but subdirectory exists
data/TODO CHANGED
@@ -1,9 +1,3 @@
1
- Known Issues:
2
-
3
- - Add an open license
4
-
5
1
  Feature Requests:
6
2
 
7
- - Allow for the creation of nested snippets (sub-directories)
8
- - when listing, count topics in subdirectories but don't list the individual snippets
9
3
  - Add a search functionality that lists the snippet(s) containing the item searched for along with any matching content lines
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'pathname'
2
3
 
3
4
  module Recollect
4
5
  class Recollection
@@ -11,6 +12,7 @@ module Recollect
11
12
  @separator = '-------------------------'
12
13
  @recollect_path = File.join(ENV['HOME'], '.recollections')
13
14
  FileUtils.mkdir_p(@recollect_path)
15
+ @debug = ENV['DEBUG']
14
16
  end
15
17
 
16
18
  def usage(msg = nil)
@@ -19,42 +21,67 @@ module Recollect
19
21
  puts 'Recollect manages a series of things worth remembering "recollections" as a series of'
20
22
  puts "text files.\n\n"
21
23
  puts ' Actions: list, new, edit, or <name> where <name> is the recollection to be displayed.'
22
- puts ' list - provides a listing of all available recollections'
24
+ puts ' list [category] - provides a listing of all available recollections.'
25
+ puts ' use [category] to specify a subdirectory'
23
26
  puts " name - displays the recollection matching 'name'"
24
- puts ' new [name] - creates a new recollection'
25
- puts ' edit [name] - modifies an existing recollection'
26
- puts ' remove [name] - removes a recollection'
27
+ puts ' new <name> - creates a new recollection'
28
+ puts ' edit <name> - modifies an existing recollection'
29
+ puts ' remove <name> - removes a recollection'
27
30
  puts "\nNote: #{@reserved} are reserved and cannot be the name"
28
31
  puts 'of a recollection.'
29
32
  exit 1
30
33
  end
34
+
35
+ def debug(msg)
36
+ puts msg if @debug == '1' or @debug == 'true'
37
+ end
31
38
 
32
- def recollection_names
33
- recollections.map { |r| File.basename(r, File.extname(r)) }
39
+ def recollection_names(search_path = @recollect_path)
40
+ rec = []
41
+ recollections(search_path).each do |r|
42
+ abs = Pathname.new(File.expand_path(r))
43
+ rel = abs.relative_path_from(Pathname.new(File.expand_path(search_path)))
44
+ *p, f = rel.to_s.split('/')
45
+ file = File.basename(f, File.extname(f))
46
+ out = p.empty? ? file : File.join(p, file)
47
+ rec << out
48
+ end
49
+ rec
34
50
  end
35
51
 
36
- def recollections
37
- @recollections ||= Dir.glob(File.join(@recollect_path, '**'))
52
+ def recollections(search_path = @recollect_path)
53
+ Dir.glob(File.join(search_path, '**/*')).select { |f| f unless File.directory?(f) }
38
54
  end
39
55
 
40
56
  def verify_name(item = @name)
41
57
  unless item_exists?(item)
42
- puts "Unable to find a recollecter matching '#{item}'"
43
- usage
58
+ puts "**** Unable to find a recollection matching '#{item}'"
59
+ if File.directory?(File.join(@recollect_path, item))
60
+ puts "Here are the contents of that category:"
61
+ list_recollections(item)
62
+ exit
63
+ else
64
+ usage
65
+ end
44
66
  end
45
67
  end
46
68
 
47
69
  def item_exists?(item)
48
70
  recollections.find { |e| /#{item}\./ =~ e }
49
71
  end
50
-
72
+
51
73
  def write_file
52
- `#{ENV['EDITOR']} #{File.join(@recollect_path, @name) + '.txt'}`
74
+ fullPath = File.join(@recollect_path, @name) + '.txt'
75
+ subdir = File.dirname(fullPath)
76
+ FileUtils.mkdir_p(subdir) unless subdir == '.'
77
+ `#{ENV['EDITOR']} #{fullPath}`
53
78
  end
54
79
 
55
- def list_recollections
80
+ def list_recollections(local_name = @name)
81
+ location = @recollect_path
82
+ location = File.join(@recollect_path, local_name) unless local_name.nil?
56
83
  puts "Available recollections:\n#{@separator}"
57
- puts recollection_names.map { |r| ' ' + r }
84
+ puts recollection_names(location).map { |r| ' ' + r }
58
85
  end
59
86
 
60
87
  def new_recollection
@@ -70,13 +97,23 @@ module Recollect
70
97
 
71
98
  def remove_recollection
72
99
  verify_name
73
- File.delete(File.join(@recollect_path, @name) + '.txt') if confirm?
100
+ if confirm?
101
+ File.delete(File.join(@recollect_path, @name) + '.txt')
102
+ cleanup_path(File.dirname(File.join(@recollect_path, @name)))
103
+ end
104
+ end
105
+
106
+ def cleanup_path(path)
107
+ if path != @recollect_path && Dir["#{path}/*"].empty?
108
+ debug "removing #{path}..."
109
+ FileUtils.rmdir(path)
110
+ cleanup_path(File.dirname(path))
111
+ end
74
112
  end
75
113
 
76
114
  def print_recollection
77
115
  verify_name(@action)
78
116
  puts @separator
79
- #puts `cat #{File.join(@recollect_path, @action) + '.*'}`
80
117
  File.open(File.join(@recollect_path, @action) + '.txt', 'r') do |f|
81
118
  f.each_line do |line|
82
119
  puts line
@@ -1,3 +1,3 @@
1
1
  module Recollect
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recollect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Poland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2017-04-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Storage, Management and Retrieval of things you'd like to remember (recollect).
14
14
  email: recollect@tylerpoland.com