Module: Noty

Defined in:
lib/noty.rb,
lib/noty/ui.rb,
lib/noty/helpers.rb,
lib/noty/storage.rb,
lib/noty/version.rb,
lib/noty/models/snippet.rb,
lib/noty/models/bookmark.rb,
lib/noty/services/search.rb

Defined Under Namespace

Modules: Helpers, Services, UI Classes: Bookmark, Snippet

Constant Summary collapse

STORAGE_PATH =
File.expand_path(ENV['NOTES_PATH'] || '~/.notes')
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.bookmarkObject



55
56
57
58
59
# File 'lib/noty.rb', line 55

def bookmark
  bm = Bookmark.from_url(ARGV.first)
  bm.save
  bm.edit
end

.helpObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/noty.rb', line 15

def help
  version
  puts <<-EOT
Snippets and bookmarks manager.

Usage:
noty [command|inputs]

Commands:
help, -h, --help : print this message
version, -v, --version : print noty version

Input types:
url: e.g "http://www.example.com", add URL as a bookmark file
keyword: search bookmarks and perform action on it, a single word of multiple words or regex, it is passed to "ag silver searcher"
snippet text: any multiword text, it will search first if no files contain this text you'll be asked if you want to create a snippet for it
EOT
end

.searchObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/noty.rb', line 34

def search
  keyword = ARGV.join ' '
  result = Services.search(keyword)

  if !result.empty?
    UI.choose result
  elsif keyword.include?(' ')
    choice = ask 'Do you want to save it as a snippet? [y/N]: '
    snippet if choice.casecmp 'y'
  end
end

.snippetObject



46
47
48
49
50
51
52
53
# File 'lib/noty.rb', line 46

def snippet
  content = ARGV.join ' '
  path = File.join(Noty::STORAGE_PATH, Time.now.to_i.to_s + '.snippet')

  snippet = Snippet.new(path)
  snippet.content = content
  snippet.save
end

.versionObject



11
12
13
# File 'lib/noty.rb', line 11

def version
  puts "Noty version #{VERSION}"
end