open 0.1.30

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.
@@ -0,0 +1,329 @@
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
+ # === tomato
93
+ # ========================================================================= #
94
+ def tomato(i = '')
95
+ if Object.const_defined? :Colours
96
+ return ::Colours.tomato(i)
97
+ else
98
+ return i
99
+ end
100
+ end
101
+
102
+ # ========================================================================= #
103
+ # === etomato
104
+ # ========================================================================= #
105
+ def etomato(i = '')
106
+ e tomato(i)
107
+ end
108
+
109
+ # ========================================================================= #
110
+ # === sfile
111
+ # ========================================================================= #
112
+ def sfile(i = '')
113
+ if Object.const_defined? :Colours
114
+ return ::Colours.sfile(i)
115
+ else
116
+ return i
117
+ end
118
+ end
119
+
120
+ # ========================================================================= #
121
+ # === register_sigint
122
+ # ========================================================================= #
123
+ def register_sigint
124
+ Signal.trap('SIGINT') { exit }
125
+ end
126
+
127
+ # ========================================================================= #
128
+ # === esystem
129
+ #
130
+ # This is a bit of an ad-hoc fix to make this work on windows as well.
131
+ #
132
+ # Eventually may have to rewrite the method a little bit, but for now
133
+ # (September 2021) this has to suffice.
134
+ # ========================================================================= #
135
+ def esystem(
136
+ i, do_show_the_command_that_will_be_used = true
137
+ )
138
+ if is_on_windows?
139
+ # i = i.to_s.sub(/\\/,'\\') if i.include?("\\")
140
+ i = '"'+i.to_s+'"' if i.include?(' ')
141
+ end
142
+ e i if do_show_the_command_that_will_be_used
143
+ system(i)
144
+ end
145
+
146
+ # ========================================================================= #
147
+ # === sanitize
148
+ # ========================================================================= #
149
+ def sanitize(i)
150
+ return i unless Object.const_defined? :ConvertGlobalEnv
151
+ begin
152
+ return ConvertGlobalEnv.convert(i)
153
+ rescue NoMethodError
154
+ i
155
+ end
156
+ end
157
+
158
+ # ========================================================================= #
159
+ # === return_pwd
160
+ # ========================================================================= #
161
+ def return_pwd
162
+ "#{Dir.pwd}/".squeeze('/')
163
+ end
164
+
165
+ # ========================================================================= #
166
+ # == snakecase
167
+ # ========================================================================= #
168
+ def snakecase(i)
169
+ i.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
170
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
171
+ tr('-', '_').
172
+ gsub(/\s/, '_').
173
+ gsub(/__+/, '_').
174
+ downcase
175
+ end
176
+
177
+ # ========================================================================= #
178
+ # === reset (reset tag)
179
+ # ========================================================================= #
180
+ def reset
181
+ # ======================================================================= #
182
+ # === @namespace
183
+ # ======================================================================= #
184
+ @namespace = NAMESPACE
185
+ # ======================================================================= #
186
+ # === @be_verbose
187
+ # ======================================================================= #
188
+ @be_verbose = true
189
+ end
190
+
191
+ # ========================================================================= #
192
+ # === opnn
193
+ # ========================================================================= #
194
+ def opnn(
195
+ i = { namespace: @namespace }
196
+ )
197
+ if Object.const_defined? :Opn
198
+ Opn.opn(i)
199
+ end
200
+ end
201
+
202
+ # ========================================================================= #
203
+ # === set_commandline_arguments
204
+ # ========================================================================= #
205
+ def set_commandline_arguments(
206
+ i = ARGV
207
+ )
208
+ @commandline_arguments = [i].flatten.compact
209
+ end
210
+
211
+ # ========================================================================= #
212
+ # === first_argument?
213
+ # ========================================================================= #
214
+ def first_argument?
215
+ @commandline_arguments.first
216
+ end
217
+
218
+ # ========================================================================= #
219
+ # === rds
220
+ # ========================================================================= #
221
+ def rds(i)
222
+ i.squeeze('/')
223
+ end
224
+
225
+ # ========================================================================= #
226
+ # === mkdir
227
+ # ========================================================================= #
228
+ def mkdir(i)
229
+ FileUtils.mkdir_p(i)
230
+ end
231
+
232
+ # ========================================================================= #
233
+ # === touch
234
+ # ========================================================================= #
235
+ def touch(i)
236
+ FileUtils.touch(i)
237
+ end
238
+
239
+ # ========================================================================= #
240
+ # === use_which_editor?
241
+ # ========================================================================= #
242
+ def use_which_editor?
243
+ ::Open.use_which_editor?
244
+ end
245
+
246
+ # ========================================================================= #
247
+ # === use_which_browser?
248
+ # ========================================================================= #
249
+ def use_which_browser?
250
+ ::Open.use_which_browser?
251
+ end
252
+
253
+ # ========================================================================= #
254
+ # === this_file_was_not_found
255
+ #
256
+ # Use this whenever we did not find any file.
257
+ # ========================================================================= #
258
+ def this_file_was_not_found(i)
259
+ e "No file called `#{sfile(i)}` was found. It "\
260
+ "is assumed that it does not exist."
261
+ end; alias no_file_exists_at this_file_was_not_found # === no_file_exists_at
262
+ alias no_file_was_found_at this_file_was_not_found # === no_file_was_found_at
263
+
264
+ # ========================================================================= #
265
+ # === host_os?
266
+ #
267
+ # Return the host-operating system via this method.
268
+ # ========================================================================= #
269
+ def host_os?
270
+ ::Open.host_os?
271
+ end
272
+
273
+ # ========================================================================= #
274
+ # === is_on_windows?
275
+ # ========================================================================= #
276
+ def is_on_windows?(i = host_os?)
277
+ ::Open.is_on_windows?(i)
278
+ end; alias on_windows? is_on_windows? # === on_windows?
279
+
280
+ # ========================================================================= #
281
+ # === is_on_roebe?
282
+ # ========================================================================= #
283
+ def is_on_roebe?
284
+ ENV['IS_ROEBE'].to_s == '1'
285
+ end
286
+
287
+ # ========================================================================= #
288
+ # === ecomment
289
+ # ========================================================================= #
290
+ def ecomment(i = '')
291
+ ::Colours.ecomment(i)
292
+ end
293
+
294
+ # ========================================================================= #
295
+ # === beautiful_url
296
+ #
297
+ # Wrapper-method towards BeautifulUrl.
298
+ # ========================================================================= #
299
+ def beautiful_url(i)
300
+ if Object.const_defined? :BeautifulUrl
301
+ i = BeautifulUrl::BeautifulUrl.new(i).results?
302
+ end
303
+ return i
304
+ end
305
+
306
+ # ========================================================================= #
307
+ # === infer_the_namespace
308
+ #
309
+ # This will assume the true namespace from the inspectable name.
310
+ # ========================================================================= #
311
+ def infer_the_namespace
312
+ _ = inspect.to_s.delete('<')
313
+ if _.include? ' '
314
+ _ = _.split(' ').first.delete('#')
315
+ if _.include? ':'
316
+ _ = _.split(':')[0 .. -2].reject {|entry| entry.empty? }.join('::')
317
+ end
318
+ end
319
+ @namespace = _ # And assign it here.
320
+ end
321
+
322
+ # ========================================================================= #
323
+ # === namespace?
324
+ # ========================================================================= #
325
+ def namespace?
326
+ @namespace
327
+ end
328
+
329
+ end; end
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'open/constants/constants.rb'
6
+ # =========================================================================== #
7
+ module Open
8
+
9
+ require 'yaml'
10
+ require 'open/project/project.rb'
11
+
12
+ # ========================================================================= #
13
+ # === IN_BACKGROUND
14
+ # ========================================================================= #
15
+ IN_BACKGROUND = ' &'
16
+
17
+ # ========================================================================= #
18
+ # === HOME_DIRECTORY_OF_USER_X
19
+ #
20
+ # This constant is only useful on my home system.
21
+ # ========================================================================= #
22
+ HOME_DIRECTORY_OF_USER_X = '/home/x/'
23
+
24
+ # ========================================================================= #
25
+ # === RUBY_SRC
26
+ # ========================================================================= #
27
+ RUBY_SRC = "#{HOME_DIRECTORY_OF_USER_X}programming/ruby/src/"
28
+
29
+ # ========================================================================= #
30
+ # === PROGRAMMING_LANGUAGES_DIRECTORY_AT_HOME
31
+ # ========================================================================= #
32
+ PROGRAMMING_LANGUAGES_DIRECTORY_AT_HOME =
33
+ "#{HOME_DIRECTORY_OF_USER_X}programming/"
34
+
35
+ # ========================================================================= #
36
+ # === USERFIND
37
+ # ========================================================================= #
38
+ USERFIND = "find #{HOME_DIRECTORY_OF_USER_X}data -name"
39
+
40
+ # ========================================================================= #
41
+ # === MY_DATA
42
+ #
43
+ # This is functionality equivalent to the String '/home/x/data/'.
44
+ # ========================================================================= #
45
+ MY_DATA = "#{HOME_DIRECTORY_OF_USER_X}data/"
46
+ DATA_DIRECTORY_AT_HOME = MY_DATA # === DATA_DIRECTORY_AT_HOME
47
+
48
+ # ========================================================================= #
49
+ # === N_DELAY
50
+ #
51
+ # This delay is specifically used for delaying before batch-opening
52
+ # files via the Open.in_editor() functionality.
53
+ # ========================================================================= #
54
+ N_DELAY = 0.48
55
+
56
+ # ========================================================================= #
57
+ # === Open::LOCATION_OF_BROWSER_YAML_FILE
58
+ #
59
+ # Here we must define where we store the location for our browser.
60
+ #
61
+ # That file will tell us which browser to use.
62
+ #
63
+ # Most users will not have this file, so the code will have to remain
64
+ # flexible in this regard.
65
+ #
66
+ # On my home system this will point towards the following file:
67
+ #
68
+ # /home/Programs/Ruby/3.1.2/lib/ruby/site_ruby/3.1.0/open/yaml/use_this_browser.yml
69
+ #
70
+ # ========================================================================= #
71
+ LOCATION_OF_BROWSER_YAML_FILE =
72
+ "#{project_yaml_directory?}use_this_browser.yml"
73
+
74
+ # ========================================================================= #
75
+ # === Open.file_browser?
76
+ # ========================================================================= #
77
+ def self.file_browser?
78
+ LOCATION_OF_BROWSER_YAML_FILE
79
+ end
80
+
81
+ # ========================================================================= #
82
+ # === FILE_SHORTCUTS
83
+ # ========================================================================= #
84
+ FILE_SHORTCUTS =
85
+ "#{project_yaml_directory?}shortcuts.yml"
86
+
87
+ # ========================================================================= #
88
+ # === LOCATION_OF_EDITOR_YAML_FILE
89
+ # ========================================================================= #
90
+ LOCATION_OF_EDITOR_YAML_FILE =
91
+ "#{project_yaml_directory?}use_this_editor.yml"
92
+
93
+ # ========================================================================= #
94
+ # === USE_THIS_EDITOR
95
+ #
96
+ # This variant is hardcoded, but there are class-methods that can be used
97
+ # to overrule the setting.
98
+ # ========================================================================= #
99
+ if File.exist?(LOCATION_OF_EDITOR_YAML_FILE)
100
+ USE_THIS_EDITOR = YAML.load_file(LOCATION_OF_EDITOR_YAML_FILE)
101
+ else # else use a hardcoded default
102
+ USE_THIS_EDITOR = 'bluefish' # geany
103
+ end
104
+
105
+ # ========================================================================= #
106
+ # === USE_THIS_BROWSER
107
+ # ========================================================================= #
108
+ if File.exist?(Dir.home+'/use_this_browser.yml') # First check the home directory of the user.
109
+ USE_THIS_BROWSER = YAML.load_file(Dir.home+'/use_this_browser.yml')
110
+ elsif File.exist?(LOCATION_OF_BROWSER_YAML_FILE)
111
+ USE_THIS_BROWSER = YAML.load_file(LOCATION_OF_BROWSER_YAML_FILE)
112
+ else # else use a hardcoded default
113
+ USE_THIS_BROWSER = 'firefox' # palemoon or chrome may be options too
114
+ end
115
+
116
+ end
117
+
118
+ if __FILE__ == $PROGRAM_NAME
119
+ puts Open::MY_DATA
120
+ puts Open::LOCATION_OF_BROWSER_YAML_FILE
121
+ puts Open::USE_THIS_EDITOR
122
+ puts Open::USE_THIS_BROWSER
123
+ end