Skip to content

Commit

Permalink
Filtering todo files from output
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubujka committed Mar 10, 2012
1 parent 987282c commit 4e9eb39
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 59 deletions.
1 change: 1 addition & 0 deletions cards
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require "stringio"

require "lib/hash.rb"

require "class.rb"
require "cards_helper.rb"
require "dir_mode.rb"
require "file_mode.rb"
Expand Down
63 changes: 9 additions & 54 deletions cards_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def clear
print `clear`
end

def todo_file_pattern
/^[0-9].*/
end

def files_in_pth pth
arr = Dir.entries(pth).select do |v|
!File.directory? fjoin(pth, v) and !(v =='.' || v == '..')
Expand All @@ -44,6 +48,7 @@ def files_in_pth pth
!v.match(/^\./)
end
end

arr
end

Expand Down Expand Up @@ -78,7 +83,6 @@ def pp_list array, label, ret = false
end
io.close_write
r += io.readlines.to_s + "\n"
r += "---------------------\n"
end
end
puts(r) unless(ret)
Expand Down Expand Up @@ -198,8 +202,11 @@ def goto_file_mode file
do_what_i_say_in_file file
end

def _hr
'-----------------------------------------------------'.green
end
def hr
puts '-----------------------------------------------------'.green
puts _hr
end

def nl
Expand Down Expand Up @@ -245,58 +252,6 @@ def get_doc
t
end

class String
def esc
return "''" if self.empty?
str = self.dup
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
str.gsub!(/\n/, "'\n'")
str
end

def cdate
File.ctime(self).strftime('%F')
end

def achieve_status
if(self.content.split("\n")[0] =~ /ACHIEVE:(.*)/)
$1.chomp.to_sym
else
:regular
end
end

def achieve_status= what
c = "ACHIEVE:#{what.to_s}\n" + self.content.sub(/ACHIEVE:(.*)\n/, '')
self.content = c;
end

def basename
File.basename self
end

def dirname
File.dirname self
end

def content
r_file self
end

def content= what
w_file self, what
end

def strip_home
t = self.dup
t[home_dir() + '/'] = ""
t
end

def ex
File.expand_path(self)
end
end

def ob
buffer = StringIO.new
Expand Down
58 changes: 58 additions & 0 deletions class.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class Array
def hrify
self.map(&:chomp).join("\n\n"+_hr+"\n\n").chomp
end
end

class String
def esc
return "''" if self.empty?
str = self.dup
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
str.gsub!(/\n/, "'\n'")
str
end

def cdate
File.ctime(self).strftime('%F')
end

def achieve_status
if(self.content.split("\n")[0] =~ /ACHIEVE:(.*)/)
$1.chomp.to_sym
else
:regular
end
end

def achieve_status= what
c = "ACHIEVE:#{what.to_s}\n" + self.content.sub(/ACHIEVE:(.*)\n/, '')
self.content = c;
end

def basename
File.basename self
end

def dirname
File.dirname self
end

def content
r_file self
end

def content= what
w_file self, what
end

def strip_home
t = self.dup
t[home_dir() + '/'] = ""
t
end

def ex
File.expand_path(self)
end
end
25 changes: 20 additions & 5 deletions dir_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,35 @@ def show_current_dir_line dir

def default_dir_action dir
dirs = dirs_in_pth(dir)
content = []
colored_dirs = dirs.map do |v|
pth = "#{dir}/#{v}"
(v + " (" + `find #{pth.esc} -type f | wc -l`.chomp + ")")
end
t = pp_list(colored_dirs, 'Dirs', true).gsub(/\([0-9]+\)/){|v| v.blue}.chomp
puts t
content.push pp_list(colored_dirs, 'Dirs', true).gsub(/\([0-9]+\)/){|v| v.blue}.chomp

if t = pp_list(files_in_pth(dir), "Files", true).chomp
puts t
files = files_in_pth(dir)
files_cnt = files.size
if rc(:hide_todo_files)
files.select! do |v|
!v.match(todo_file_pattern)
end
end

if(files_cnt != files.size)
content.push "Todo: " + (files_cnt - files.size).to_s.green + ' tasks'
end

if t = pp_list(files, "Files", true).chomp
content.push t
end

puts content.hrify
end

def do_what_i_say_in_dir dir
print "What to do:".green
nl
print "What to do: ".green
print_flash_messages

if cmd = get_cmd_from_user
Expand Down
1 change: 1 addition & 0 deletions rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ default_dir: ~/gtd
hide_empty_dirs: true
hide_dotted_dirs: true
hide_dotted_files: true
hide_todo_files: true
cache: false
bind:
t: dbg_show_env
Expand Down

0 comments on commit 4e9eb39

Please sign in to comment.