module Til
Constants
- VERSION
Public Class Methods
config_settings_file_and_notes_repo()
click to toggle source
# File lib/til.rb, line 14 def self.config_settings_file_and_notes_repo Initializer.new.create_settings_file Initializer.new.create_notes_directory puts "Your settings file is at `#{Settings.load.settings_file_path}`. Your notes are at `#{Settings.load.directory}`." end
edit_file(search_term, options)
click to toggle source
# File lib/til.rb, line 57 def self.edit_file(search_term, options) if options[:last] system(Settings.load.editor, Directory.root.notes.most_recent.path) return end matches = Til.search_results_for(search_term) if matches.length < 1 puts "no matches" else system(Settings.load.editor, matches.filter.path) end end
list_all_notes()
click to toggle source
# File lib/til.rb, line 143 def self.list_all_notes notes = Directory.root.notes.sort_by_modified_time puts "Listing all #{notes.length} notes: " NoteDisplayer.new(notes).list end
list_notes_in(subject)
click to toggle source
# File lib/til.rb, line 120 def self.list_notes_in(subject) notes = Directory.for(subject).notes if notes.empty? puts "You don't seem to have any notes on that subject!" puts "You DO have notes on the following subjects:" Til.list_subjects else NoteDisplayer.new(notes).list end end
list_subjects(list_style=:bullet_points)
click to toggle source
# File lib/til.rb, line 131 def self.list_subjects(list_style=:bullet_points) subjects = Array.new Dir.glob(Settings.load.directory + "/*").each do |dirname| subjects.push dirname.gsub(Settings.load.directory + "/", "") end if list_style==:flat puts subjects.join(", ") else subjects.each {|subject| puts "- #{subject}"} end end
new_note(subject, title)
click to toggle source
# File lib/til.rb, line 24 def self.new_note(subject, title) if_unmodified = Proc.new do puts "You didn't write anything, so a note wasn't created.".red return end if_modified = Proc.new do |note_content| subject_path = Settings.load.directory + "/#{subject.downcase}" if !File.directory? subject_path FileUtils.mkdir(subject_path) puts "Created a new directory for #{subject.downcase}" end file_path = subject_path + "/" + title.downcase.gsub(" ", "-") + ".md" write_file = File.new(file_path, "w") write_file.write note_content write_file.close puts "You created a new note in ".green + subject.green.bold + ". `til last` to read it, or `til edit --last` to edit it.".green end NoteWriter.new(title).call(if_modified, if_unmodified) end
open_github_page_for_repo()
click to toggle source
# File lib/til.rb, line 79 def self.open_github_page_for_repo if !Settings.load.github_repo.nil? system("open https://www.github.com/#{Settings.github_repo}") else begin repo = %x|git --git-dir=#{Settings.load.directory}/.git --work-tree=#{Settings.load.directory} remote -v|.scan(/:(.*).git/).flatten.first system("open https://www.github.com/#{repo}") rescue puts "You don't appear to have a GitHub remote repository for your notes.".red end end end
print(note)
click to toggle source
# File lib/til.rb, line 149 def self.print note NoteDisplayer.new(note).print end
print_all_notes()
click to toggle source
# File lib/til.rb, line 110 def self.print_all_notes notes = Directory.root.notes NoteDisplayer.new(notes).print end
print_all_notes_in(subject)
click to toggle source
# File lib/til.rb, line 115 def self.print_all_notes_in(subject) notes = Directory.for(subject).notes NoteDisplayer.new(notes).print end
print_most_recent_note(quantity)
click to toggle source
# File lib/til.rb, line 105 def self.print_most_recent_note quantity notes = Directory.root.notes.sort_by_modified_time.take(quantity) notes.each {|note| NoteDisplayer.new(note).print} end
print_working_directory()
click to toggle source
# File lib/til.rb, line 20 def self.print_working_directory puts Settings.load.directory end
remove_file(search_term)
click to toggle source
# File lib/til.rb, line 70 def self.remove_file(search_term) matches = Til.search_results_for(search_term) if matches.length < 1 puts "no matches" else NoteDeleter.new(matches.filter).delete end end
run_ag_command(*args)
click to toggle source
# File lib/til.rb, line 101 def self.run_ag_command(*args) system("ag #{args.join(" ")} #{Settings.load.directory}") end
run_git_command(*args)
click to toggle source
# File lib/til.rb, line 93 def self.run_git_command(*args) system("git --git-dir=#{Settings.load.directory}/.git --work-tree=#{Settings.load.directory} #{args.join(" ")}") end
run_grep_command(*args)
click to toggle source
# File lib/til.rb, line 97 def self.run_grep_command(*args) system("grep -r #{args.join(" ")} #{Settings.load.directory}") end
search_results_for(search_terms)
click to toggle source
# File lib/til.rb, line 47 def self.search_results_for(search_terms) matches = NoteList.new Directory.root.notes.each do |note| if note.title.downcase.include?(search_terms.downcase) matches.push note end end matches end