-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbm.rb
executable file
·51 lines (39 loc) · 952 Bytes
/
bm.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
require 'require_all'
require_all("#{__dir__}/lib")
@reserved_words = %w[add search ls list edit rm remove delete]
@bookmark_hash = get_hash
@debug = @bookmark_hash['debug']
puts "Retrieved bookmark hash: #{@bookmark_hash}" if @debug
puts "Arguments: #{ARGV.inspect}" if @debug
if ARGV.size > 1 and ARGV[1]
case ARGV[0]
when 'add'
write_hash if add_url(ARGV[1], ARGV[2..-1])
when 'search'
search_hash(ARGV[1])
when 'rm', 'remove', 'delete'
if ARGV[1].numeric?
write_hash if remove_url(ARGV[1].to_i)
end
else
puts "You haven't entered a recognized command! Try `bm help` for more info."
end
elsif ARGV.size == 1
case ARGV[0]
when 'list', 'ls'
dump_hash if @debug
list_bookmarks
when 'help'
puts_help
else
if ARGV[0].numeric?
open_url_from_index(ARGV[0].to_i)
else
search_and_open(ARGV[0])
end
end
else
puts_banner
list_bookmarks
end