booker 0.4 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ede393f061fc758e36d7ab8a09d414dbee51559c
4
- data.tar.gz: 3390c07e38358019217b79fa4d73560a0e7941de
3
+ metadata.gz: d252a9a7c36783822c6fb4d7aeb4e92bc4a84e0a
4
+ data.tar.gz: bf2315269a359f08bec9c34631efdd58980e39e9
5
5
  SHA512:
6
- metadata.gz: 299fda2e34de05e4ce9501f6dcb62fc748563e639ba775465bb6f686048063b3dabd28070876b445a3071c0677c08a9d8b55600dff8c36bf2922ab317fecaa56
7
- data.tar.gz: 2eb7dfde1026069de99d1069c6e1eb112d02bb6318396b70b27ce215ceae451104c36f7b0b71224d99aca449de9f5f279f67333909264392767a7be80e9e3dd9
6
+ metadata.gz: a954524d07453dd2fdec24744211b1e4037581b822706dd4094001f06bc3175830453757abca42c73059a9a91e27abbb034e3d55426e90b0a886fb560995f20a
7
+ data.tar.gz: ca595683fc4e2d57c6308fada77b2d7ee430415190c8b680af2edbd7a653ac64f81be3bd956368e1b7114a3ae2be471e6a52843f0863dcaa5be3d001357e4bb5
File without changes
@@ -1,7 +1,7 @@
1
- # parse web's command line args
1
+ # parse booker's command line args
2
2
 
3
3
 
4
- VERSION = "0.4"
4
+ VERSION = "0.5"
5
5
 
6
6
 
7
7
  require 'yaml'
@@ -21,113 +21,110 @@ class Booker
21
21
  parse args
22
22
  end
23
23
 
24
- def pexit(msg, sig)
25
- puts msg
26
- exit sig
27
- end
28
-
29
- def helper
30
- pexit HELP_BANNER, 0
31
- end
32
-
33
- def openweb(url)
34
- system(browse + wrap(url))
35
- end
36
-
37
24
  def parse(args)
38
25
  # no args given, show help
39
26
  helper if args.none?
40
27
 
41
28
  # if arg starts with hyphen, parse option
42
- parse_opt args if /^-.*/.match(args[0])
29
+ parse_opt args if /^-.*/.match(args.first)
43
30
 
44
31
  # interpret command
45
- browsearg = args[0]
32
+ browsearg = args.first
46
33
 
47
34
  if browsearg.match(/^[0-9]/) # bookmark
48
- bm = Bookmarks.new('')
49
- url = bm.bookmark_url(browsearg)
50
- pexit "Failure:".red + " bookmark #{browsearg} not found", 1 if url.nil?
51
- puts 'opening bookmark ' + url + '...'
52
- openweb(wrap(url))
35
+ open_bookmark args
53
36
  elsif domain.match(browsearg) # website
54
37
  puts 'opening website ' + browsearg + '...'
55
38
  openweb(wrap(prep(browsearg)))
56
39
  else
57
40
  allargs = wrap(args.join(' '))
58
- puts 'searching ' + allargs + '...'
59
- search = BConfig.new.searcher
60
- openweb(Shellwords.escape(search + allargs))
41
+ open_search allargs
61
42
  end
62
43
  end
63
44
 
45
+ def pexit(msg, sig)
46
+ puts msg
47
+ exit sig
48
+ end
49
+
50
+ def helper
51
+ pexit HELP_BANNER, 0
52
+ end
53
+
54
+ def version
55
+ pexit VERSION, 0
56
+ end
57
+
58
+ def openweb(url)
59
+ system(browse + wrap(url))
60
+ end
61
+
62
+ # an array of ints, as bookmark ids
63
+ def open_bookmark(bm)
64
+ id = bm.shift
65
+ url = Bookmarks.new.bookmark_url(id)
66
+ pexit "Failure:".red + " bookmark #{id} not found", 1 if url.nil?
67
+ puts 'opening bookmark ' + url + '...'
68
+ openweb(wrap(url))
69
+ open_bookmark bm unless bm.empty?
70
+ end
71
+
72
+ def open_search(term)
73
+ puts 'searching ' + term + '...'
74
+ search = BConfig.new.searcher
75
+ openweb(Shellwords.escape(search + term))
76
+ end
77
+
78
+ # parse and execute any command line options
64
79
  def parse_opt(args)
65
80
  valid_opts = %w{--version -v --install -i --help -h
66
81
  --complete -c --bookmark -b --search -s}
67
82
 
68
- nextarg = args[0]
69
- errormsg = "Error: ".red + "unrecognized option #{nextarg}"
83
+ nextarg = args.shift
84
+ errormsg = 'Error: '.red + "unrecognized option #{nextarg}"
70
85
  pexit errormsg, 1 if ! (valid_opts.include? nextarg)
71
86
 
72
87
  # doing forced bookmarking
73
- if args[0] == "--bookmark" || args[0] == "-b"
74
- bm = Bookmarks.new('')
75
- id = args[1]
76
- if id
77
- url = bm.bookmark_url(id)
78
- puts 'opening ' + url + '...'
79
- system(browse + wrap(url))
80
- exit 0
88
+ if nextarg == '--bookmark' || nextarg == '-b'
89
+ if args.first.nil?
90
+ pexit 'Error: '.red + 'booker --bookmark expects bookmark id', 1
81
91
  else
82
- pexit 'Error: '.red +
83
- 'web --bookmark expects bookmark id', 1
92
+ open_bookmark args
84
93
  end
85
94
  end
86
95
 
87
96
  # doing autocompletion
88
- if args[0] == "--complete" || args[0] == "-c"
89
- args.shift # remove flag
97
+ if nextarg == '--complete' || nextarg == '-c'
90
98
  allargs = args.join(' ')
91
99
  bm = Bookmarks.new(allargs)
92
100
  bm.autocomplete
93
- exit 0
94
101
  end
95
102
 
96
103
  # doing installation
97
- if args[0] == "--install" || args[0] == "-i"
98
- args.shift # remove flag
99
- if args.length > 0
104
+ if nextarg == '--install' || nextarg == '-i'
105
+ if !args.empty?
100
106
  install(args)
101
107
  else
102
- pexit 'Error: '.red +
103
- "web --install expects arguments: [completion, bookmarks, config]", 1
108
+ err = 'booker --install expects arguments: [completion, bookmarks, config]'
109
+ pexit 'Error: '.red + err, 1
104
110
  end
105
111
  end
106
112
 
107
- # needs some help
108
- if args[0] == "--help" || args[0] == "-h"
109
- helper
110
- end
111
-
112
113
  # doing forced searching
113
- if args[0] == "--search" || args[0] == "-s"
114
- args.shift # remove flag
114
+ if nextarg == '--search' || nextarg == '-s'
115
+ pexit '--search requires an argument', 1 if args.empty?
115
116
  allargs = args.join(' ')
116
- if allargs == ""
117
- pexit "--search requires an argument", 1
118
- else
119
- puts 'searching ' + allargs + '...'
120
- search = BConfig.new.searcher
121
- openweb(Shellwords.escape(search + allargs))
122
- exit 0
123
- end
117
+ open_search allargs
124
118
  end
125
119
 
126
120
  # print version information
127
- if args[0] == "--version" || args[0] == "-v"
128
- pexit VERSION, 0
129
- end
130
- end # parse opt
121
+ version if nextarg == '--version' || nextarg == '-v'
122
+
123
+ # needs some help
124
+ helper if nextarg == '--help' || nextarg == '-h'
125
+
126
+ exit 0 # dont parse_arg
127
+ end # parse_opt
131
128
 
132
129
  def install(args)
133
130
  target = args.shift
@@ -158,14 +155,14 @@ class Booker
158
155
  # determine where to install completion function
159
156
  fpath.each do |fp|
160
157
  begin
161
- File.open(fp + "/_web", 'w') {|f| f.write(COMPLETION) }
162
- system "zsh -c 'autoload -U _web'"
158
+ File.open(fp + "/_booker", 'w') {|f| f.write(COMPLETION) }
159
+ system "zsh -c 'autoload -U _booker'"
163
160
  puts "Success: ".grn +
164
161
  "installed zsh autocompletion in #{fp}"
165
162
  break # if this works, don't try anymore
166
163
  rescue
167
164
  puts "Failure: ".red +
168
- "could not write ZSH completion _web script to $fpath (#{fp})"
165
+ "could not write ZSH completion _booker script to $fpath (#{fp})"
169
166
  end
170
167
  end
171
168
  end
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  # try to read bookmarks
35
35
  class Bookmarks
36
- def initialize(search_term)
36
+ def initialize(search_term = '')
37
37
  @conf = BConfig.new
38
38
  begin
39
39
  local_bookmarks = JSON.parse(open(@conf.bookmarks).read)
@@ -42,7 +42,7 @@ class Bookmarks
42
42
  puts "Warning: ".yel +
43
43
  "Chrome JSON Bookmarks not found."
44
44
  puts "Suggest: ".grn +
45
- "web --install bookmarks"
45
+ "booker --install bookmarks"
46
46
  @chrome_bookmarks = {}
47
47
  end
48
48
 
@@ -32,7 +32,7 @@ module Browser
32
32
  end
33
33
 
34
34
  def domain
35
- /.*(io|com|web|net|org|gov|edu)(\/.*)?$/i
35
+ /.*(io|com|web|net|org|gov|edu|xyz)(\/.*)?$/i
36
36
  end
37
37
 
38
38
  # helper methods
@@ -62,7 +62,7 @@ class BConfig
62
62
  readyaml = read(YAMLCONF)
63
63
  default_config = {
64
64
  :browser => 'open ',
65
- :searcher => "https://duckduckgo.com/?q=",
65
+ :searcher => "https://google.com/?q=",
66
66
  :bookmarks => HOME +
67
67
  "/Library/Application Support/Google/Chrome/Profile 1/Bookmarks",
68
68
  }
@@ -3,7 +3,7 @@
3
3
 
4
4
  HELP_BANNER = <<-EOS
5
5
  Open browser:
6
- $ web [option] [arguments]
6
+ $ booker [option] [arguments]
7
7
 
8
8
  Main options:
9
9
  --bookmark, -b: explicity open bookmark
@@ -18,17 +18,18 @@ EOS
18
18
 
19
19
 
20
20
  DEF_CONFIG = <<-EOS
21
- bookmarks: null
22
- searcher: https://duckduckgo.com/?q=
21
+ ---
22
+ :searcher: https://google.com/?q=
23
+ :bookmarks: null
23
24
  EOS
24
25
 
25
26
 
26
27
  COMPLETION = <<-EOS
27
- #compdef web
28
+ #compdef booker
28
29
  #autoload
29
30
 
30
31
 
31
- _web_bookmarks() {
32
+ _booker_bookmarks() {
32
33
  #http://zsh.sourceforge.net/Guide/zshguide06.html#l147
33
34
  setopt glob bareglobqual nullglob rcexpandparam extendedglob automenu
34
35
  unsetopt allexport aliases errexit octalzeroes ksharrays cshnullglob
@@ -36,9 +37,9 @@ _web_bookmarks() {
36
37
  #get chrome bookmarks
37
38
  local -a bookmarks sites search
38
39
 
39
- #grab all CLI args, remove 'web' from start
40
- search=`echo $@ | sed -e '/^web /d'`
41
- sites=`web --complete $search`
40
+ #grab all CLI args, remove 'booker' from start
41
+ search=`echo $@ | sed -e '/^booker /d'`
42
+ sites=`booker --complete $search`
42
43
  bookmarks=("${(f)${sites}}")
43
44
 
44
45
  #terminal colors
@@ -60,7 +61,7 @@ _web_bookmarks() {
60
61
  }
61
62
 
62
63
 
63
- _web() {
64
+ _booker() {
64
65
  compstate[insert]=menu
65
66
  local curcontext state line
66
67
  typeset -A opt_args
@@ -73,29 +74,29 @@ _web() {
73
74
  '(--install)--install[perform installations (bookmarks, completion, config)]'\
74
75
  '(-s)-s[search google for...]'\
75
76
  '(--search)--search[search google for...]'\
76
- '(-h)-h[show web help]'\
77
- '(--help)--help[show web help]'\
77
+ '(-h)-h[show booker help]'\
78
+ '(--help)--help[show booker help]'\
78
79
  '(-v)-v[show version]'\
79
80
  '(--version)--version[show version]'\
80
81
  '*::bookmarks:->bookmarks' && return 0
81
82
 
82
- _web_bookmarks $words
83
+ _booker_bookmarks $words
83
84
  }
84
85
 
85
86
 
86
- _web
87
+ _booker
87
88
  EOS
88
89
 
89
90
 
90
91
  ZSH_SCRIPT = <<-EOS
91
- # load zsh web completions
92
+ # load zsh booker completions
92
93
  install_loc=~/.oh-my-zsh/completions
93
- script=_web
94
+ script=_booker
94
95
 
95
96
  install:
96
- mkdir -vp $(install_loc)
97
- cp -v $(script) $(install_loc)/
97
+ mkdir -vp $(install_loc)
98
+ cp -v $(script) $(install_loc)/
98
99
 
99
100
  uninstall:
100
- rm -v $(install_loc)/$(script)
101
+ rm -v $(install_loc)/$(script)
101
102
  EOS
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: booker
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Warner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-20 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-terminfo
@@ -73,16 +73,16 @@ dependencies:
73
73
  description: |2
74
74
  Select your bookmarks from the command line, by their bookmark id number.
75
75
  ZSH users will be able to tab complete through their matches, similar to
76
- how the autocompletion for `kill` works. If no bookmark is provided, web
77
- will check if the argument is a website and visit it, or search duckduckgo
78
- for the string argument.
76
+ how the autocompletion for `kill` works. If no bookmark is provided, booker
77
+ will check if the argument is a website and visit it, or go to google
78
+ (or your preferred search engine) with the string argument.
79
79
  email: jeremywrnr@gmail.com
80
80
  executables:
81
- - web
81
+ - booker
82
82
  extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
- - bin/web
85
+ - bin/booker
86
86
  - lib/booker.rb
87
87
  - lib/bookmarks.rb
88
88
  - lib/config.rb
@@ -93,9 +93,9 @@ licenses:
93
93
  metadata: {}
94
94
  post_install_message: |2
95
95
  Thank you for installing booker!
96
- To find your bookmarks, run `web -i bookmarks`
97
- To add zsh completion, run `web -i completion`
98
- To see more help, run `web --help`
96
+ To find your bookmarks, run `booker -i bookmarks`
97
+ To add zsh completion, run `booker -i completion`
98
+ To see more help, run `booker --help`
99
99
  rdoc_options: []
100
100
  require_paths:
101
101
  - lib
@@ -111,8 +111,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  requirements: []
113
113
  rubyforge_project:
114
- rubygems_version: 2.4.8
114
+ rubygems_version: 2.5.1
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: CLI parser/selector for google chrome bookmarks
118
118
  test_files: []
119
+ has_rdoc: