open 0.1.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of open might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6e97b4bf7fefbde0c67eeb92997a65094d055811f5de61b49267c35fcef94bbc
4
+ data.tar.gz: e98c638baed4bc5746a14e81a79679a83b2a6b664604d3a64cd1387b1ac47458
5
+ SHA512:
6
+ metadata.gz: ca4aacf66939ed31a9dfc0ade920c91469f62e545d2680a20233dc90dfb3bcd7d0b4c841d6f9a43cae94e0b1a1c53bfcb56850d6a1e2ed92c8157f1df828ae98
7
+ data.tar.gz: e7356840e738c0549e10a4f18950fd7df205146438376c49810c88ceaefd20b4d62836eb3b01ffcf4763144feea951235376b75ec6462c5fd0978c367d9862fc
data/README.md ADDED
@@ -0,0 +1,181 @@
1
+ [![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
2
+ [![forthebadge](http://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
+ ## History of this project
6
+
7
+ In the past I used separate projects / gems, such as **OpenInEditor** or
8
+ **OpenInBrowser**, to open files via my favourite editor, or to open
9
+ remote URLs via my favourite browser.
10
+
11
+ Additionally I also had more code aggregated in **roebe/classes/open/**.
12
+
13
+ This slightly confusing situation accrued over the years, from 2010 to 2021
14
+ or so.
15
+
16
+ In early **September 2021** I reconsidered the old approach.
17
+
18
+ I wanted to not only clean up the old code base, making it more flexible
19
+ as well in the process, but **add a new API** such as:
20
+
21
+ Open.in_editor('/home/foobar.md')
22
+ Open.in_editor(this_file: '/home/foobar.md')
23
+
24
+ As well as:
25
+
26
+ Open.in_browser(url: 'google.de', browser: 'firefox')
27
+
28
+ That way we can 'think' of "Open" first, and then simply call
29
+ the method name that we want to use. On the commandline we can
30
+ still do:
31
+
32
+ open_in_editor foobar.rb
33
+ open_in_browser google.de
34
+
35
+ ## Layout of the project's structure
36
+
37
+ This subsection will not include all details, but may serve as a slight
38
+ introduction to how the project is layout.
39
+
40
+ Most of the constants will reside under **open/constants/constants.rb**.
41
+
42
+ Toplevel-methods can be found under **open/toplevel_code/** for the
43
+ most part. This may be ignored by some classes if they add
44
+ toplevel-methods; in that case the toplevel may be modified by such
45
+ a class.
46
+
47
+ ## Optional dependencies in this project
48
+
49
+ Officially there are no hardcoded dependencies in this project.
50
+
51
+ However had, you are encouraged to install various gems, such as:
52
+
53
+ - colours
54
+ - convert_global_env
55
+ - beautiful_url
56
+ - opn
57
+
58
+ These may enhance the ruby code used in this project.
59
+
60
+ I highly recommend to install the **colours** gem, but ultimately
61
+ the code in this project is written deliberately in a manner to
62
+ make all these add-ons optional, so this is entirely up to you
63
+ in the end.
64
+
65
+ ## class Open::InEditor
66
+
67
+ This is used for opening a (local) file via the editor.
68
+
69
+ To open a local file via the open-gem, do:
70
+
71
+ require 'open'
72
+
73
+ Open.in_editor('FILE_PATH_GOES_IN_HERE')
74
+ Open.in_editor('/home/x/programming/ruby/src/open/open.gemspec')
75
+
76
+ ## class Open::InBrowser
77
+
78
+ This is used for opening a remote URL via your favourite
79
+ browser.
80
+
81
+ Upon requiring the main class, the method called:
82
+
83
+ open_in_browser()
84
+
85
+ will be defined as well, to simplify working with the
86
+ class.
87
+
88
+ To specify a particular port, use this variant:
89
+
90
+ Open.open_in_browser(port: 8080)
91
+
92
+ This is equivalent to this variant:
93
+
94
+ PORT_TO_USE = 8080
95
+ Open.in_browser(with_localhost: PORT_TO_USE)
96
+
97
+ So different keywords can be used, however your brain prefers
98
+ this or that variant.
99
+
100
+ ## class Open::LastUrl
101
+
102
+ This small class can be used to specifically open the content
103
+ of the xorg-buffer via the browser.
104
+
105
+ ## class Open::WithDelay
106
+
107
+ You can open files via a delay, through class **Open::WithDelay**.
108
+
109
+ You can specify a delay via:
110
+
111
+ openwithdelay 3
112
+
113
+ Or via the method:
114
+
115
+ .set_use_this_delay()
116
+ .set_use_this_delay(3)
117
+ .set_use_this_delay(0.5)
118
+
119
+ ## Changing to a different default editor and browser
120
+
121
+ In **November 2021** I realized that we need a way to more
122
+ easily switch between the default main editor and the
123
+ default main browser. For instance, I abandoned palemoon,
124
+ so I needed to use firefox quickly.
125
+
126
+ The old code had hardcoded calls to **palemoon**, which was
127
+ not very elegant, and made changes to the code harder.
128
+
129
+ Thus two new yaml files were added:
130
+
131
+ use_this_browser.yml
132
+ use_this_editor.yml
133
+
134
+ Now you can modify these yaml files and use a different
135
+ browser or editor. You can even specify the full path
136
+ to these browsers and it should work fine.
137
+
138
+ ## Finding out the current editor and browser in use
139
+
140
+ Use the following two methods if you wish to find out
141
+ which is the current main editor and the current
142
+ main browser in use.
143
+
144
+ puts Open.use_which_editor?
145
+ puts Open.use_which_browser?
146
+
147
+ ## class Open::Base
148
+
149
+ This subsection contains just a few pointers to class
150
+ **Open::Base**.
151
+
152
+ The method **.this_file_was_not_found()** can be
153
+ used to designate that a certain file (the input
154
+ argument to that method) could not be found.
155
+
156
+
157
+ ## Contact information
158
+
159
+ If your creative mind has ideas and specific suggestions to make this
160
+ gem more useful in general, feel free to drop me an email at any
161
+ time, via:
162
+
163
+ shevy@inbox.lt
164
+
165
+ Before that email I used an email account at Google gmail, but in **2021** I
166
+ decided to slowly abandon gmail for various reasons. In part this is because
167
+ the UI annoys me (on non-chrome browser loading takes too long), but also
168
+ because of Google's attempt to establish mass surveillance via its
169
+ federated cohorts sniffing (FLoC). I do not know what happened at Google,
170
+ but enough is enough - there is only so much you can take while supporting
171
+ greed. When it comes to data mining done by private groups, ultimately
172
+ the user became the product.
173
+
174
+ Do keep in mind that responding to emails may take some time,
175
+ depending on the amount of work I may have at that moment, due
176
+ to reallife time constraints. I will, however had, read feedback
177
+ eventually. Patches and code changes are welcome too, of course,
178
+ as long as they are in the spirit of the project at hand, e. g.
179
+ fitting to the general theme. For this I may make use of github
180
+ as a discussion site, but this has a low priority right now.
181
+
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,154 @@
1
+ ADD_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.
44
+
45
+ ## Optional dependencies in this project
46
+
47
+ Officially there are no hardcoded dependencies in this project.
48
+
49
+ However had, you are encouraged to install various gems, such as:
50
+
51
+ - colours
52
+ - convert_global_env
53
+ - beautiful_url
54
+ - opn
55
+
56
+ These may enhance the ruby code used in this project.
57
+
58
+ I highly recommend to install the **colours** gem, but ultimately
59
+ the code in this project is written deliberately in a manner to
60
+ make all these add-ons optional, so this is entirely up to you
61
+ in the end.
62
+
63
+ ## class Open::InEditor
64
+
65
+ This is used for opening a (local) file via the editor.
66
+
67
+ To open a local file via the open-gem, do:
68
+
69
+ require 'open'
70
+
71
+ Open.in_editor('FILE_PATH_GOES_IN_HERE')
72
+ Open.in_editor('/home/x/programming/ruby/src/open/open.gemspec')
73
+
74
+ ## class Open::InBrowser
75
+
76
+ This is used for opening a remote URL via your favourite
77
+ browser.
78
+
79
+ Upon requiring the main class, the method called:
80
+
81
+ open_in_browser()
82
+
83
+ will be defined as well, to simplify working with the
84
+ class.
85
+
86
+ To specify a particular port, use this variant:
87
+
88
+ Open.open_in_browser(port: 8080)
89
+
90
+ This is equivalent to this variant:
91
+
92
+ PORT_TO_USE = 8080
93
+ Open.in_browser(with_localhost: PORT_TO_USE)
94
+
95
+ So different keywords can be used, however your brain prefers
96
+ this or that variant.
97
+
98
+ ## class Open::LastUrl
99
+
100
+ This small class can be used to specifically open the content
101
+ of the xorg-buffer via the browser.
102
+
103
+ ## class Open::WithDelay
104
+
105
+ You can open files via a delay, through class **Open::WithDelay**.
106
+
107
+ You can specify a delay via:
108
+
109
+ openwithdelay 3
110
+
111
+ Or via the method:
112
+
113
+ .set_use_this_delay()
114
+ .set_use_this_delay(3)
115
+ .set_use_this_delay(0.5)
116
+
117
+ ## Changing to a different default editor and browser
118
+
119
+ In **November 2021** I realized that we need a way to more
120
+ easily switch between the default main editor and the
121
+ default main browser. For instance, I abandoned palemoon,
122
+ so I needed to use firefox quickly.
123
+
124
+ The old code had hardcoded calls to **palemoon**, which was
125
+ not very elegant, and made changes to the code harder.
126
+
127
+ Thus two new yaml files were added:
128
+
129
+ use_this_browser.yml
130
+ use_this_editor.yml
131
+
132
+ Now you can modify these yaml files and use a different
133
+ browser or editor. You can even specify the full path
134
+ to these browsers and it should work fine.
135
+
136
+ ## Finding out the current editor and browser in use
137
+
138
+ Use the following two methods if you wish to find out
139
+ which is the current main editor and the current
140
+ main browser in use.
141
+
142
+ puts Open.use_which_editor?
143
+ puts Open.use_which_browser?
144
+
145
+ ## class Open::Base
146
+
147
+ This subsection contains just a few pointers to class
148
+ **Open::Base**.
149
+
150
+ The method **.this_file_was_not_found()** can be
151
+ used to designate that a certain file (the input
152
+ argument to that method) could not be found.
153
+
154
+ ADD_CONTACT_INFORMATION
@@ -0,0 +1,268 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'open/base/base.rb'
6
+ # < Base
7
+ # =========================================================================== #
8
+ module Open
9
+
10
+ class Base # === Open::Base
11
+
12
+ require 'yaml'
13
+
14
+ require 'fileutils'
15
+
16
+ begin
17
+ require 'colours'
18
+ include Colours::E
19
+ rescue LoadError; end
20
+
21
+ begin
22
+ require 'beautiful_url'
23
+ rescue LoadError
24
+ # puts 'BeautifulUrl is not available.'
25
+ end
26
+
27
+ begin
28
+ require 'opn'
29
+ rescue LoadError; end
30
+
31
+ begin
32
+ require 'convert_global_env'
33
+ rescue LoadError; end
34
+
35
+ begin
36
+ require 'roebe/classes/find_expanded_alias.rb'
37
+ rescue LoadError; end
38
+
39
+ require 'open/constants/constants.rb'
40
+ require 'open/toplevel_code/toplevel_code.rb'
41
+
42
+ # ========================================================================= #
43
+ # === NAMESPACE
44
+ # ========================================================================= #
45
+ NAMESPACE = inspect
46
+
47
+ # ========================================================================= #
48
+ # === rev
49
+ # ========================================================================= #
50
+ def rev
51
+ if Object.const_defined? :Colours
52
+ ::Colours.rev
53
+ else
54
+ ''
55
+ end
56
+ end
57
+
58
+ # ========================================================================= #
59
+ # === simp
60
+ # ========================================================================= #
61
+ def simp(i = '')
62
+ if Object.const_defined? :Colours
63
+ return ::Colours.simp(i)
64
+ else
65
+ return i
66
+ end
67
+ end
68
+
69
+ # ========================================================================= #
70
+ # === sfancy
71
+ # ========================================================================= #
72
+ def sfancy(i = '')
73
+ if Object.const_defined? :Colours
74
+ return ::Colours.sfancy(i)
75
+ else
76
+ return i
77
+ end
78
+ end
79
+
80
+ # ========================================================================= #
81
+ # === steelblue
82
+ # ========================================================================= #
83
+ def steelblue(i = '')
84
+ if Object.const_defined? :Colours
85
+ return ::Colours.steelblue(i)
86
+ else
87
+ return i
88
+ end
89
+ end
90
+
91
+ # ========================================================================= #
92
+ # === sfile
93
+ # ========================================================================= #
94
+ def sfile(i = '')
95
+ if Object.const_defined? :Colours
96
+ return ::Colours.sfile(i)
97
+ else
98
+ return i
99
+ end
100
+ end
101
+
102
+ # ========================================================================= #
103
+ # === register_sigint
104
+ # ========================================================================= #
105
+ def register_sigint
106
+ Signal.trap('SIGINT') { exit }
107
+ end
108
+
109
+ # ========================================================================= #
110
+ # === esystem
111
+ #
112
+ # This is a bit of an ad-hoc fix to make this work on windows as well.
113
+ #
114
+ # Eventually may have to rewrite the method a little bit, but for now
115
+ # (September 2021) this has to suffice.
116
+ # ========================================================================= #
117
+ def esystem(
118
+ i, do_show_the_command_that_will_be_used = true
119
+ )
120
+ if is_on_windows?
121
+ # i = i.to_s.sub(/\\/,'\\') if i.include?("\\")
122
+ i = '"'+i.to_s+'"' if i.include?(' ')
123
+ end
124
+ e i if do_show_the_command_that_will_be_used
125
+ system(i)
126
+ end
127
+
128
+ # ========================================================================= #
129
+ # === sanitize
130
+ # ========================================================================= #
131
+ def sanitize(i)
132
+ return i unless Object.const_defined? :ConvertGlobalEnv
133
+ begin
134
+ return ConvertGlobalEnv.convert(i)
135
+ rescue NoMethodError
136
+ i
137
+ end
138
+ end
139
+
140
+ # ========================================================================= #
141
+ # === return_pwd
142
+ # ========================================================================= #
143
+ def return_pwd
144
+ "#{Dir.pwd}/".squeeze('/')
145
+ end
146
+
147
+ # ========================================================================= #
148
+ # === is_on_roebe?
149
+ # ========================================================================= #
150
+ def is_on_roebe?
151
+ ENV['IS_ROEBE'].to_s == '1'
152
+ end
153
+
154
+ # ========================================================================= #
155
+ # == snakecase
156
+ # ========================================================================= #
157
+ def snakecase(i)
158
+ i.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
159
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
160
+ tr('-', '_').
161
+ gsub(/\s/, '_').
162
+ gsub(/__+/, '_').
163
+ downcase
164
+ end
165
+
166
+ # ========================================================================= #
167
+ # === is_on_windows?
168
+ # ========================================================================= #
169
+ def is_on_windows?
170
+ ::Open.is_on_windows?
171
+ end
172
+
173
+ # ========================================================================= #
174
+ # === reset (reset tag)
175
+ # ========================================================================= #
176
+ def reset
177
+ # ======================================================================= #
178
+ # === @namespace
179
+ # ======================================================================= #
180
+ @namespace = NAMESPACE
181
+ # ======================================================================= #
182
+ # === @be_verbose
183
+ # ======================================================================= #
184
+ @be_verbose = true
185
+ end
186
+
187
+ # ========================================================================= #
188
+ # === opnn
189
+ # ========================================================================= #
190
+ def opnn(
191
+ i = { namespace: @namespace }
192
+ )
193
+ if Object.const_defined? :Opn
194
+ Opn.opn(i)
195
+ end
196
+ end
197
+
198
+ # ========================================================================= #
199
+ # === set_commandline_arguments
200
+ # ========================================================================= #
201
+ def set_commandline_arguments(
202
+ i = ARGV
203
+ )
204
+ @commandline_arguments = [i].flatten.compact
205
+ end
206
+
207
+ # ========================================================================= #
208
+ # === first_argument?
209
+ # ========================================================================= #
210
+ def first_argument?
211
+ @commandline_arguments.first
212
+ end
213
+
214
+ # ========================================================================= #
215
+ # === rds
216
+ # ========================================================================= #
217
+ def rds(i)
218
+ i.squeeze('/')
219
+ end
220
+
221
+ # ========================================================================= #
222
+ # === mkdir
223
+ # ========================================================================= #
224
+ def mkdir(i)
225
+ FileUtils.mkdir_p(i)
226
+ end
227
+
228
+ # ========================================================================= #
229
+ # === touch
230
+ # ========================================================================= #
231
+ def touch(i)
232
+ FileUtils.touch(i)
233
+ end
234
+
235
+ # ========================================================================= #
236
+ # === use_which_editor?
237
+ # ========================================================================= #
238
+ def use_which_editor?
239
+ ::Open.use_which_editor?
240
+ end
241
+
242
+ # ========================================================================= #
243
+ # === use_which_browser?
244
+ # ========================================================================= #
245
+ def use_which_browser?
246
+ ::Open.use_which_browser?
247
+ end
248
+
249
+ # ========================================================================= #
250
+ # === this_file_was_not_found
251
+ #
252
+ # Use this whenever we did not find any file.
253
+ # ========================================================================= #
254
+ def this_file_was_not_found(i)
255
+ e "No file called `#{sfile(i)}` was found. It "\
256
+ "is assumed that it does not exist."
257
+ end; alias no_file_exists_at this_file_was_not_found # === no_file_exists_at
258
+ alias no_file_was_found_at this_file_was_not_found # === no_file_was_found_at
259
+
260
+ # ========================================================================= #
261
+ # === beautiful_url
262
+ # ========================================================================= #
263
+ def beautiful_url(i)
264
+ result = BeautifulUrl[i] if Object.const_defined? :BeautifulUrl
265
+ return result
266
+ end
267
+
268
+ end; end