open 0.1.30 → 0.2.13

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.

Potentially problematic release.


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

Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +73 -9
  3. data/bin/open +1 -1
  4. data/bin/open_in_browser +1 -1
  5. data/doc/README.gen +72 -8
  6. data/doc/deprecated_code/deprecated_code.md +26 -0
  7. data/img/open_logo.png +0 -0
  8. data/lib/open/base/base.rb +262 -122
  9. data/lib/open/books/README.md +8 -0
  10. data/lib/open/books/books.rb +99 -0
  11. data/lib/open/constants/constants.rb +85 -8
  12. data/lib/open/in_browser/in_browser.rb +476 -304
  13. data/lib/open/in_editor/in_editor.rb +348 -155
  14. data/lib/open/last/last.rb +14 -12
  15. data/lib/open/nano_open/nano_open.rb +4 -3
  16. data/lib/open/{open.rb → open/open.rb} +597 -653
  17. data/lib/open/project/project.rb +3 -2
  18. data/lib/open/requires/failsafe_require_of_beautiful_url.rb +9 -0
  19. data/lib/open/requires/require_the_project.rb +2 -2
  20. data/lib/open/requires/require_yaml.rb +13 -0
  21. data/lib/open/these_files/these_files.rb +1 -1
  22. data/lib/open/toplevel_methods/browser.rb +71 -0
  23. data/lib/open/toplevel_methods/delay.rb +23 -0
  24. data/lib/open/toplevel_methods/e.rb +14 -0
  25. data/lib/open/toplevel_methods/editor.rb +41 -0
  26. data/lib/open/toplevel_methods/host_os.rb +25 -0
  27. data/lib/open/toplevel_methods/is_on_roebe.rb +16 -0
  28. data/lib/open/toplevel_methods/is_on_windows.rb +26 -0
  29. data/lib/open/toplevel_methods/misc.rb +50 -0
  30. data/lib/open/version/version.rb +2 -2
  31. data/lib/open/with_delay/with_delay.rb +9 -11
  32. data/open.gemspec +1 -1
  33. data/test/testing_open.rb +1 -1
  34. data/test/testing_open_in_browser.rb +16 -0
  35. data/test/testing_open_via_launchy.rb +3 -0
  36. data/test/testing_shortcuts.rb +3 -0
  37. metadata +24 -8
  38. data/lib/open/toplevel_code/toplevel_code.rb +0 -189
@@ -5,15 +5,15 @@
5
5
  # === Open::Open
6
6
  #
7
7
  # This class will simply open a given file. It may also "open" the file
8
- # in the browser, that is, to use primarily firefox to display the file
9
- # content as such.
8
+ # in the browser, that is, to use firefox or chrome or thorium to
9
+ # display the file content as such.
10
10
  #
11
11
  # Usage example:
12
12
  #
13
13
  # Open::Open.new(ARGV)
14
14
  #
15
15
  # =========================================================================== #
16
- # require 'open/open.rb'
16
+ # require 'open/open/open.rb'
17
17
  # Open::Open.new(ARGV)
18
18
  # =========================================================================== #
19
19
  require 'open/base/base.rb'
@@ -22,13 +22,13 @@ module Open
22
22
 
23
23
  class Open < ::Open::Base # === Open::Open
24
24
 
25
- require 'open/in_editor/in_editor.rb'
26
25
  require 'open/in_browser/in_browser.rb'
27
- require 'open/toplevel_code/toplevel_code.rb'
26
+ require 'open/in_editor/in_editor.rb'
27
+ require 'open/toplevel_methods/misc.rb'
28
28
 
29
29
  begin
30
30
  require 'roebe/classes/find_expanded_alias.rb'
31
- rescue LoadError; end
31
+ rescue LoadError => error; puts error; end
32
32
 
33
33
  # ========================================================================= #
34
34
  # === LIBREOFFICE
@@ -41,7 +41,7 @@ class Open < ::Open::Base # === Open::Open
41
41
  if ENV['PATH_TO_THE_LIBREOFFICE_EXECUTABLE']
42
42
  LIBREOFFICE = ENV['PATH_TO_THE_LIBREOFFICE_EXECUTABLE'].to_s.dup
43
43
  else
44
- LIBREOFFICE = '/usr/bin/soffice'
44
+ LIBREOFFICE = '/usr/bin/soffice' # This will be valid for most users of the gem.
45
45
  end
46
46
 
47
47
  # ========================================================================= #
@@ -63,26 +63,6 @@ class Open < ::Open::Base # === Open::Open
63
63
  # ========================================================================= #
64
64
  USE_THIS_DELAY = 0.65
65
65
 
66
- # ========================================================================= #
67
- # === ARRAY_EXTENSIONS_THAT_CAN_BE_OPENED_IN_THE_EDITOR
68
- #
69
- # All extensions that can be opened in the editor should be registered
70
- # in this constant.
71
- #
72
- # For example, "h" means ".h" aka a C or C++ header file.
73
- # ========================================================================= #
74
- ARRAY_EXTENSIONS_THAT_CAN_BE_OPENED_IN_THE_EDITOR = %w(
75
- php rb txt yaml yml cgi
76
- md gemspec html csv py
77
- conf c sh js log css cr
78
- ascii la pl perl json
79
- js fasta fa m3u cpp
80
- go gff gff3
81
- gen h
82
- erb sinatra
83
- sql
84
- ).sort << '' # The last part is for files like "TODO" which lack an extension.
85
-
86
66
  # ========================================================================= #
87
67
  # === ARRAY_LIBREOFFICE_EXTENSIONS
88
68
  #
@@ -104,42 +84,18 @@ class Open < ::Open::Base # === Open::Open
104
84
  pps
105
85
  )
106
86
 
107
- # ========================================================================= #
108
- # === ARRAY_IMAGES
109
- #
110
- # All file-extensions for images can be registered in this Array.
111
- # ========================================================================= #
112
- ARRAY_IMAGES = %w(
113
- png
114
- jpg
115
- gif
116
- jpeg
117
- tiff
118
- tif
119
- bmp
120
- )
121
-
122
- # ========================================================================= #
123
- # === ARRAY_VIDEOS
124
- # ========================================================================= #
125
- ARRAY_VIDEOS = %w(
126
- vob
127
- avi
128
- flv
129
- mp3
130
- mp4
131
- )
132
-
133
87
  # ========================================================================= #
134
88
  # === initialize
135
89
  # ========================================================================= #
136
90
  def initialize(
137
- i = nil,
138
- run_already = true,
91
+ commandline_arguments = ARGV,
92
+ run_already = true,
139
93
  &block
140
94
  )
141
95
  reset
142
- set_input(i)
96
+ set_commandline_arguments(
97
+ commandline_arguments
98
+ )
143
99
  # ======================================================================= #
144
100
  # === Handle blocks next
145
101
  # ======================================================================= #
@@ -159,7 +115,7 @@ class Open < ::Open::Base # === Open::Open
159
115
  # === :open_via_fullscreen
160
116
  # =================================================================== #
161
117
  if yielded.has_key? :open_via_fullscreen
162
- @open_via_fullscreen = yielded.delete(:open_via_fullscreen)
118
+ @internal_hash[:open_via_fullscreen] = yielded.delete(:open_via_fullscreen)
163
119
  end
164
120
  end
165
121
  end
@@ -173,75 +129,104 @@ class Open < ::Open::Base # === Open::Open
173
129
  super()
174
130
  infer_the_namespace
175
131
  # ======================================================================= #
176
- # === @image_editor
132
+ # === @internal_hash
133
+ # ======================================================================= #
134
+ @internal_hash = {}
177
135
  # ======================================================================= #
178
- @image_editor = 'gimp'
136
+ # === :open_via_fullscreen
179
137
  # ======================================================================= #
180
- # === @editor
138
+ @internal_hash[:open_via_fullscreen] = false
181
139
  # ======================================================================= #
182
- @editor = use_which_editor?
140
+ # === :set_the_main_book
183
141
  # ======================================================================= #
184
- # === @set_the_main_book
142
+ @internal_hash[:set_the_main_book] = false
185
143
  # ======================================================================= #
186
- @set_the_main_book = false
144
+ # === :image_editor_to_use
187
145
  # ======================================================================= #
188
- # === @open_via_fullscreen
146
+ @internal_hash[:image_editor_to_use] = 'gimp'
189
147
  # ======================================================================= #
190
- @open_via_fullscreen = false
148
+ # === :editor
149
+ # ======================================================================= #
150
+ set_editor(use_which_editor?)
151
+ # ======================================================================= #
152
+ # === :open_these_elements
153
+ # ======================================================================= #
154
+ @internal_hash[:open_these_elements] = []
191
155
  end
192
156
 
193
157
  # ========================================================================= #
194
158
  # === set_the_main_book?
195
159
  # ========================================================================= #
196
160
  def set_the_main_book?
197
- @set_the_main_book
161
+ @internal_hash[:set_the_main_book]
198
162
  end
199
163
 
200
164
  # ========================================================================= #
201
- # === set_use_this_editor
165
+ # === open_in_editor (open tag, open1 tag)
166
+ #
167
+ # This method will simply delegate towards class Open::InEditor.
168
+ #
169
+ # Take note that Open.in_editor() will already handle delays, so
170
+ # we do not have to do anything special here.
202
171
  # ========================================================================= #
203
- def set_use_this_editor(
204
- i = use_which_editor?
205
- )
206
- @editor = i.to_s
207
- end
172
+ def open_in_editor(i)
173
+ ::Open.in_editor(i)
174
+ end; alias try_to_open_this_file_in_the_editor open_in_editor # === try_to_open_this_file_in_the_editor
175
+ alias consider_opening_the_given_input open_in_editor # === consider_opening_the_given_input
176
+ alias open_these_files open_in_editor # === open_these_files
177
+ alias do_open_in_editor open_in_editor # === do_open_in_editor
208
178
 
209
179
  # ========================================================================= #
210
- # === replace_localhost_with_data
180
+ # === try_to_require_the_studium_project
211
181
  # ========================================================================= #
212
- def replace_localhost_with_data(i)
213
- if i.include? 'programming'
214
- return i.sub('localhost','/home/x/')
215
- else
216
- return i.sub('localhost','/home/x/data/')
182
+ def try_to_require_the_studium_project
183
+ unless Object.const_defined?(:Studium) and
184
+ Studium.respond_to?(:include_this_exam_topic?)
185
+ begin # We pull in only the relevant files from the Studium project.
186
+ require 'studium/constants/constants.rb'
187
+ require 'studium/toplevel_methods/find_exam_topic_and_exam_title.rb'
188
+ require 'studium/toplevel_methods/is_this_exam_topic_included.rb'
189
+ rescue LoadError
190
+ if is_on_roebe?
191
+ e 'The three files ('\
192
+ 'studium/constants/constants.rb,'\
193
+ 'studium/toplevel_methods/find_exam_topic_and_exam_title.rb and '\
194
+ 'studium/toplevel_methods/is_this_exam_topic_included.rb '\
195
+ 'forth) from the studium-project could not be loaded.'
196
+ end
197
+ end
217
198
  end
218
199
  end
219
200
 
220
201
  # ========================================================================= #
221
- # === set_input
202
+ # === show_help (help tag)
222
203
  # ========================================================================= #
223
- def set_input(i = ARGV)
224
- i = [i] unless i.is_a? Array
225
- i.map! {|entry|
226
- entry = entry.to_s.dup
227
- # ===================================================================== #
228
- # Split away at '::' if this is part of that substring.
229
- # ===================================================================== #
230
- if entry.include? '::'
231
- splitted = entry.split('::')
232
- entry = splitted.last
233
- end
234
- if entry.include? '^'
235
- entry.delete!('^')
236
- end
237
- case entry
238
- # ===================================================================== #
239
- # === open --everything
240
- #
241
- # This actually refers only to files, so we select for files next.
242
- # ===================================================================== #
243
- when /^-?-?everything?$/i
244
- entry = Dir['**/**'].select {|inner_entry| File.file?(inner_entry) }
204
+ def show_help
205
+ opne 'The following options are available:'
206
+ e
207
+ ecomment ' SELF # Open this .rb file here.'
208
+ ecomment ' --use-this-browser=firefox # Assign a new browser, in this case firefox.'
209
+ ecomment ' --browser? # '\
210
+ 'Show which browser is the currently assigned one.'
211
+ ecomment ' --everything # '\
212
+ 'This will open every file in the current working directory, and '\
213
+ 'all subdirectories.'
214
+ ecomment ' --important-exam # '\
215
+ 'Open all important exams. Only useful if the studium gem is '\
216
+ 'also installed.'
217
+ e
218
+ end
219
+
220
+ # ========================================================================= #
221
+ # === menu (menu tag)
222
+ # ========================================================================= #
223
+ def menu(
224
+ i = commandline_arguments?
225
+ )
226
+ if i.is_a? Array
227
+ i.each {|entry| menu(entry) }
228
+ else
229
+ case i # (case tag)
245
230
  # ===================================================================== #
246
231
  # === open --important-exam
247
232
  # ===================================================================== #
@@ -249,140 +234,46 @@ class Open < ::Open::Base # === Open::Open
249
234
  base_dir = ENV['USERS']
250
235
  base_dir = '/home' if base_dir.nil?
251
236
  entry = "#{base_dir}/x/programming/ruby/src/studium/lib/studium/yaml/important_exams.yml"
252
- end
253
- # ===================================================================== #
254
- # Get rid of localhost next. This must be handled with more care,
255
- # because some files may include the string 'localhost' as part of
256
- # their name, such as 'remove_localhost.rb'. In this case, we will
257
- # additionally check whether the file exists.
237
+ @internal_hash[:open_these_elements].clear
238
+ @internal_hash[:open_these_elements] << entry
258
239
  # ===================================================================== #
259
- if entry.is_a?(String) and entry.include?('localhost')
260
- unless File.exist? entry # See the above header for an explanation.
261
- entry = replace_localhost_with_data(entry)
262
- end
263
- end
264
- if entry.is_a? String
265
- entry.chop! if entry.end_with? '#' # Don't need trailing '#' tokens.
266
- entry.chop! if entry.end_with? ':-' # ← This check must come before the check against ':'.
267
- entry.chop! if entry.end_with? ':' # Chop off trailing ':' tokens.
268
- # ===================================================================== #
269
- # Next, we handle input such as:
270
- # 'lib/lpc/requires/basic_requires.rb:begin'
271
- # This evidently does not end with a ':' character, but it clearly
272
- # has a fairly useless ':' component in it. If that is the case,
273
- # we will treat this as input that is only valid up towards the
274
- # very right ':', anchored on the '.rb:' part.
275
- # ===================================================================== #
276
- if entry.include? '.rb:'
277
- # =================================================================== #
278
- # The following code means to find the index at '.rb:' and then add
279
- # 2 to it - this should be the correct name of the entry at hand.
280
- # =================================================================== #
281
- entry = entry[0 .. (entry.index('.rb:')+2)]
282
- end
283
- if entry.end_with?(',') and !File.exist?(',')
284
- entry.chop!
285
- elsif entry.end_with?('.') and File.exist?(entry[0..-2])
286
- # =================================================================== #
287
- # This clause will be entered if we have input something like
288
- # "colours.rb." where the user may have wanted to type in
289
- # "colours.rb" - and IF the file exists.
290
- # =================================================================== #
291
- opnn; e "Assuming a superfluous trailing '.', so removing "\
292
- "the last '.' there."
293
- entry.chop!
294
- end
295
- end
296
- case entry # Work only on the first entry. (case tag)
297
- # ===================================================================== #
298
- # === open ME
240
+ # === open --everything
241
+ #
242
+ # This actually refers only to files, so we select for files next.
299
243
  # ===================================================================== #
300
- when 'ME',
301
- 'SELF',
302
- 'ALL',/
303
- ^-?-?this(_|-)?file/
304
- open_this_file_here
305
- exit
244
+ when /^-?-?everything?$/i
245
+ elements = Dir['**/**'].select {|inner_entry| File.file?(inner_entry) }
246
+ @internal_hash[:open_these_elements].clear
247
+ @internal_hash[:open_these_elements] << elements
306
248
  # ===================================================================== #
307
249
  # === open --help
308
250
  # ===================================================================== #
309
251
  when /^-?-?help$/i,
310
- 'show_help'
252
+ /^-?-?show(-|_)?help$/i
311
253
  show_help
312
254
  exit
313
- end unless File.exist?(entry.to_s)
314
- entry
315
- }
316
- @input = i # This must be an Array.
317
- end; alias set_input_files set_input # === set_input_files
318
-
319
- # ========================================================================= #
320
- # === input?
321
- # ========================================================================= #
322
- def input?
323
- @input
324
- end; alias input_file? input? # === input_file?
325
- alias input_files? input? # === input_files?
326
-
327
- # ========================================================================= #
328
- # === check_whether_the_user_has_provided_any_input
329
- # ========================================================================= #
330
- def check_whether_the_user_has_provided_any_input
331
- _ = input_files?
332
- local_files = Dir['*'].select {|entry| File.file? entry }
333
- if _.empty? and !local_files.empty? and (local_files.size == 1)
334
255
  # ===================================================================== #
335
- # Handle the case where no specific input was given, but only
336
- # one file exists in the local directory.
256
+ # === open --browser?
337
257
  # ===================================================================== #
338
- set_input_files(local_files.first)
339
- _ = input_files?
340
- end
341
- if _.empty?
342
- if is_on_roebe? and !is_bluefish_running?
343
- start_bluefish
344
- else
345
- opnn; e 'Please provide at least one argument - the file '\
346
- 'you wish to open.'
258
+ when /^-?-?browser\??$/
259
+ _ = YAML.load_file(::Open.file_browser?)
260
+ e "#{rev}The browser currently in use is `#{sfancy(_)}#{rev}`."
261
+ exit
262
+ # ===================================================================== #
263
+ # === open --use-this-browser=firefox
264
+ # ===================================================================== #
265
+ when /^-?-?use(-|_)?this(-|_)?browser=(.+)/
266
+ ::Open.permanently_use_this_browser = $3.to_s.dup
347
267
  exit
348
268
  end
349
269
  end
350
270
  end
351
271
 
352
272
  # ========================================================================= #
353
- # === start_bluefish
354
- # ========================================================================= #
355
- def start_bluefish
356
- esystem 'bluefish &'
357
- end
358
-
359
- # ========================================================================= #
360
- # === is_bluefish_running?
361
- # ========================================================================= #
362
- def is_bluefish_running?
363
- `ps ax | grep bluefish`.split("\n").reject {|entry|
364
- entry.include? 'grep'
365
- }.size > 0
366
- end
367
-
368
- # ========================================================================= #
369
- # === consider_padding
370
- #
371
- # Simply add a surrounding '"' to the given input, so that any resulting
372
- # system() call will still work if we have awkward filenames.
373
- # ========================================================================= #
374
- def consider_padding(i)
375
- if i.include?(' ') or i.include?('(')
376
- i = '"'+i+'"'
377
- end
378
- return i
379
- end
380
-
381
- # ========================================================================= #
382
- # === play_multimedia_file
273
+ # === editor?
383
274
  # ========================================================================= #
384
- def play_multimedia_file(i)
385
- esystem "#{USE_THIS_MPLAYER_COMMAND} #{i}" # open
275
+ def editor?
276
+ @internal_hash[:editor]
386
277
  end
387
278
 
388
279
  # ========================================================================= #
@@ -392,13 +283,6 @@ class Open < ::Open::Base # === Open::Open
392
283
  do_open_in_editor(this_file?+IN_BACKGROUND)
393
284
  end
394
285
 
395
- # ========================================================================= #
396
- # === return_this_file_here
397
- # ========================================================================= #
398
- def return_this_file_here
399
- __FILE__
400
- end; alias this_file? return_this_file_here # === this_file?
401
-
402
286
  # ========================================================================= #
403
287
  # === delay?
404
288
  # ========================================================================= #
@@ -407,176 +291,61 @@ class Open < ::Open::Base # === Open::Open
407
291
  end
408
292
 
409
293
  # ========================================================================= #
410
- # === find_and_return_last_file
411
- # ========================================================================= #
412
- def find_and_return_last_file
413
- array = Dir['*'].reject {|entry| ! File.file? entry }
414
- array.map! {|entry|
415
- [entry, File.ctime(entry)]
416
- }
417
- result = array.sort_by {|entry| entry[1] }.reverse
418
- result = result.first[0]
419
- return result
420
- end
421
-
422
- # ========================================================================= #
423
- # === can_be_opened_in_the_editor?
294
+ # === set_use_this_editor
424
295
  # ========================================================================= #
425
- def can_be_opened_in_the_editor?(i)
426
- _ = File.extname(i).delete('.')
427
- ARRAY_EXTENSIONS_THAT_CAN_BE_OPENED_IN_THE_EDITOR.include? i
428
- end
296
+ def set_use_this_editor(
297
+ i = use_which_editor?
298
+ )
299
+ @internal_hash[:editor] = i.to_s
300
+ end; alias set_editor set_use_this_editor # === set_editor
429
301
 
430
302
  # ========================================================================= #
431
- # === try_to_open_this_file_in_the_editor
303
+ # === open_in_pdf_viewer (pdf tag)
304
+ #
305
+ # This method can be used to open a .pdf file. We will let the project
306
+ # PdfParadise handle this situation.
307
+ #
308
+ # Since as of 19.09.2018 we will keep a log of the opened .pdf files
309
+ # if we are on roebe. This can then be used to determine which were
310
+ # the last .pdf files that were read.
432
311
  # ========================================================================= #
433
- def try_to_open_this_file_in_the_editor(
434
- i = input_files?
435
- )
312
+ def open_in_pdf_viewer(i)
313
+ require 'pdf_paradise' unless Object.const_defined? :PdfParadise
436
314
  # ======================================================================= #
437
- # === First check whether we have passed an Array
315
+ # Since as of April 2022 we will use the absolute path to the .pdf
316
+ # file at hand. The reason for this is because this makes it easier
317
+ # to know which files are open, and we can store these file paths
318
+ # into a local file (such as a .yml file), and then use this at a
319
+ # later time to restore all .pdf files that were open. This thus
320
+ # constitutes some type of "session management".
438
321
  # ======================================================================= #
439
- if i.is_a? Array # Array tag
440
- if i.size > DELAY_IF_WE_HAVE_MORE_THAN_N_ENTRIES
441
- opnn; e 'More than '+simp(DELAY_IF_WE_HAVE_MORE_THAN_N_ENTRIES.to_s)+
442
- ' entries given ('+i.size.to_s+'), hence we will use a '\
443
- 'small delay (of '+sfancy(delay?.to_s)+' seconds).'
444
- end
445
- i.each {|entry|
446
- sleep delay? if i.size > DELAY_IF_WE_HAVE_MORE_THAN_N_ENTRIES # Small delay.
447
- try_to_open_this_file_in_the_editor(entry)
448
- }
449
- else
450
- # ===================================================================== #
451
- # Get rid of localhost-string parts next.
452
- # ===================================================================== #
453
- if i.include? 'localhost'
454
- i = replace_localhost_with_data(i)
455
- end unless File.exist? i
456
- # ===================================================================== #
457
- # Next, we chop off '?' characters. This is, however had, not good if
458
- # this is part of the filename. So we must check if the file exists,
459
- # prior to doing this check.
460
- # ===================================================================== #
461
- unless File.exist? i
462
- i = i[0..i.index('?')] if i.include? '?'
463
- end
464
- # ===================================================================== #
465
- # Get rid of '#' in the input, if it exists.
466
- # ===================================================================== #
467
- i = i[0..i.index('#')] if i.include? '#'
468
- case i
469
- when 'LAST' # Assign the last file.
470
- i = find_and_return_last_file
471
- end
472
- # ===================================================================== #
473
- # Next, act on the extension name.
474
- # ===================================================================== #
475
- _ = File.extname(i).delete('.').downcase
476
- case _ # case tag
477
- # ===================================================================== #
478
- # === open .pdf files
479
- # ===================================================================== #
480
- when 'pdf'
481
- open_in_pdf_viewer(i)
482
- # ===================================================================== #
483
- # === epub
484
- # ===================================================================== #
485
- when 'epub'
486
- esystem "okular #{i} &"
487
- # ===================================================================== #
488
- # === torrent
489
- # ===================================================================== #
490
- when 'torrent'
491
- open_this_torrent_file(i)
492
- # ===================================================================== #
493
- # === Extensions that can be opened in the editor
494
- # ===================================================================== #
495
- when *ARRAY_EXTENSIONS_THAT_CAN_BE_OPENED_IN_THE_EDITOR
496
- open_in_browser_or_in_editor(i)
497
- # ===================================================================== #
498
- # === All registered images
499
- # ===================================================================== #
500
- when *ARRAY_IMAGES
501
- open_in_gimp(i)
502
- # ===================================================================== #
503
- # === All libreoffice extensions
504
- # ===================================================================== #
505
- when *ARRAY_LIBREOFFICE_EXTENSIONS
506
- open_in_office(i)
322
+ i = File.absolute_path(i)
323
+ if File.exist? i
324
+ require 'pdf_paradise/main_pdf/main_pdf.rb'
325
+ require 'pdf_paradise/set_main_book.rb'
507
326
  # ===================================================================== #
508
- # === All videos
327
+ # Only enable the following on my home-system, and only in the
328
+ # books-subdirectory, and university-subdirectory.
509
329
  # ===================================================================== #
510
- when *ARRAY_VIDEOS
511
- play_multimedia_file(i)
512
- else
513
- if File.exist? i
514
- opnn; e "Not registered extension `#{sfancy(_)}`."
515
- opnn; e 'We will attempt to open it anyway though.'
516
- open_in_browser_or_in_editor(i)
517
- else # else we conclude that the file does not exist.
518
- no_file_was_found_at(i)
330
+ if is_on_roebe? and set_the_main_book?
331
+ case return_pwd
332
+ # =================================================================== #
333
+ # The following checks were explained above. We will also run
334
+ # rcfiles, and send pidof.
335
+ # =================================================================== #
336
+ when /^#{Regexp.quote('/home/x/books/')}/,
337
+ /^#{Regexp.quote('/home/x/studium/')}/
338
+ PdfParadise::SetMainBook.new(i)
339
+ run_rcfiles_then_run_ata_via_qdbus
519
340
  end
520
341
  end
342
+ PdfParadise.main_pdf(i) {{
343
+ open_via_fullscreen: open_via_fullscreen?
344
+ }}
345
+ register_this_pdf_file(i)
346
+ else
347
+ this_file_was_not_found(i)
521
348
  end
522
- end; alias consider_opening_the_given_input try_to_open_this_file_in_the_editor # === consider_opening_the_given_input
523
- alias open_in_editor try_to_open_this_file_in_the_editor # === open_in_editor
524
- alias open_these_files try_to_open_this_file_in_the_editor # === open_these_files
525
-
526
- # ========================================================================= #
527
- # === open_this_torrent_file
528
- # ========================================================================= #
529
- def open_this_torrent_file(i)
530
- if i.include?("'") and !i.include?('"')
531
- i = '"'+i+'"'
532
- end
533
- _ = "transmission #{i} &"
534
- esystem(_)
535
- end
536
-
537
- # ========================================================================= #
538
- # === try_to_find_files_based_on_hyphens_as_part_of_the_input
539
- #
540
- # This method will try to find files based on '::' input.'
541
- # ========================================================================= #
542
- def try_to_find_files_based_on_hyphens_as_part_of_the_input(i)
543
- if i.include? '::'
544
- # ===================================================================== #
545
- # In this case, replace '::', after passing it through the
546
- # snakecase() method.
547
- # ===================================================================== #
548
- i = snakecase_and_prepend_first_name_and_lib(i).tr('::','/')+'/'
549
- end
550
- unless i.start_with?('/home')
551
- # ===================================================================== #
552
- # We assume that only ruby files follow the '::' layout, for now. (Jun 2017)
553
- # ===================================================================== #
554
- i.prepend('$RUBY_SRC/')
555
- end
556
- if i.include? '$'
557
- i = convert_global_env(i)
558
- end
559
- i.squeeze!('/')
560
- unless i.end_with?('*')
561
- i << '*'
562
- end
563
- these_files = Dir[i]
564
- open_these_files(these_files)
565
- end
566
-
567
- # ========================================================================= #
568
- # === snakecase_and_prepend_first_name_and_lib
569
- #
570
- # This combines snakecase() by also prepending the first-name
571
- # and "lib/" prefix.
572
- # ========================================================================= #
573
- def snakecase_and_prepend_first_name_and_lib(i)
574
- if i.include? '::'
575
- splitted = i.split('::')
576
- first_name = splitted.first.downcase
577
- end
578
- i = snakecase(i)
579
- return first_name+'/lib/'+i
580
349
  end
581
350
 
582
351
  # ========================================================================= #
@@ -585,8 +354,7 @@ class Open < ::Open::Base # === Open::Open
585
354
  def register_this_pdf_file(what)
586
355
  begin
587
356
  require 'save_file'
588
- require 'roebe/constants/file_constants.rb'
589
- require 'roebe/constants/directory_constants.rb'
357
+ require 'roebe/constants/file_and_directory_constants.rb'
590
358
  rescue LoadError; end
591
359
  into = Roebe.file_these_pdf_files_were_opened
592
360
  old_dataset = nil
@@ -627,36 +395,17 @@ class Open < ::Open::Base # === Open::Open
627
395
  end
628
396
 
629
397
  # ========================================================================= #
630
- # === open_in_browser_or_in_editor
631
- #
632
- # This method was required because sometimes we wish to open in the
633
- # browser, and sometimes we wish to open in the editor.
398
+ # === return_this_file_here
634
399
  # ========================================================================= #
635
- def open_in_browser_or_in_editor(i)
636
- if i.include? '//'
637
- i = i.dup if i.frozen?
638
- i.squeeze!('/')
639
- end
640
- # ======================================================================= #
641
- # Next, we get the extension name.
642
- # ======================================================================= #
643
- _ = File.extname(File.basename(i)).delete '.'
644
- case _
645
- when 'html','php' # Open in both, in this case.
646
- do_open_in_editor(i)
647
- unless File.zero? i
648
- ::Open.in_browser(i) unless _.include? 'php'
649
- end
650
- else
651
- do_open_in_editor(i)
652
- end
653
- end
400
+ def return_this_file_here
401
+ __FILE__
402
+ end; alias this_file? return_this_file_here # === this_file?
654
403
 
655
404
  # ========================================================================= #
656
405
  # === open_in_gimp
657
406
  # ========================================================================= #
658
407
  def open_in_gimp(i)
659
- esystem "#{@image_editor} #{i}#{IN_BACKGROUND}"
408
+ esystem "#{@internal_hash[:image_editor_to_use]} #{i}#{IN_BACKGROUND}"
660
409
  end
661
410
 
662
411
  # ========================================================================= #
@@ -676,147 +425,277 @@ class Open < ::Open::Base # === Open::Open
676
425
  end
677
426
 
678
427
  # ========================================================================= #
679
- # === try_to_require_the_studium_project
428
+ # === open_via_fullscreen?
680
429
  # ========================================================================= #
681
- def try_to_require_the_studium_project
682
- unless Object.const_defined?(:Studium) and
683
- Studium.respond_to?(:include_this_exam_topic?)
684
- begin # We pull in only the relevant files from the Studium project.
685
- require 'studium/constants/constants.rb'
686
- require 'studium/toplevel_methods/find_exam_topic_and_exam_title.rb'
687
- require 'studium/toplevel_methods/is_this_exam_topic_included.rb'
688
- rescue LoadError
689
- if is_on_roebe?
690
- e 'The three files ('\
691
- 'studium/constants/constants.rb,'\
692
- 'studium/toplevel_methods/find_exam_topic_and_exam_title.rb and '\
693
- 'studium/toplevel_methods/is_this_exam_topic_included.rb '\
694
- 'forth) from the studium-project could not be loaded.'
695
- end
430
+ def open_via_fullscreen?
431
+ @internal_hash[:open_via_fullscreen]
432
+ end
433
+
434
+ # ========================================================================= #
435
+ # === joined_and_stripped_commandline_arguments
436
+ # ========================================================================= #
437
+ def joined_and_stripped_commandline_arguments
438
+ _ = commandline_arguments?.map {|entry|
439
+ if entry.is_a? Symbol
440
+ entry = ":#{entry}" # Symbols become "fake" symbols here, on purpose.
696
441
  end
442
+ entry
443
+ }
444
+ return _.join(' ').strip
445
+ end
446
+
447
+ # ========================================================================= #
448
+ # === set_open_these_elements
449
+ # ========================================================================= #
450
+ def set_open_these_elements(i)
451
+ @internal_hash[:open_these_elements] = [i].flatten.compact
452
+ end; alias set_input set_open_these_elements # === set_input
453
+ alias set_input_files set_open_these_elements # === set_input_files
454
+
455
+ # ========================================================================= #
456
+ # === play_multimedia_file
457
+ # ========================================================================= #
458
+ def play_multimedia_file(i)
459
+ esystem "#{USE_THIS_MPLAYER_COMMAND} #{i}" # open
460
+ end
461
+
462
+ # ========================================================================= #
463
+ # === can_be_opened_in_the_editor?
464
+ # ========================================================================= #
465
+ def can_be_opened_in_the_editor?(i)
466
+ _ = File.extname(i).delete('.')
467
+ ARRAY_EXTENSIONS_THAT_CAN_BE_OPENED_IN_THE_EDITOR.include?(i)
468
+ end
469
+
470
+ # ========================================================================= #
471
+ # === find_and_return_last_file
472
+ #
473
+ # This method will select all files from the current directory and
474
+ # add the ctime (into the Array). Then it will simply sort based
475
+ # the ctime, and return the first entry.
476
+ # ========================================================================= #
477
+ def find_and_return_last_file
478
+ array = Dir['*'].select {|entry| File.file? entry }
479
+ array.map! {|entry|
480
+ [entry, File.ctime(entry)]
481
+ }
482
+ result = array.sort_by {|entry| entry[1] }.reverse
483
+ result = result.first[0] # Return the first entry here.
484
+ return result
485
+ end
486
+
487
+ # ========================================================================= #
488
+ # === open_this_torrent_file
489
+ #
490
+ # This method will properly open a .torrent file - right now hardcoded
491
+ # towards the "transmission" application.
492
+ # ========================================================================= #
493
+ def open_this_torrent_file(i)
494
+ if i.include?("'") and !i.include?('"')
495
+ i = '"'+i+'"'
697
496
  end
497
+ _ = "transmission #{i} &"
498
+ esystem(_)
698
499
  end
699
500
 
700
501
  # ========================================================================= #
701
- # === do_open_in_editor
502
+ # === open_these_elements?
503
+ # ========================================================================= #
504
+ def open_these_elements?
505
+ @internal_hash[:open_these_elements]
506
+ end; alias input_files? open_these_elements? # === input_files?
507
+ alias input_file? open_these_elements? # === input_file?
508
+ alias input? open_these_elements? # === input?
509
+
510
+ # ========================================================================= #
511
+ # === remove_empty_entries
512
+ # ========================================================================= #
513
+ def remove_empty_entries
514
+ @internal_hash[:open_these_elements].reject! {|entry|
515
+ entry.nil? or entry.empty?
516
+ }
517
+ end
518
+
519
+ # ========================================================================= #
520
+ # === snakecase_and_prepend_first_name_and_lib
702
521
  #
703
- # This method will try to open the file via the specified (main)
704
- # editor. Since as of August 2019, this will also be logged into
705
- # a local file, if we are on a roebe-system.
522
+ # This combines snakecase() by also prepending the first-name
523
+ # and "lib/" prefix.
706
524
  # ========================================================================= #
707
- def do_open_in_editor(
708
- i, use_this_editor = @editor
709
- )
710
- if i.include? '//'
711
- i.squeeze!('/')
525
+ def snakecase_and_prepend_first_name_and_lib(i)
526
+ if i.include? '::'
527
+ splitted = i.split('::')
528
+ first_name = splitted.first.downcase
712
529
  end
713
- if Object.const_defined? :Roebe
714
- expanded_alias = Roebe::FindExpandedAlias.new(i) { :be_quiet }
715
- if expanded_alias.is_included?
716
- unless File.exist? i
717
- points_at = expanded_alias.points_at?
718
- if points_at.include?(';')
719
- splitted = points_at.split(';')
720
- if File.exist? splitted.first
721
- points_at = splitted.first
722
- end
723
- end
724
- opnn; e 'Making use of the aliased-pointer at'
725
- opnn; e ' `'+steelblue(points_at)+'`.'
726
- i = points_at
727
- end
728
- end
530
+ i = snakecase(i)
531
+ return first_name+'/lib/'+i
532
+ end
533
+
534
+ # ========================================================================= #
535
+ # === replace_localhost_with_data
536
+ # ========================================================================= #
537
+ def replace_localhost_with_data(i)
538
+ if i.include? 'programming'
539
+ return i.sub('localhost',HOME_DIRECTORY_OF_USER_X)
540
+ else
541
+ return i.sub('localhost',"#{HOME_DIRECTORY_OF_USER_X}data/")
729
542
  end
730
- i = rds(i) # Get rid of // again, just in case.
731
- # ======================================================================= #
732
- # Make an exception for .cpp files:
733
- # ======================================================================= #
734
- if (File.extname(i).delete('.') == 'cpp')
735
- if is_on_roebe? and ENV.has_key?('CPP_EDITOR')
736
- use_this_editor = ENV['CPP_EDITOR'].to_s.dup
737
- else
738
- use_this_editor = 'geany' # We use geany for cpp files.
739
- end
543
+ end
544
+
545
+ # ========================================================================= #
546
+ # === try_to_find_files_based_on_hyphens_as_part_of_the_input
547
+ #
548
+ # This method will try to find files based on '::' input.'
549
+ # ========================================================================= #
550
+ def try_to_find_files_based_on_hyphens_as_part_of_the_input(i)
551
+ if i.include? '::'
552
+ # ===================================================================== #
553
+ # In this case, replace '::', after passing it through the
554
+ # snakecase() method.
555
+ # ===================================================================== #
556
+ i = snakecase_and_prepend_first_name_and_lib(i).tr('::','/')+'/'
740
557
  end
741
- if i.include?("'") and !i.include?('"')
742
- i = '"'+i+'"'
558
+ unless i.start_with?('/home')
559
+ # ===================================================================== #
560
+ # We assume that only ruby files follow the '::' layout, for now. (Jun 2017)
561
+ # ===================================================================== #
562
+ i.prepend('$RUBY_SRC/')
743
563
  end
744
- if i.include? '('
745
- i = '"'+i+'"'
564
+ if i.include? '$'
565
+ i = convert_global_env(i)
746
566
  end
747
- _ = "#{use_this_editor} #{i}"
748
- esystem(_)
749
- if File.file?(i) and Object.const_defined?(:Roebe) and
750
- File.directory?(Roebe.log_dir?) and
751
- is_on_roebe?
752
- into = Roebe.log_dir?+'opened_files.yml'
753
- if File.exist? into
754
- array = YAML.load_file(into)
755
- else
756
- array = [into].flatten.compact
757
- end
758
- what = YAML.dump(array)
759
- SaveFile.write_what_into(what, into)
567
+ i.squeeze!('/')
568
+ unless i.end_with?('*')
569
+ i << '*'
760
570
  end
571
+ these_files = Dir[i]
572
+ open_these_files(these_files)
761
573
  end
762
574
 
763
575
  # ========================================================================= #
764
- # === run_rcfiles_then_run_ata_via_qdbus
576
+ # === is_bluefish_running?
765
577
  # ========================================================================= #
766
- def run_rcfiles_then_run_ata_via_qdbus
767
- require 'rcfiles'
768
- Rcfiles.run
769
- esystem 'qdbus org.kde.konsole-`pidof -s konsole` /Sessions/2 runCommand "ata"'
770
- esystem 'qdbus org.kde.konsole-`pidof -s konsole` /Sessions/3 runCommand "ata"'
771
- esystem 'qdbus org.kde.konsole-`pidof -s konsole` /Sessions/4 runCommand "ata"'
578
+ def is_bluefish_running?
579
+ `ps ax | grep bluefish`.split("\n").reject {|entry|
580
+ entry.include? 'grep'
581
+ }.size > 0
772
582
  end
773
583
 
774
584
  # ========================================================================= #
775
- # === open_in_pdf_viewer (pdf tag)
585
+ # === start_bluefish
776
586
  #
777
- # This method can be used to open a .pdf file. We will let the project
778
- # PdfParadise handle this situation.
587
+ # This method can be used to start the bluefish-editor.
588
+ # ========================================================================= #
589
+ def start_bluefish
590
+ esystem 'bluefish &'
591
+ end
592
+
593
+ # ========================================================================= #
594
+ # === check_whether_the_user_has_provided_any_input
595
+ # ========================================================================= #
596
+ def check_whether_the_user_has_provided_any_input
597
+ _ = input_files?
598
+ local_files = Dir['*'].select {|entry| File.file? entry }
599
+ if _.empty? and !local_files.empty? and (local_files.size == 1)
600
+ # ===================================================================== #
601
+ # Handle the case where no specific input was given, but only
602
+ # one file exists in the local directory.
603
+ # ===================================================================== #
604
+ set_input_files(local_files.first)
605
+ _ = input_files?
606
+ end
607
+ if _.empty?
608
+ if is_on_roebe? and !is_bluefish_running?
609
+ opne 'Starting bluefish now, as we are on a roebe-system and'
610
+ opne 'bluefish is currently not running.'
611
+ start_bluefish
612
+ else
613
+ opne tomato('Please provide at the least one argument - the '\
614
+ 'file you wish to open.')
615
+ exit
616
+ end
617
+ end
618
+ end
619
+
620
+ # ========================================================================= #
621
+ # === general_open_functionality
779
622
  #
780
- # Since as of 19.09.2018 we will keep a log of the opened .pdf files
781
- # if we are on roebe. This can then be used to determine which were
782
- # the last .pdf files that were read.
623
+ # This method will act based on the extension name of the file usually -
624
+ # or, if not applicable, it will simply open this in the default,
625
+ # designated editor.
783
626
  # ========================================================================= #
784
- def open_in_pdf_viewer(i)
785
- require 'pdf_paradise' unless Object.const_defined? :PdfParadise
627
+ def general_open_functionality(i)
628
+ extname = File.extname(i).delete('.').downcase
629
+ case extname # case tag
786
630
  # ======================================================================= #
787
- # Since as of April 2022 we will use the absolute path to the .pdf
788
- # file at hand. The reason for this is because this makes it easier
789
- # to know which files are open, and we can store these file paths
790
- # into a local file (such as a .yml file), and then use this at a
791
- # later time to restore all .pdf files that were open. This thus
792
- # constitutes some type of "session management".
631
+ # === Extensions that can be opened in the editor
793
632
  # ======================================================================= #
794
- i = File.absolute_path(i)
795
- if File.exist? i
796
- require 'pdf_paradise/main_pdf/main_pdf.rb'
797
- require 'pdf_paradise/set_main_book.rb'
798
- # ===================================================================== #
799
- # Only enable the following on my home-system, and only in the
800
- # books-subdirectory, and university-subdirectory.
801
- # ===================================================================== #
802
- if is_on_roebe? and set_the_main_book?
803
- case return_pwd
804
- # =================================================================== #
805
- # The following checks were explained above. We will also run
806
- # rcfiles, and send pidof.
807
- # =================================================================== #
808
- when /^#{Regexp.quote('/home/x/books/')}/,
809
- /^#{Regexp.quote('/home/x/studium/')}/
810
- PdfParadise::SetMainBook.new(i)
811
- run_rcfiles_then_run_ata_via_qdbus
812
- end
633
+ when *ARRAY_EXTENSIONS_THAT_CAN_BE_OPENED_IN_THE_EDITOR
634
+ open_in_browser_or_in_editor(i)
635
+ # ======================================================================= #
636
+ # === torrent
637
+ # ======================================================================= #
638
+ when 'torrent'
639
+ open_this_torrent_file(i)
640
+ # ======================================================================= #
641
+ # === All registered images
642
+ # ======================================================================= #
643
+ when *ARRAY_IMAGES
644
+ open_in_gimp(i)
645
+ # ======================================================================= #
646
+ # === All libreoffice extensions
647
+ # ======================================================================= #
648
+ when *ARRAY_LIBREOFFICE_EXTENSIONS
649
+ open_in_office(i)
650
+ # ======================================================================= #
651
+ # === epub
652
+ # ======================================================================= #
653
+ when 'epub'
654
+ esystem "okular #{i} &"
655
+ # ======================================================================= #
656
+ # === open .pdf files
657
+ # ======================================================================= #
658
+ when 'pdf'
659
+ open_in_pdf_viewer(i)
660
+ # ======================================================================= #
661
+ # === All videos will enter here
662
+ # ======================================================================= #
663
+ when *ARRAY_VIDEOS
664
+ play_multimedia_file(i)
665
+ else
666
+ if File.exist? i
667
+ opne "Not registered extension `#{sfancy(i)}`."
668
+ opne 'We will attempt to open it anyway though.'
669
+ open_in_browser_or_in_editor(i)
670
+ else # else we conclude that the file does not exist.
671
+ no_file_was_found_at(i)
672
+ end
673
+ end
674
+ end; alias try_to_open_this_file_in_the_editor general_open_functionality # === try_to_open_this_file_in_the_editor
675
+
676
+ # ========================================================================= #
677
+ # === open_in_browser_or_in_editor
678
+ #
679
+ # This method was required because sometimes we wish to open in the
680
+ # browser, and sometimes we wish to open in the editor.
681
+ # ========================================================================= #
682
+ def open_in_browser_or_in_editor(i)
683
+ if i.include? '//'
684
+ i = i.dup if i.frozen?
685
+ i = rds(i)
686
+ end
687
+ # ======================================================================= #
688
+ # Next, we get the extension name.
689
+ # ======================================================================= #
690
+ _ = File.extname(File.basename(i)).delete '.'
691
+ case _
692
+ when 'html','php' # Open in both, editor and browser, in this case.
693
+ do_open_in_editor(i)
694
+ unless File.zero? i
695
+ ::Open.in_browser(i) unless _.include? 'php'
813
696
  end
814
- PdfParadise.main_pdf(i) {{
815
- open_via_fullscreen: @open_via_fullscreen
816
- }}
817
- register_this_pdf_file(i)
818
697
  else
819
- this_file_was_not_found(i)
698
+ do_open_in_editor(i)
820
699
  end
821
700
  end
822
701
 
@@ -837,79 +716,135 @@ class Open < ::Open::Base # === Open::Open
837
716
  end
838
717
 
839
718
  # ========================================================================= #
840
- # === show_help (help tag)
719
+ # === run_rcfiles_then_run_ata_via_qdbus
841
720
  # ========================================================================= #
842
- def show_help
843
- opnn; e 'The following options are available:'
844
- e
845
- ecomment ' SELF # Open this .rb file here.'
846
- ecomment ' --use-this-browser=firefox # Assign a new browser, in this case firefox.'
847
- ecomment ' --browser? # '\
848
- 'Show which browser is the currently assigned one.'
849
- e
721
+ def run_rcfiles_then_run_ata_via_qdbus
722
+ require 'rcfiles'
723
+ Rcfiles.run
724
+ esystem 'qdbus org.kde.konsole-`pidof -s konsole` /Sessions/2 runCommand "ata"'
725
+ esystem 'qdbus org.kde.konsole-`pidof -s konsole` /Sessions/3 runCommand "ata"'
726
+ esystem 'qdbus org.kde.konsole-`pidof -s konsole` /Sessions/4 runCommand "ata"'
850
727
  end
851
728
 
852
729
  # ========================================================================= #
853
- # === menu (menu tag)
730
+ # === sanitize_the_commandline_arguments
854
731
  # ========================================================================= #
855
- def menu(
856
- i = input?
857
- )
858
- if i.is_a? Array
859
- i.each {|entry| menu(entry) }
860
- else
861
- case i # (case tag)
732
+ def sanitize_the_commandline_arguments
733
+ @commandline_arguments.flatten!
734
+ @commandline_arguments.map! {|entry|
735
+ case entry
736
+ when '*'
737
+ entry = Dir['*']
738
+ end
739
+ entry
740
+ }
741
+ @commandline_arguments.flatten!
742
+ end
743
+
744
+ # ========================================================================= #
745
+ # === run (run tag)
746
+ # ========================================================================= #
747
+ def run
748
+ sanitize_the_commandline_arguments
749
+ # @internal_hash[:open_these_elements] << joined_and_stripped_commandline_arguments
750
+ @internal_hash[:open_these_elements] << commandline_arguments_without_hyphens
751
+ remove_empty_entries
752
+ check_whether_the_user_has_provided_any_input
753
+ try_to_require_the_studium_project
754
+ try_to_require_the_beautiful_url_project
755
+ menu # Now we can pass this into the main menu here.
756
+ array = [@internal_hash[:open_these_elements]].flatten.compact
757
+ array.each {|_|
758
+ _ = _.to_s.dup # Always work on a String-copy past this point.
759
+ # ===================================================================== #
760
+ # Check whether the input includes the ':' character - but this may
761
+ # have two different use cases. The first one is to check for a
762
+ # shortcut entry; the second will just ignore the part after ':'.
763
+ # ===================================================================== #
764
+ if _.start_with? ':'
765
+ open_in_editor(_)
766
+ return
767
+ end
768
+ if _.include?(':') and
769
+ !File.exist?(_) and
770
+ File.exist?(_.split(':').first.to_s)
771
+ _ = _.split(':').first.to_s
772
+ end
862
773
  # ===================================================================== #
863
- # === open --browser?
774
+ # Next, we handle input such as:
775
+ #
776
+ # 'lib/lpc/requires/basic_requires.rb:begin'
777
+ #
778
+ # This evidently does not end with a ':' character, but it clearly
779
+ # has a fairly useless ':' component in it. If that is the case,
780
+ # we will treat this as input that is only valid up towards the
781
+ # very right ':', anchored on the '.rb:' part.
864
782
  # ===================================================================== #
865
- when /^-?-?browser\??$/
866
- _ = YAML.load_file(::Open.file_browser?)
867
- e 'The browser currently in use is `'+sfancy(_)+'`.'
868
- exit
783
+ if _.include? '.rb:'
784
+ # =================================================================== #
785
+ # The following code means to find the index at '.rb:' and then add
786
+ # 2 to it - this should be the correct name of the entry at hand.
787
+ # =================================================================== #
788
+ _ = _[0 .. (_.index('.rb:')+2)]
789
+ end
790
+ unless File.exist? _
791
+ _.chop! if _.end_with? '#' # Don't need trailing '#' tokens.
792
+ _.chop! if _.end_with? ':-' # ← This check must come before the check against ':'.
793
+ _.chop! if _.end_with? ':' # Chop off trailing ':' tokens.
794
+ _.chop! if _.end_with? ';' # Chop off trailing ':' tokens.
795
+ _.delete_prefix!('http:') if _.start_with?('http:')
796
+ end
797
+ case _
869
798
  # ===================================================================== #
870
- # === open --use-this-browser=firefox
799
+ # === open ME
871
800
  # ===================================================================== #
872
- when /^-?-?use(-|_)?this(-|_)?browser=(.+)/
873
- ::Open.permanently_use_this_browser = $3.to_s.dup
801
+ when 'ME',
802
+ 'SELF',
803
+ 'ALL',/
804
+ ^-?-?this(_|-)?file/
805
+ open_this_file_here
874
806
  exit
807
+ end unless File.exist?(_)
808
+ _.delete!('^') if _.include?('^')
809
+ if _.end_with?('.') and File.exist?(_[0..-2])
810
+ # =================================================================== #
811
+ # This clause will be entered if we have input something like
812
+ # "colours.rb." where the user may have wanted to type in
813
+ # "colours.rb" - and IF the file exists.
814
+ # =================================================================== #
815
+ opne "Assuming a superfluous trailing '.', so removing "\
816
+ "the last '.' there."
817
+ _.chop!
875
818
  end
876
- end
877
- end
878
-
879
- # ========================================================================= #
880
- # === try_to_require_the_beautiful_url_project
881
- # ========================================================================= #
882
- def try_to_require_the_beautiful_url_project
883
- unless Object.const_defined? :BeautifulUrl
884
- begin
885
- require 'roebe/requires/failsafe_require_of_beautiful_url.rb'
886
- rescue LoadError; end
887
- end
888
- end
889
-
890
- # ========================================================================= #
891
- # === run_everything
892
- # ========================================================================= #
893
- def run_everything
894
- input_files = input_files?.flatten
895
- # ======================================================================= #
896
- # Iterate over all input files that were passed to us.
897
- # ======================================================================= #
898
- input_files.each {|this_file|
899
819
  # ===================================================================== #
900
- # Check whether the input includes the ':' character:
820
+ # Split away at '::' if this is part of that substring.
901
821
  # ===================================================================== #
902
- if this_file.include?(':') and !File.exist?(this_file) and
903
- File.exist?(this_file.split(':').first.to_s)
904
- this_file = this_file.split(':').first.to_s
822
+ if _.include? '::'
823
+ splitted = _.split('::')
824
+ _ = splitted.last
905
825
  end
906
- if this_file.start_with?('http:') and !File.exist?(this_file)
907
- this_file.delete_prefix!('http:')
826
+ # ===================================================================== #
827
+ # === Get rid of localhost-string parts next.
828
+ #
829
+ # Get rid of the String "localhost" next. This must be handled with
830
+ # more care, because some files may include the string 'localhost' as
831
+ # part of their name, such as 'remove_localhost.rb'. In this case,
832
+ # we will additionally check whether the file exists.
833
+ # ===================================================================== #
834
+ if _.is_a?(String) and _.include?('localhost')
835
+ unless File.exist? _ # See the above header for an explanation.
836
+ _ = replace_localhost_with_data(_)
837
+ end
838
+ end
839
+ case _
840
+ when 'LAST' # Assign the last file.
841
+ _ = find_and_return_last_file
908
842
  end
909
843
  # ===================================================================== #
910
- # === Query whether the file exists or whether it does not
844
+ # If the file exists, enter here first - thus, we will query whether
845
+ # the file exists or whether it does not.
911
846
  # ===================================================================== #
912
- if File.exist?(this_file) # This is the simplest way - the file exists here.
847
+ if File.exist? _ # This is the simplest way - the file exists here.
913
848
  # =================================================================== #
914
849
  # However had, in December 2022 it was noticed that a file such
915
850
  # as "curricula.yml" may exist, as well as a directory called
@@ -917,86 +852,91 @@ class Open < ::Open::Base # === Open::Open
917
852
  # curricula.yml rather than curricula/. So, what to do in this
918
853
  # case? Well - we will do a minimal glob, that is, if a file
919
854
  # exists as described above, then we will prioritize this over
920
- # the directory name.
855
+ # the directory name and immediately open it.
921
856
  # =================================================================== #
922
- if File.directory?(this_file) and !File.file?(this_file) and
923
- (Dir[this_file+'*'].size > 0)
924
- this_file = Dir[this_file+'.*'].first.to_s # Pick a real file in this case.
857
+ if File.directory?(_) and !File.file?(_) and
858
+ (Dir["#{_}*"].size > 0)
859
+ _ = Dir["#{_}*"].first.to_s # Pick a real file in this case.
925
860
  end
926
- try_to_open_this_file_in_the_editor(this_file)
927
- else # Ok, the file was not instantly found. Run more checks here.
928
- possible_matches = Dir[('*'+this_file+'*').squeeze('*')] # This may be an empty Array as well.
861
+ general_open_functionality(_)
862
+ # ===================================================================== #
863
+ # === Check whether the input is an exam-question next
864
+ #
865
+ # This check should come before we delegate towards FindExpandedAlias.
866
+ #
867
+ # Invocation example:
868
+ #
869
+ # open ab2
870
+ #
871
+ # ===================================================================== #
872
+ elsif Object.const_defined?(:Studium) and
873
+ ::Studium.respond_to?(:include_this_exam_topic?) and
874
+ ::Studium.respond_to?(:find_corresponding_exam_topic) and
875
+ ::Studium.include_this_exam_topic?(_) # open ab2
876
+ _ = ::Studium.find_corresponding_exam_topic(
877
+ ::Studium.find_corresponding_exam_topic(_),
878
+ :be_quiet
879
+ ) # This can be false.
880
+ if _
881
+ if is_on_roebe?
882
+ _ = Studium.my_exam_topics_directory?+File.basename(_)
883
+ else
884
+ _ = Studium.exam_topics_directory?+File.basename(_)
885
+ end
886
+ open_in_editor(_)
887
+ end
888
+ # ===================================================================== #
889
+ # === Query whether BeautifulUrl includes this file.
890
+ # ===================================================================== #
891
+ elsif BeautifulUrl.does_include?(_) # open linux
892
+ _ = beautiful_url(_)
893
+ consider_opening_the_given_input(_) # Then try again.
894
+ # ===================================================================== #
895
+ # Ok, the following else-clauses handle the situation
896
+ # that the given input could not be found.
897
+ # ===================================================================== #
898
+ elsif _.include? 'project_'
899
+ do_open_in_editor(_)
900
+ else
901
+ possible_matches = Dir[('*'+_+'*').squeeze('*')] # ← This may be an empty Array as well.
929
902
  # =================================================================== #
930
903
  # Since as of Jan 2018, if the variable possible_matches is NOT
931
904
  # empty, we will sort it in a way so that the shorter file names
932
- # are on top of the array.
905
+ # are on top of the array. See the following clause for that.
933
906
  # =================================================================== #
934
907
  unless possible_matches.empty?
935
908
  possible_matches = possible_matches.sort_by {|entry| entry.size }
936
909
  end
937
910
  # =================================================================== #
938
- # === Check whether the input is an exam-question next
939
- #
940
- # This check should come before we delegate towards FindExpandedAlias.
941
- # =================================================================== #
942
- if Object.const_defined?(:Studium) and
943
- ::Studium.respond_to?(:include_this_exam_topic?) and
944
- ::Studium.respond_to?(:find_corresponding_exam_topic) and
945
- ::Studium.include_this_exam_topic?(this_file) # open ab2
946
- _ = ::Studium.find_corresponding_exam_topic(
947
- ::Studium.find_corresponding_exam_topic(this_file),
948
- :be_quiet
949
- ) # This can be false.
950
- if _
951
- if is_on_roebe?
952
- _ = Studium.my_exam_topics_directory?+File.basename(_)
953
- else
954
- _ = Studium.exam_topics_directory?+File.basename(_)
955
- end
956
- open_in_editor(_)
957
- end
911
+ # At the least one entry has been found in the next case.
958
912
  # =================================================================== #
959
- # === Query whether BeautifulUrl includes this file.
960
- # =================================================================== #
961
- elsif BeautifulUrl.does_include?(this_file) # open linux
962
- _ = beautiful_url(this_file)
963
- consider_opening_the_given_input(_) # Then try again.
964
- # =================================================================== #
965
- # Ok, the following else-clauses handle the situation
966
- # that the given input could not be found.
967
- # =================================================================== #
968
- elsif this_file.include? 'project_'
969
- do_open_in_editor(this_file)
970
- # =================================================================== #
971
- # At the least one entry has been found.
972
- # =================================================================== #
973
- elsif ((_ = possible_matches).size > 0) # If we can find at least one entry.
974
- consider_opening_the_given_input(_.first) # Recursive call.
913
+ if (possible_matches.size > 0) # If we can find at least one entry.
914
+ consider_opening_the_given_input(possible_matches.first) # Recursive call here.
975
915
  # =================================================================== #
976
916
  # Same as above, but both prepend and append a '*' character.
977
917
  # =================================================================== #
978
- elsif ((_ = possible_matches).size > 0) # If we can find at least one entry.
979
- consider_opening_the_given_input(_.first)
918
+ elsif (possible_matches.size > 0) # If we can find at least one entry.
919
+ consider_opening_the_given_input(possible_matches.first)
980
920
  # =================================================================== #
981
921
  # Next, try to pass it through class Roebe::FindExpandedAlias.
982
922
  # =================================================================== #
983
- elsif File.exist?(_ = Roebe.find_expanded_alias(this_file).to_s)
984
- open_in_editor(_)
923
+ elsif File.exist?(more_matches = Roebe.find_expanded_alias(_).to_s)
924
+ open_in_editor(more_matches)
985
925
  # =================================================================== #
986
926
  # Next, try to handle input containing two ':' tokens.
987
927
  # =================================================================== #
988
- elsif this_file.include?('::')
989
- try_to_find_files_based_on_hyphens_as_part_of_the_input(this_file)
928
+ elsif _.include?('::')
929
+ try_to_find_files_based_on_hyphens_as_part_of_the_input(_)
990
930
  # =================================================================== #
991
931
  # Use RUBY_SRC as shortcut on my home system.
992
932
  # =================================================================== #
993
933
  elsif is_on_roebe? and
994
- File.exist?(return_assumed_path_to_ruby_src_lib_of(this_file))
995
- use_this_file_instead = return_assumed_path_to_ruby_src_lib_of(this_file)
996
- e rev+'Since we are on roebe, we will use another path, aka'
997
- e
998
- e " #{steelblue(use_this_file_instead)}"
999
- e
934
+ File.exist?(return_assumed_path_to_ruby_src_lib_of(_))
935
+ use_this_file_instead = return_assumed_path_to_ruby_src_lib_of(_)
936
+ opne "#{rev}Since we are on roebe, we will use another path, aka"
937
+ opne
938
+ opne " #{steelblue(use_this_file_instead)}"
939
+ opne
1000
940
  open_in_editor(use_this_file_instead)
1001
941
  # =================================================================== #
1002
942
  # === Check for aliases next
@@ -1004,30 +944,29 @@ class Open < ::Open::Base # === Open::Open
1004
944
  # Next, try to find an expanded alias here.
1005
945
  # =================================================================== #
1006
946
  elsif Roebe.const_defined?(:FindExpandedAlias) and
1007
- (::Roebe::FindExpandedAlias[this_file] != this_file)
1008
- do_open_in_editor(this_file)
947
+ (::Roebe::FindExpandedAlias[_] != _)
948
+ do_open_in_editor(_)
1009
949
  else
1010
- opnn; e 'No match could be found for `'+sfancy(this_file)+'`.'
950
+ # ================================================================= #
951
+ # Alright - the file was not found via the above checks, so we
952
+ # will simply delegate towards Open.in_browser() next.
953
+ # ================================================================= #
954
+ # Or we could notify the user that no entry was found:
955
+ # opne "No match could be found for `#{sfancy(_)}`."
956
+ # ================================================================= #
957
+ ::Open.in_browser(_)
1011
958
  end
1012
959
  end
1013
960
  }
1014
961
  end
1015
962
 
1016
- # ========================================================================= #
1017
- # === run (run tag)
1018
- # ========================================================================= #
1019
- def run
1020
- check_whether_the_user_has_provided_any_input
1021
- try_to_require_the_studium_project
1022
- try_to_require_the_beautiful_url_project
1023
- menu
1024
- run_everything
1025
- end
1026
-
1027
963
  # ========================================================================= #
1028
964
  # === Open::Open[]
1029
965
  # ========================================================================= #
1030
- def self.[](i = ARGV, &block)
966
+ def self.[](
967
+ i = ARGV,
968
+ &block
969
+ )
1031
970
  new(i, &block) # Always delegate here.
1032
971
  end
1033
972
 
@@ -1036,15 +975,20 @@ end
1036
975
  # =========================================================================== #
1037
976
  # === Open.open
1038
977
  # =========================================================================== #
1039
- def self.open(i = ARGV, &block)
978
+ def self.open(
979
+ i = ARGV, &block
980
+ )
1040
981
  ::Open::Open.new(i, &block)
1041
982
  end; self.instance_eval { alias [] open } # === Open[]
1042
983
 
1043
984
  # =========================================================================== #
1044
985
  # === Open.pdf_viewer?
986
+ #
987
+ # This method can be used to query the pdf-viewer in use.
1045
988
  # =========================================================================== #
1046
989
  def self.pdf_viewer?
1047
- unless (Object.const_defined?(:PdfParadise) and PdfParadise.const_defined?(:MainPdf))
990
+ unless (Object.const_defined?(:PdfParadise) and
991
+ PdfParadise.const_defined?(:MainPdf))
1048
992
  require 'pdf_paradise/main_pdf/main_pdf.rb'
1049
993
  end
1050
994
  return ::PdfParadise.use_which_pdf_viewer?
@@ -1054,4 +998,4 @@ end
1054
998
 
1055
999
  if __FILE__ == $PROGRAM_NAME
1056
1000
  Open::Open.new(ARGV)
1057
- end # open
1001
+ end # ruby open.rb local_ginger