open 0.1.30

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5e4eff5815591683e6976282591579cd498be53e5b2c2159a0126b636a98eef0
4
+ data.tar.gz: d48d7c9749e89819b821ae9de54e7e8630025415a82294dcafbb9052361aa67b
5
+ SHA512:
6
+ metadata.gz: be4686662a3c32e3db742e02179f846ca7fd4a8b1c8c0f9e17be69feec48a9292643411795a35245490850205fc2401b9057ddb163dd8454f0da15c247f6417b
7
+ data.tar.gz: 5047cc0c99fea50c40951f04977358f5e39795054b9bbe4eecb55c001bd3ca75210a65c1de89bd8c29ae5b5b1d780e21a5e327bc5db88ff293313ca9c9504729
data/README.md ADDED
@@ -0,0 +1,312 @@
1
+ [![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
2
+ [![forthebadge](https://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
3
+ [![Gem Version](https://badge.fury.io/rb/open.svg)](https://badge.fury.io/rb/open)
4
+
5
+ This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">16.05.2023</span> (dd.mm.yyyy notation), at <span style="color: steelblue; font-weight: bold">15:26:58</span> o'clock.
6
+
7
+ ## History of this project
8
+
9
+ In the past I used separate projects / gems, such as **OpenInEditor** or
10
+ **OpenInBrowser**, to open files via my favourite editor, or to open
11
+ remote URLs via my favourite browser.
12
+
13
+ Additionally I also had more code aggregated in **roebe/classes/open/**.
14
+
15
+ This slightly confusing situation accrued over the years, from 2010 to 2021
16
+ or so.
17
+
18
+ In early **September 2021** I reconsidered the old approach.
19
+
20
+ I wanted to not only clean up the old code base, making it more flexible
21
+ as well in the process, but **add a new API** such as:
22
+
23
+ Open.in_editor('/home/foobar.md')
24
+ Open.in_editor(this_file: '/home/foobar.md')
25
+
26
+ As well as:
27
+
28
+ Open.in_browser(url: 'google.de', browser: 'firefox')
29
+
30
+ That way we can 'think' of "Open" first, and then simply call
31
+ the method name that we want to use. On the commandline we can
32
+ still do:
33
+
34
+ open_in_editor foobar.rb
35
+ open_in_browser google.de
36
+
37
+ ## Layout of the project's structure
38
+
39
+ This subsection will not include all details, but may serve as a slight
40
+ introduction to how the project is layout.
41
+
42
+ Most of the constants will reside under **open/constants/constants.rb**.
43
+
44
+ Toplevel-methods can be found under **open/toplevel_code/** for the
45
+ most part. This may be ignored by some classes if they add
46
+ toplevel-methods; in that case the toplevel may be modified by such
47
+ a class, and **can subsequently be found in that .rb file where the
48
+ class is defined** (or the directory, if this class is split up
49
+ into several different .rb files).
50
+
51
+ So, for instance, **class Open::Browser** may define a toplevel
52
+ method called **Open.in_browser()**. You can also **grep** (on Linux)
53
+ for where the source code resides specifically, of course.
54
+
55
+ ## Optional dependencies in this project
56
+
57
+ Officially there are no hardcoded dependencies in this project.
58
+
59
+ However had, you are encouraged to install various gems, such as:
60
+
61
+ - colours
62
+ - convert_global_env
63
+ - beautiful_url
64
+ - opn
65
+
66
+ These may enhance the ruby code used in this project.
67
+
68
+ I highly recommend to install the **colours** gem, but ultimately
69
+ the code in this project is written deliberately in a manner to
70
+ make all these add-ons optional, so this is entirely up to you
71
+ in the end.
72
+
73
+ ## class Open::InEditor
74
+
75
+ This class can be used for **opening a (local) file via the editor**.
76
+
77
+ To open a local file via the open-gem, do:
78
+
79
+ require 'open'
80
+
81
+ Open.in_editor('FILE_PATH_GOES_IN_HERE')
82
+ Open.in_editor('/home/x/programming/ruby/src/open/open.gemspec')
83
+
84
+ ## class Open::InBrowser
85
+
86
+ This class can be used for opening a remote URL via your
87
+ favourite **browser**.
88
+
89
+ Upon requiring the main class, the method called:
90
+
91
+ open_in_browser()
92
+
93
+ will be defined as well, to simplify working with the
94
+ class.
95
+
96
+ To specify a particular **port**, use this variant:
97
+
98
+ Open.open_in_browser(port: 8080)
99
+
100
+ This is equivalent to this variant here:
101
+
102
+ PORT_TO_USE = 8080
103
+ Open.in_browser(with_localhost: PORT_TO_USE)
104
+
105
+ So **different keywords** can be used, however your brain prefers
106
+ this or that variant.
107
+
108
+ In **February 2022** I discovered the **launchy** gem. This gem
109
+ can be used to open a remote URL via your favourite browser
110
+ too. Since that is a rather neat functionality to have, I
111
+ decided to integrate this as an optional API into the
112
+ **open** gem as well.
113
+
114
+ Open.open_in_browser(port: 8080, use_launchy: true)
115
+ # or this variant
116
+ Open.open_in_browser(port: 8080) { :use_launchy }
117
+
118
+ Note that in order for this to work, e. g. to use **:use_launchy**
119
+ such as shown by the last example, you need to have the launchy
120
+ gem installed, logically.
121
+
122
+ On windows you can open a remote URL via firefox in the following
123
+ manner:
124
+
125
+ start firefox website_here
126
+ start firefox blog.fefe.de
127
+ start firefox www.howtogeek.com
128
+ start firefox -new-tab www.howtogeek.com
129
+
130
+ In particular the latter variant can be used as-is via
131
+ cmd.exe. You can also pass the **/k** flag to spawn a
132
+ new cmd.exe, on windows. Before knowing that I used
133
+ the system() approach passing the path to firefox.exe,
134
+ but that did not work. Via **start**, though, it does
135
+ indeed work.
136
+
137
+ If you want to find out what the currently used browser
138
+ is, simply issue <b>the following command</b>:
139
+
140
+ open --browser?
141
+
142
+ ## class Open::LastUrl
143
+
144
+ This small class can be used to specifically open the content
145
+ of the xorg-buffer via the browser.
146
+
147
+ ## class Open::WithDelay
148
+
149
+ You can open files via a <b>delay</b>, through class **Open::WithDelay**.
150
+
151
+ You can specify a delay via:
152
+
153
+ openwithdelay 3
154
+
155
+ Or via the method:
156
+
157
+ .set_use_this_delay()
158
+ .set_use_this_delay(3)
159
+ .set_use_this_delay(0.5)
160
+
161
+ Why may this be necessary? My old editor (called bluefish) has had
162
+ problems batch-opening many files, so I needed a delay. With a delay
163
+ in place the problem I saw went away. So this was mostly 'workaround'
164
+ code.
165
+
166
+ ## Changing to a different default editor and browser
167
+
168
+ In **November 2021** I realized that we need a way to more
169
+ easily switch between the default main editor and the
170
+ default main browser. For instance, I abandoned palemoon,
171
+ so I needed to use firefox quickly.
172
+
173
+ The old code had hardcoded calls to **palemoon**, which was
174
+ not very elegant, and made changes to the code harder
175
+ naturally.
176
+
177
+ Thus <b>two new yaml files</b> were added to the gem:
178
+
179
+ use_this_browser.yml
180
+ use_this_editor.yml
181
+
182
+ Now you can modify these yaml files and use a different
183
+ browser or editor. You can even specify the full path
184
+ to these browsers and it should work fine.
185
+
186
+ In July 2022 I decided to extend this functionality.
187
+
188
+ First, you can now <b>automatically</b> set a new
189
+ browser via the toplevel method
190
+ <b>Open.permanently_use_this_browser()</b>.
191
+
192
+ Simply pass the new browser as name to the method,
193
+ such as:
194
+
195
+ Open.permanently_use_this_browser('thorium') # if you want to use the thorium browser
196
+
197
+ The second argument is optional and allows the user to
198
+ specify another .yml file to use. The default value
199
+ should be fine for most users, though, in perhaps
200
+ 99.9% of the use cases.
201
+
202
+ Note that the **save_file** gem is required for this
203
+ functionality.
204
+
205
+ Note that you can also place a file called
206
+ <b>use_this_browser.yml</b> in your home directory -
207
+ the home directory can be queried via <b>Dir.home</b>.
208
+ This .yml file, should it exist, will be checked
209
+ first. That way you can simply assign a new default
210
+ value without having to modify the internal .yml
211
+ files of this project.
212
+
213
+ ## Finding out the current editor and browser in use
214
+
215
+ Use the following two methods if you wish to find out which
216
+ is the current main editor and the current main browser in use.
217
+
218
+ puts Open.use_which_editor?
219
+ puts Open.use_which_browser? # Or the shorter alias: Open.browser?
220
+
221
+ Both values can be changed for your own use case. For instance,
222
+ if you would like to change the browser to be used, use either
223
+ of the following two methods:
224
+
225
+ Open.set_use_this_browser
226
+ Open.use_this_browser=
227
+
228
+ Currently, as of <b>July 2022</b>, the following browsers have
229
+ been tested and "integrated":
230
+
231
+ firefox
232
+ palemoon
233
+ chromium
234
+ thorium
235
+
236
+ More may be added in the future. Note that "integrated" mostly
237
+ means tested on my home system. Each of these may use a
238
+ slightly different way to open a remote URL in a tab, so
239
+ the syntax has to be adjusted to each browser differently.
240
+
241
+ ## class Open::Base
242
+
243
+ This subsection contains just a few pointers to the class
244
+ called **Open::Base**.
245
+
246
+ The method **.this_file_was_not_found()** can be used to
247
+ designate that a certain file (the input argument to
248
+ that method) could <b>not</b> be found.
249
+
250
+ ## Determining which browser is in use
251
+
252
+ You can use this method to query which browser has been
253
+ assigned to be used for Open:
254
+
255
+ Open.use_which_browser?
256
+
257
+ ## Opening local files when the symbol : is used
258
+
259
+ You can use e. g.
260
+
261
+ open_in_editor :gamebooks
262
+
263
+ To open all files that belong to gamebooks. This is catered to my
264
+ own use cases. You may have to change the .yml file to suit your
265
+ own use cases. I needed this functionality to batch-open a
266
+ "project", based on individual files, so this functionality
267
+ was added in <b>March 2023</b>.
268
+
269
+
270
+ ## Contact information and mandatory 2FA coming up in 2022
271
+
272
+ If your creative mind has ideas and specific suggestions to make this gem
273
+ more useful in general, feel free to drop me an email at any time, via:
274
+
275
+ shevy@inbox.lt
276
+
277
+ Before that email I used an email account at Google gmail, but in **2021** I
278
+ decided to slowly abandon gmail, for various reasons. In order to limit the
279
+ explanation here, allow me to just briefly state that I do not feel as if I
280
+ want to promote any Google service anymore when the user becomes the
281
+ product (such as via data collection by upstream services). I feel this is
282
+ a hugely flawed business model.
283
+
284
+ Do keep in mind that responding to emails may take some time, depending on
285
+ the amount of work I may have at that moment.
286
+
287
+ In <b>2022</b> rubygems.org, or rather the corporate overlords who control the
288
+ rubygems.org infrastructure these days, decided to make 2FA mandatory for every
289
+ gem owner eventually: see
290
+ https://blog.rubygems.org/2022/06/13/making-packages-more-secure.html
291
+
292
+ Mandatory 2FA will eventually be extended to all rubygems.org developers and
293
+ maintainers. As I can not use 2FA, for reasons I will skip explaining here,
294
+ this means that my projects will eventually be taken over by shopify (or,
295
+ correspondingly, whoever effectively controls the rubygems.org ecosystem).
296
+ At that point, I no longer have any control what is done to my projects
297
+ since shopify (respectively those controlling the gems ecosystem) took away
298
+ control here. Not sure at which point ruby became corporate-controlled -
299
+ that was not the case several years ago.
300
+
301
+ Ruby also only allows 2FA users to participate on the issue tracker these
302
+ days:
303
+
304
+ https://bugs.ruby-lang.org/issues/18800
305
+
306
+ (Note that this was changed a few months ago, so the last part is no
307
+ longer valid - it is possible to register again without mandating
308
+ 2FA. I will retain the above notice for a bit longer, though, as I feel
309
+ we should not restrict communication via mandatory authentification
310
+ in general. Fighting spam is a noble goal, but when it also means you
311
+ lock out real human people then this is definitely NOT good.)
312
+
data/bin/nano_open ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'open/nano_open/nano_open.rb'
6
+
7
+ Open::NanoOpen.new(ARGV)
data/bin/open ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'open/open.rb' # Only require the minimal code for this.
6
+
7
+ Open::Open.new(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'open/in_browser/in_browser.rb'
6
+
7
+ open_in_browser(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'open/these_files/these_files.rb'
6
+
7
+ Open.these_files(STDIN.read)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'open/with_delay/with_delay.rb'
6
+
7
+ Open::WithDelay.new(ARGV)
data/doc/README.gen ADDED
@@ -0,0 +1,265 @@
1
+ DEFAULT_HEADER
2
+
3
+ ## History of this project
4
+
5
+ In the past I used separate projects / gems, such as **OpenInEditor** or
6
+ **OpenInBrowser**, to open files via my favourite editor, or to open
7
+ remote URLs via my favourite browser.
8
+
9
+ Additionally I also had more code aggregated in **roebe/classes/open/**.
10
+
11
+ This slightly confusing situation accrued over the years, from 2010 to 2021
12
+ or so.
13
+
14
+ In early **September 2021** I reconsidered the old approach.
15
+
16
+ I wanted to not only clean up the old code base, making it more flexible
17
+ as well in the process, but **add a new API** such as:
18
+
19
+ Open.in_editor('/home/foobar.md')
20
+ Open.in_editor(this_file: '/home/foobar.md')
21
+
22
+ As well as:
23
+
24
+ Open.in_browser(url: 'google.de', browser: 'firefox')
25
+
26
+ That way we can 'think' of "Open" first, and then simply call
27
+ the method name that we want to use. On the commandline we can
28
+ still do:
29
+
30
+ open_in_editor foobar.rb
31
+ open_in_browser google.de
32
+
33
+ ## Layout of the project's structure
34
+
35
+ This subsection will not include all details, but may serve as a slight
36
+ introduction to how the project is layout.
37
+
38
+ Most of the constants will reside under **open/constants/constants.rb**.
39
+
40
+ Toplevel-methods can be found under **open/toplevel_code/** for the
41
+ most part. This may be ignored by some classes if they add
42
+ toplevel-methods; in that case the toplevel may be modified by such
43
+ a class, and **can subsequently be found in that .rb file where the
44
+ class is defined** (or the directory, if this class is split up
45
+ into several different .rb files).
46
+
47
+ So, for instance, **class Open::Browser** may define a toplevel
48
+ method called **Open.in_browser()**. You can also **grep** (on Linux)
49
+ for where the source code resides specifically, of course.
50
+
51
+ ## Optional dependencies in this project
52
+
53
+ Officially there are no hardcoded dependencies in this project.
54
+
55
+ However had, you are encouraged to install various gems, such as:
56
+
57
+ - colours
58
+ - convert_global_env
59
+ - beautiful_url
60
+ - opn
61
+
62
+ These may enhance the ruby code used in this project.
63
+
64
+ I highly recommend to install the **colours** gem, but ultimately
65
+ the code in this project is written deliberately in a manner to
66
+ make all these add-ons optional, so this is entirely up to you
67
+ in the end.
68
+
69
+ ## class Open::InEditor
70
+
71
+ This class can be used for **opening a (local) file via the editor**.
72
+
73
+ To open a local file via the open-gem, do:
74
+
75
+ require 'open'
76
+
77
+ Open.in_editor('FILE_PATH_GOES_IN_HERE')
78
+ Open.in_editor('/home/x/programming/ruby/src/open/open.gemspec')
79
+
80
+ ## class Open::InBrowser
81
+
82
+ This class can be used for opening a remote URL via your
83
+ favourite **browser**.
84
+
85
+ Upon requiring the main class, the method called:
86
+
87
+ open_in_browser()
88
+
89
+ will be defined as well, to simplify working with the
90
+ class.
91
+
92
+ To specify a particular **port**, use this variant:
93
+
94
+ Open.open_in_browser(port: 8080)
95
+
96
+ This is equivalent to this variant here:
97
+
98
+ PORT_TO_USE = 8080
99
+ Open.in_browser(with_localhost: PORT_TO_USE)
100
+
101
+ So **different keywords** can be used, however your brain prefers
102
+ this or that variant.
103
+
104
+ In **February 2022** I discovered the **launchy** gem. This gem
105
+ can be used to open a remote URL via your favourite browser
106
+ too. Since that is a rather neat functionality to have, I
107
+ decided to integrate this as an optional API into the
108
+ **open** gem as well.
109
+
110
+ Open.open_in_browser(port: 8080, use_launchy: true)
111
+ # or this variant
112
+ Open.open_in_browser(port: 8080) { :use_launchy }
113
+
114
+ Note that in order for this to work, e. g. to use **:use_launchy**
115
+ such as shown by the last example, you need to have the launchy
116
+ gem installed, logically.
117
+
118
+ On windows you can open a remote URL via firefox in the following
119
+ manner:
120
+
121
+ start firefox website_here
122
+ start firefox blog.fefe.de
123
+ start firefox www.howtogeek.com
124
+ start firefox -new-tab www.howtogeek.com
125
+
126
+ In particular the latter variant can be used as-is via
127
+ cmd.exe. You can also pass the **/k** flag to spawn a
128
+ new cmd.exe, on windows. Before knowing that I used
129
+ the system() approach passing the path to firefox.exe,
130
+ but that did not work. Via **start**, though, it does
131
+ indeed work.
132
+
133
+ If you want to find out what the currently used browser
134
+ is, simply issue <b>the following command</b>:
135
+
136
+ open --browser?
137
+
138
+ ## class Open::LastUrl
139
+
140
+ This small class can be used to specifically open the content
141
+ of the xorg-buffer via the browser.
142
+
143
+ ## class Open::WithDelay
144
+
145
+ You can open files via a <b>delay</b>, through class **Open::WithDelay**.
146
+
147
+ You can specify a delay via:
148
+
149
+ openwithdelay 3
150
+
151
+ Or via the method:
152
+
153
+ .set_use_this_delay()
154
+ .set_use_this_delay(3)
155
+ .set_use_this_delay(0.5)
156
+
157
+ Why may this be necessary? My old editor (called bluefish) has had
158
+ problems batch-opening many files, so I needed a delay. With a delay
159
+ in place the problem I saw went away. So this was mostly 'workaround'
160
+ code.
161
+
162
+ ## Changing to a different default editor and browser
163
+
164
+ In **November 2021** I realized that we need a way to more
165
+ easily switch between the default main editor and the
166
+ default main browser. For instance, I abandoned palemoon,
167
+ so I needed to use firefox quickly.
168
+
169
+ The old code had hardcoded calls to **palemoon**, which was
170
+ not very elegant, and made changes to the code harder
171
+ naturally.
172
+
173
+ Thus <b>two new yaml files</b> were added to the gem:
174
+
175
+ use_this_browser.yml
176
+ use_this_editor.yml
177
+
178
+ Now you can modify these yaml files and use a different
179
+ browser or editor. You can even specify the full path
180
+ to these browsers and it should work fine.
181
+
182
+ In July 2022 I decided to extend this functionality.
183
+
184
+ First, you can now <b>automatically</b> set a new
185
+ browser via the toplevel method
186
+ <b>Open.permanently_use_this_browser()</b>.
187
+
188
+ Simply pass the new browser as name to the method,
189
+ such as:
190
+
191
+ Open.permanently_use_this_browser('thorium') # if you want to use the thorium browser
192
+
193
+ The second argument is optional and allows the user to
194
+ specify another .yml file to use. The default value
195
+ should be fine for most users, though, in perhaps
196
+ 99.9% of the use cases.
197
+
198
+ Note that the **save_file** gem is required for this
199
+ functionality.
200
+
201
+ Note that you can also place a file called
202
+ <b>use_this_browser.yml</b> in your home directory -
203
+ the home directory can be queried via <b>Dir.home</b>.
204
+ This .yml file, should it exist, will be checked
205
+ first. That way you can simply assign a new default
206
+ value without having to modify the internal .yml
207
+ files of this project.
208
+
209
+ ## Finding out the current editor and browser in use
210
+
211
+ Use the following two methods if you wish to find out which
212
+ is the current main editor and the current main browser in use.
213
+
214
+ puts Open.use_which_editor?
215
+ puts Open.use_which_browser? # Or the shorter alias: Open.browser?
216
+
217
+ Both values can be changed for your own use case. For instance,
218
+ if you would like to change the browser to be used, use either
219
+ of the following two methods:
220
+
221
+ Open.set_use_this_browser
222
+ Open.use_this_browser=
223
+
224
+ Currently, as of <b>July 2022</b>, the following browsers have
225
+ been tested and "integrated":
226
+
227
+ firefox
228
+ palemoon
229
+ chromium
230
+ thorium
231
+
232
+ More may be added in the future. Note that "integrated" mostly
233
+ means tested on my home system. Each of these may use a
234
+ slightly different way to open a remote URL in a tab, so
235
+ the syntax has to be adjusted to each browser differently.
236
+
237
+ ## class Open::Base
238
+
239
+ This subsection contains just a few pointers to the class
240
+ called **Open::Base**.
241
+
242
+ The method **.this_file_was_not_found()** can be used to
243
+ designate that a certain file (the input argument to
244
+ that method) could <b>not</b> be found.
245
+
246
+ ## Determining which browser is in use
247
+
248
+ You can use this method to query which browser has been
249
+ assigned to be used for Open:
250
+
251
+ Open.use_which_browser?
252
+
253
+ ## Opening local files when the symbol : is used
254
+
255
+ You can use e. g.
256
+
257
+ open_in_editor :gamebooks
258
+
259
+ To open all files that belong to gamebooks. This is catered to my
260
+ own use cases. You may have to change the .yml file to suit your
261
+ own use cases. I needed this functionality to batch-open a
262
+ "project", based on individual files, so this functionality
263
+ was added in <b>March 2023</b>.
264
+
265
+ ADD_CONTACT_INFORMATION