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.
- checksums.yaml +4 -4
- data/README.md +73 -9
- data/bin/open +1 -1
- data/bin/open_in_browser +1 -1
- data/doc/README.gen +72 -8
- data/doc/deprecated_code/deprecated_code.md +26 -0
- data/img/open_logo.png +0 -0
- data/lib/open/base/base.rb +262 -122
- data/lib/open/books/README.md +8 -0
- data/lib/open/books/books.rb +99 -0
- data/lib/open/constants/constants.rb +85 -8
- data/lib/open/in_browser/in_browser.rb +476 -304
- data/lib/open/in_editor/in_editor.rb +348 -155
- data/lib/open/last/last.rb +14 -12
- data/lib/open/nano_open/nano_open.rb +4 -3
- data/lib/open/{open.rb → open/open.rb} +597 -653
- data/lib/open/project/project.rb +3 -2
- data/lib/open/requires/failsafe_require_of_beautiful_url.rb +9 -0
- data/lib/open/requires/require_the_project.rb +2 -2
- data/lib/open/requires/require_yaml.rb +13 -0
- data/lib/open/these_files/these_files.rb +1 -1
- data/lib/open/toplevel_methods/browser.rb +71 -0
- data/lib/open/toplevel_methods/delay.rb +23 -0
- data/lib/open/toplevel_methods/e.rb +14 -0
- data/lib/open/toplevel_methods/editor.rb +41 -0
- data/lib/open/toplevel_methods/host_os.rb +25 -0
- data/lib/open/toplevel_methods/is_on_roebe.rb +16 -0
- data/lib/open/toplevel_methods/is_on_windows.rb +26 -0
- data/lib/open/toplevel_methods/misc.rb +50 -0
- data/lib/open/version/version.rb +2 -2
- data/lib/open/with_delay/with_delay.rb +9 -11
- data/open.gemspec +1 -1
- data/test/testing_open.rb +1 -1
- data/test/testing_open_in_browser.rb +16 -0
- data/test/testing_open_via_launchy.rb +3 -0
- data/test/testing_shortcuts.rb +3 -0
- metadata +24 -8
- data/lib/open/toplevel_code/toplevel_code.rb +0 -189
@@ -6,12 +6,16 @@
|
|
6
6
|
#
|
7
7
|
# This class can specifically be used to open a local file via your
|
8
8
|
# favourite editor. This is admittedly more useful for GUI-based editors
|
9
|
-
# such as "geany" or "gedit" than, say, "vim" or "nano".
|
9
|
+
# such as "geany" or "gedit" than, say, "vim" or "nano". Nonetheless
|
10
|
+
# I also use this class as base-class for class Open::NanoOpen - that is,
|
11
|
+
# opening a local file via the nano editor.
|
10
12
|
#
|
11
|
-
# If the file was not found, and BeautifulUrl is available, then
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# "
|
13
|
+
# If the file at hand was not found, and BeautifulUrl is available, then this
|
14
|
+
# class will tap into the functionality made available by BeautifulUrl, in
|
15
|
+
# order to see whether that leads to a file that can be found. If the file
|
16
|
+
# can not be found then "dfind" will be tried, as last attempt, which in
|
17
|
+
# turn is based on "locate / updatedb" - so it only works on Linux systems
|
18
|
+
# really or some UNIX-variants.
|
15
19
|
#
|
16
20
|
# Usage example:
|
17
21
|
#
|
@@ -33,12 +37,20 @@ class InEditor < Base # === Open::InEditor
|
|
33
37
|
# The first argument should be the name of the file that we wish to open.
|
34
38
|
# ========================================================================= #
|
35
39
|
def initialize(
|
36
|
-
|
37
|
-
run_already
|
40
|
+
commandline_arguments = ARGV,
|
41
|
+
run_already = true
|
38
42
|
)
|
39
43
|
register_sigint
|
40
44
|
reset
|
41
|
-
|
45
|
+
commandline_arguments = [commandline_arguments].flatten.compact
|
46
|
+
set_commandline_arguments(
|
47
|
+
commandline_arguments
|
48
|
+
)
|
49
|
+
set_work_on_these_files(
|
50
|
+
commandline_arguments.reject {|entry|
|
51
|
+
entry.start_with?('--')
|
52
|
+
}
|
53
|
+
)
|
42
54
|
# ======================================================================= #
|
43
55
|
# === Handle blocks next
|
44
56
|
# ======================================================================= #
|
@@ -61,7 +73,7 @@ class InEditor < Base # === Open::InEditor
|
|
61
73
|
# =================================================================== #
|
62
74
|
if yielded.has_key? :this_file
|
63
75
|
_ = yielded[:this_file]
|
64
|
-
|
76
|
+
set_work_on_these_files(_)
|
65
77
|
end
|
66
78
|
end
|
67
79
|
end
|
@@ -73,154 +85,361 @@ class InEditor < Base # === Open::InEditor
|
|
73
85
|
# ========================================================================= #
|
74
86
|
def reset
|
75
87
|
super()
|
88
|
+
infer_the_namespace
|
89
|
+
# ======================================================================= #
|
90
|
+
# === @internal_hash
|
91
|
+
# ======================================================================= #
|
92
|
+
reset_the_internal_hash
|
76
93
|
# ======================================================================= #
|
77
|
-
# ===
|
94
|
+
# === :use_this_editor
|
78
95
|
# ======================================================================= #
|
79
|
-
|
96
|
+
set_use_this_editor(:use_the_default_editor_from_the_yaml_file)
|
97
|
+
# ======================================================================= #
|
98
|
+
# === :work_on_these_files
|
99
|
+
#
|
100
|
+
# This variable must be nil initially.
|
101
|
+
# ======================================================================= #
|
102
|
+
@internal_hash[:work_on_these_files] = nil
|
80
103
|
end
|
81
104
|
|
105
|
+
# ========================================================================= #
|
106
|
+
# === start_the_editor_in_the_background
|
107
|
+
# ========================================================================= #
|
108
|
+
def start_the_editor_in_the_background
|
109
|
+
system "#{use_which_editor?} &"
|
110
|
+
end; alias start_editor_in_background start_the_editor_in_the_background # === start_editor_in_background
|
111
|
+
|
112
|
+
# ========================================================================= #
|
113
|
+
# === set_work_on_these_files
|
114
|
+
#
|
115
|
+
# The variable has to be an Array at all times.
|
116
|
+
# ========================================================================= #
|
117
|
+
def set_work_on_these_files(i)
|
118
|
+
i = [i].flatten.compact.reject {|entry| entry.start_with?('--') }
|
119
|
+
@internal_hash[:work_on_these_files] = i
|
120
|
+
end; alias set_work_on_this_file set_work_on_these_files # === set_work_on_this_file
|
121
|
+
|
122
|
+
# ========================================================================= #
|
123
|
+
# === work_on_these_files?
|
124
|
+
# ========================================================================= #
|
125
|
+
def work_on_these_files?
|
126
|
+
@internal_hash[:work_on_these_files]
|
127
|
+
end; alias work_on_this_file? work_on_these_files? # === work_on_this_file?
|
128
|
+
alias input? work_on_these_files? # === input?
|
129
|
+
|
130
|
+
# ========================================================================= #
|
131
|
+
# === try_to_find_expanded_alias_for
|
132
|
+
#
|
133
|
+
# We delegate towards FindExpandedAlias here.
|
134
|
+
# ========================================================================= #
|
135
|
+
def try_to_find_expanded_alias_for(i)
|
136
|
+
result = false # Default return value.
|
137
|
+
if i and i.include?('$')
|
138
|
+
i = sanitize_global_environment(i)
|
139
|
+
end
|
140
|
+
if i.include? ' ' # For instance, when it includes a ' &'
|
141
|
+
i = i[0, i.index(' ')]
|
142
|
+
end if i
|
143
|
+
if Object.const_defined?(:Roebe) and
|
144
|
+
Roebe.const_defined?(:FindExpandedAlias)
|
145
|
+
expanded_alias = Roebe::FindExpandedAlias.new(i) { :be_quiet }
|
146
|
+
if expanded_alias.does_include?(i)
|
147
|
+
result = true
|
148
|
+
end
|
149
|
+
end
|
150
|
+
return result
|
151
|
+
end
|
152
|
+
|
82
153
|
# ========================================================================= #
|
83
154
|
# === use_this_editor?
|
84
155
|
# ========================================================================= #
|
85
156
|
def use_this_editor?
|
86
|
-
@use_this_editor
|
87
|
-
end; alias editor?
|
157
|
+
@internal_hash[:use_this_editor]
|
158
|
+
end; alias editor? use_this_editor? # === editor?
|
159
|
+
alias use_which_editor? use_this_editor? # === use_which_editor?
|
160
|
+
|
161
|
+
# ========================================================================= #
|
162
|
+
# === set_editor
|
163
|
+
# ========================================================================= #
|
164
|
+
def set_editor(
|
165
|
+
i = :use_the_default_editor_from_the_yaml_file
|
166
|
+
)
|
167
|
+
case i
|
168
|
+
# ======================================================================= #
|
169
|
+
# === :use_the_default_editor_from_the_yaml_file
|
170
|
+
# ======================================================================= #
|
171
|
+
when :use_the_default_editor_from_the_yaml_file
|
172
|
+
i = file_load_default_editor?
|
173
|
+
end
|
174
|
+
@internal_hash[:use_this_editor] = i
|
175
|
+
end; alias editor= set_editor # === editor=
|
176
|
+
alias set_use_this_editor set_editor # === set_use_this_editor
|
88
177
|
|
89
178
|
# ========================================================================= #
|
90
|
-
# ===
|
179
|
+
# === do_save_this_file_into_a_local_yaml_file
|
180
|
+
#
|
181
|
+
# Since as of August 2019, this will also be logged into a local file,
|
182
|
+
# if we are on a roebe-system.
|
91
183
|
# ========================================================================= #
|
92
|
-
def
|
93
|
-
if
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
184
|
+
def do_save_this_file_into_a_local_yaml_file(i)
|
185
|
+
if File.file?(i) and
|
186
|
+
Object.const_defined?(:Roebe) and
|
187
|
+
File.directory?(Roebe.log_dir?) and
|
188
|
+
is_on_roebe?
|
189
|
+
into = "#{Roebe.log_dir?}opened_files.yml"
|
190
|
+
array = []
|
191
|
+
if File.exist? into
|
192
|
+
array << YAML.load_file(into)
|
193
|
+
end
|
194
|
+
array.flatten!
|
195
|
+
array << i unless array.include?(i)
|
196
|
+
what = YAML.dump(array)
|
197
|
+
unless Object.const_defined?(:SaveFile)
|
198
|
+
require 'save_file'
|
199
|
+
end
|
200
|
+
SaveFile.write_what_into(what, into)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# ========================================================================= #
|
205
|
+
# === verbose_notify_the_user_that_a_default_delay_will_be_used_next
|
206
|
+
# ========================================================================= #
|
207
|
+
def verbose_notify_the_user_that_a_default_delay_will_be_used_next
|
208
|
+
opne "More than #{steelblue('3 arguments')} were given, thus we will "\
|
209
|
+
"use a small delay of #{simp(N_DELAY.to_s)} seconds."
|
210
|
+
end
|
211
|
+
|
212
|
+
# ========================================================================= #
|
213
|
+
# === menu (menu tag)
|
214
|
+
# ========================================================================= #
|
215
|
+
def menu(
|
216
|
+
i = commandline_arguments?
|
217
|
+
)
|
218
|
+
if i.is_a? Array
|
219
|
+
i.each {|entry| menu(entry) }
|
220
|
+
else
|
221
|
+
case i # (case tag)
|
99
222
|
# ===================================================================== #
|
100
|
-
#
|
223
|
+
# === open_in_editor --show-help
|
101
224
|
# ===================================================================== #
|
102
|
-
|
225
|
+
when /help$/
|
226
|
+
show_help
|
227
|
+
exit
|
103
228
|
# ===================================================================== #
|
104
|
-
# ===
|
229
|
+
# === open_in_editor --editor?
|
105
230
|
# ===================================================================== #
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# Since as of March 2023 we will distinguish two use cases:
|
110
|
-
#
|
111
|
-
# (1) first, we will try to use the dataset in the file called
|
112
|
-
# shortcuts.yml. If the input is part of a key in that file
|
113
|
-
# then the key will be fetched, and the associated files
|
114
|
-
# will be opened in the editor
|
115
|
-
#
|
116
|
-
# (2) otherwise we will look through RUBY_SRC and simply open
|
117
|
-
# the project-specific .rb file instead
|
118
|
-
#
|
119
|
-
# =================================================================== #
|
120
|
-
base_dir = RUBY_SRC+name
|
121
|
-
if File.exist?(FILE_SHORTCUTS)
|
122
|
-
dataset = YAML.load_file(FILE_SHORTCUTS)
|
123
|
-
end
|
124
|
-
if dataset and dataset.has_key?(name) # Invoke via: openineditors :gamebooks
|
125
|
-
entry = dataset[name]
|
126
|
-
elsif File.directory? base_dir
|
127
|
-
target = base_dir+'/lib/'+name+'/*.rb' # This is, sort of, the special action.
|
128
|
-
entry = Dir[target]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
if entry.include? '#' # Then chop off. It is probably not necessary, though.
|
132
|
-
entry = entry[0..entry.index('#')]
|
133
|
-
end
|
134
|
-
if entry.respond_to?(:start_with?) and entry.start_with?('file://')
|
135
|
-
entry[0, 'file://'.size] = ''
|
231
|
+
when /^-?-?editor\??$/i
|
232
|
+
show_the_editor_in_use
|
233
|
+
exit
|
136
234
|
end
|
137
|
-
|
138
|
-
} if i.is_a? Array
|
139
|
-
i = i.flatten if i.is_a? Array
|
140
|
-
@input = i # Must be an Array.
|
235
|
+
end
|
141
236
|
end
|
142
237
|
|
143
238
|
# ========================================================================= #
|
144
|
-
# ===
|
239
|
+
# === show_the_editor_in_use
|
240
|
+
#
|
241
|
+
# Invocation example:
|
242
|
+
#
|
243
|
+
# open_in_editor --editor?
|
145
244
|
#
|
146
|
-
# We delegate towards FindExpandedAlias
|
147
245
|
# ========================================================================= #
|
148
|
-
def
|
149
|
-
|
150
|
-
if Object.const_defined?(:Roebe) and
|
151
|
-
Roebe.const_defined?(:FindExpandedAlias)
|
152
|
-
_ = ::Roebe::FindExpandedAlias[i]
|
153
|
-
result = sanitize(_)
|
154
|
-
end
|
155
|
-
if result.include? ' ' # For instance, when it includes a ' &'
|
156
|
-
result = result[0, result.index(' ')]
|
157
|
-
end if result
|
158
|
-
return result
|
246
|
+
def show_the_editor_in_use
|
247
|
+
e steelblue(::Open.editor?)
|
159
248
|
end
|
160
249
|
|
161
250
|
# ========================================================================= #
|
162
|
-
# ===
|
251
|
+
# === show_help (help tag)
|
163
252
|
# ========================================================================= #
|
164
|
-
def
|
165
|
-
|
253
|
+
def show_help
|
254
|
+
e 'The following help-options are documented:'
|
255
|
+
e
|
256
|
+
e ' --editor? # show the current main editor in use'
|
257
|
+
e
|
166
258
|
end
|
167
259
|
|
168
260
|
# ========================================================================= #
|
169
|
-
# ===
|
261
|
+
# === consider_opening_files
|
170
262
|
# ========================================================================= #
|
171
|
-
def
|
172
|
-
|
263
|
+
def consider_opening_files(
|
264
|
+
array = work_on_these_files?,
|
265
|
+
use_this_delay_by_default = 0
|
266
|
+
)
|
267
|
+
if array.empty?
|
268
|
+
opne 'No argument was given - thus, starting the primary editor in the background.'
|
269
|
+
start_the_editor_in_the_background
|
270
|
+
else
|
271
|
+
if array.size > 3
|
272
|
+
verbose_notify_the_user_that_a_default_delay_will_be_used_next
|
273
|
+
use_this_delay_by_default = N_DELAY
|
274
|
+
# Old code in use prior to the rewrite in June 2023 was:
|
275
|
+
# case use_this_editor?
|
276
|
+
# when 'bluefish'
|
277
|
+
# sleep(use_which_delay?) if array.size > 3 # To prevent bluefish from acting silly.
|
278
|
+
# end
|
279
|
+
end
|
280
|
+
array.each {|entry|
|
281
|
+
open_this_file_in_the_editor(entry, use_this_delay_by_default)
|
282
|
+
}
|
283
|
+
end
|
173
284
|
end
|
174
285
|
|
175
286
|
# ========================================================================= #
|
176
|
-
# ===
|
287
|
+
# === open_this_file_in_the_editor
|
177
288
|
#
|
178
289
|
# The optional second argument allows us to wait a little before
|
179
290
|
# opening something in the editor.
|
180
291
|
# ========================================================================= #
|
181
|
-
def
|
182
|
-
i,
|
292
|
+
def open_this_file_in_the_editor(
|
293
|
+
i,
|
294
|
+
optional_delay = nil
|
183
295
|
)
|
296
|
+
use_this_editor = use_which_editor?
|
297
|
+
i = i.to_s.dup # So to avoid frozen strings here.
|
298
|
+
i = sanitize_global_environment(i) if i.include? '$'
|
299
|
+
i = rds(i) # Get rid of // again, just in case.
|
300
|
+
# ======================================================================= #
|
301
|
+
# Next, we chop off '?' characters. This is, however had, not good if
|
302
|
+
# this is part of the filename. So we must check if the file exists,
|
303
|
+
# prior to doing this check.
|
304
|
+
# ======================================================================= #
|
305
|
+
if i.include?('?') and !File.exist?(i)
|
306
|
+
i = i[0..i.index('?')]
|
307
|
+
end
|
308
|
+
# ======================================================================= #
|
309
|
+
# Get rid of '#' in the input, if they are part of the input.
|
310
|
+
# ======================================================================= #
|
311
|
+
i = i[0 .. i.index('#')] if i.include? '#'
|
312
|
+
# ===================================================================== #
|
313
|
+
# === Handle fake "Symbols" next:
|
314
|
+
# ===================================================================== #
|
315
|
+
if i.start_with?(':') # If this is a "symbol" we assume to do a special action.
|
316
|
+
name = i[1 .. -1] # Get rid of the leading ':' here.
|
317
|
+
# ===================================================================== #
|
318
|
+
# Since as of March 2023 we will distinguish two use cases here
|
319
|
+
# for such fake-symbols:
|
320
|
+
#
|
321
|
+
# (1) first, we will try to use the dataset in the file called
|
322
|
+
# shortcuts.yml. If the input is part of a key in that file
|
323
|
+
# then the key will be fetched, and the associated files
|
324
|
+
# will be opened in the editor
|
325
|
+
#
|
326
|
+
# (2) otherwise we will look through RUBY_SRC and simply open
|
327
|
+
# the project-specific .rb file instead
|
328
|
+
#
|
329
|
+
# These shortcuts are defined in the .yml file at:
|
330
|
+
#
|
331
|
+
# open/yaml/shortcuts.yml
|
332
|
+
#
|
333
|
+
# ===================================================================== #
|
334
|
+
base_dir = RUBY_SRC+name
|
335
|
+
if File.exist?(FILE_SHORTCUTS) # Load the dataset next.
|
336
|
+
dataset = YAML.load_file(FILE_SHORTCUTS)
|
337
|
+
end
|
338
|
+
# ===================================================================== #
|
339
|
+
# The next clause may turn i into an Array - both if and elsif
|
340
|
+
# clauses:
|
341
|
+
# ===================================================================== #
|
342
|
+
if dataset and dataset.has_key?(name) # Invoke via: openineditors :gamebooks
|
343
|
+
i = dataset[name]
|
344
|
+
elsif File.directory? base_dir
|
345
|
+
target = base_dir+'/lib/'+name+'/*.rb' # This is, sort of, the special action.
|
346
|
+
i = Dir[target] # This will make it an Array.
|
347
|
+
end
|
348
|
+
end
|
184
349
|
if i.is_a? Array
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
}
|
350
|
+
use_this_delay = 0
|
351
|
+
if i.size > 3
|
352
|
+
verbose_notify_the_user_that_a_default_delay_will_be_used_next
|
353
|
+
use_this_delay = N_DELAY
|
354
|
+
end
|
355
|
+
i.each {|entry| open_this_file_in_the_editor(entry, use_this_delay) }
|
191
356
|
else
|
192
|
-
|
357
|
+
# ===================================================================== #
|
358
|
+
# We never want to have localhost entries:
|
359
|
+
# ===================================================================== #
|
193
360
|
if i.include? 'localhost'
|
194
|
-
i.
|
361
|
+
i.sub!(/^http\:\/\/localhost\//, MY_DATA+'/')
|
362
|
+
end
|
363
|
+
if i.respond_to?(:start_with?) and i.start_with?('file://')
|
364
|
+
i[0, 'file://'.size] = ''
|
195
365
|
end
|
196
366
|
if i.end_with?(':') and !File.exist?(i)
|
197
|
-
i
|
198
|
-
elsif i =~ /(:\d+)/ # Has a : and
|
367
|
+
i.chop! # Chop off the last character in this case.
|
368
|
+
elsif i =~ /(:\d+)/ # Has a : and also number, such as ":5".
|
199
369
|
i.gsub!(/#{$1.to_s.dup}/,'')
|
200
370
|
end
|
201
|
-
|
202
|
-
|
371
|
+
if i.include? '#' # Then chop off. It is probably not necessary, though.
|
372
|
+
i = i[0 .. i.index('#')]
|
373
|
+
end
|
374
|
+
if i.count('/home') > 1 # We have more than one entry of '/home'.
|
203
375
|
i.gsub!(/#{MY_DATA}#{MY_DATA}/, MY_DATA)
|
204
376
|
end
|
205
377
|
if i.start_with?('http:') and !File.exist?(i)
|
206
378
|
i.delete_prefix!('http:')
|
207
379
|
end
|
380
|
+
# ===================================================================== #
|
381
|
+
# First check whether the file at `i` exists or whether it does not.
|
382
|
+
# ===================================================================== #
|
208
383
|
if File.exist? i
|
209
384
|
# =================================================================== #
|
210
|
-
#
|
385
|
+
# The file exists, so we can open it in our editor next. We will
|
386
|
+
# work on the absolute path to it since as of June 2023.
|
211
387
|
# =================================================================== #
|
212
|
-
|
388
|
+
i = File.absolute_path(i)
|
389
|
+
# =================================================================== #
|
390
|
+
# Make an exception for .cpp files but only for roebe-systems:
|
391
|
+
# =================================================================== #
|
392
|
+
case File.extname(i).delete('.')
|
393
|
+
when 'cpp'
|
394
|
+
if is_on_roebe?
|
395
|
+
if ENV.has_key?('CPP_EDITOR')
|
396
|
+
use_this_editor = ENV['CPP_EDITOR'].to_s.dup
|
397
|
+
else
|
398
|
+
use_this_editor = 'geany' # We use geany for cpp files.
|
399
|
+
end
|
400
|
+
end
|
401
|
+
end
|
402
|
+
if i.include?("'") and !i.include?('"')
|
403
|
+
i = '"'+i+'"'
|
404
|
+
end
|
405
|
+
if i.include? '('
|
406
|
+
i = '"'+i+'"'
|
407
|
+
end
|
408
|
+
esystem "#{use_this_editor} #{i}"
|
409
|
+
do_save_this_file_into_a_local_yaml_file(i) # Only on roebe-systems though.
|
410
|
+
sleep(optional_delay) if optional_delay # In this case we will also sleep.
|
213
411
|
else # Ok, the file does not exist at this point.
|
214
|
-
#
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
412
|
+
# ===================================================================== #
|
413
|
+
# Next assume it is a local link.
|
414
|
+
# ===================================================================== #
|
415
|
+
if BeautifulUrl.is_a_local_link?(i)
|
416
|
+
i = BeautifulUrl.local_menu(i)
|
417
|
+
else
|
418
|
+
# =================================================================== #
|
419
|
+
# First try a purl.
|
420
|
+
# =================================================================== #
|
421
|
+
_ = BeautifulUrl::BeautifulUrl.new(i, replace: true)
|
422
|
+
end
|
423
|
+
if _ and _.url_was_found
|
424
|
+
esystem "#{use_this_editor} #{_.url_as_string}"
|
425
|
+
elsif Dir["#{i}*"].size > 0 # Try to find matches.
|
426
|
+
opne 'Did not find '+sfile(i)+' but we may have found '\
|
427
|
+
'at least one other entry.'
|
428
|
+
open_in_editor(Dir["#{i}*"].reject {|entry| File.directory? entry })
|
429
|
+
# ================================================================= #
|
430
|
+
# === Run through the expanded-aliases next:
|
431
|
+
# ================================================================= #
|
432
|
+
elsif try_to_find_expanded_alias_for(i)
|
433
|
+
i = sanitize_global_environment(i) if i and i.include?('$')
|
434
|
+
if i.include? ' ' # For instance, when it includes a ' &'.
|
435
|
+
i = i[0, i.index(' ')]
|
436
|
+
end if i
|
437
|
+
if Object.const_defined?(:Roebe) and
|
438
|
+
Roebe.const_defined?(:FindExpandedAlias)
|
439
|
+
expanded_alias = Roebe::FindExpandedAlias.new(i) { :be_quiet }
|
440
|
+
i = expanded_alias[i]
|
441
|
+
end
|
442
|
+
open_in_editor(i) if i and !i.empty? # Recursive call.
|
224
443
|
# ================================================================= #
|
225
444
|
# Now the string can include 'project_', in which case we
|
226
445
|
# will handle it in a special way.
|
@@ -241,57 +460,13 @@ class InEditor < Base # === Open::InEditor
|
|
241
460
|
end
|
242
461
|
end
|
243
462
|
end
|
244
|
-
|
245
|
-
end
|
246
|
-
|
247
|
-
# ========================================================================= #
|
248
|
-
# === set_editor
|
249
|
-
# ========================================================================= #
|
250
|
-
def set_editor(i = use_which_editor?)
|
251
|
-
@use_this_editor = i
|
252
|
-
end; alias editor= set_editor # === editor=
|
253
|
-
|
254
|
-
# ========================================================================= #
|
255
|
-
# === input?
|
256
|
-
# ========================================================================= #
|
257
|
-
def input?
|
258
|
-
@input
|
259
|
-
end
|
260
|
-
|
261
|
-
# ========================================================================= #
|
262
|
-
# === consider_opening_files
|
263
|
-
# ========================================================================= #
|
264
|
-
def consider_opening_files(
|
265
|
-
i = input?
|
266
|
-
)
|
267
|
-
if i.is_a? Array
|
268
|
-
i.flatten!
|
269
|
-
i.map! {|file|
|
270
|
-
file.chop! if file.end_with? ':'
|
271
|
-
file
|
272
|
-
}
|
273
|
-
if i.empty?
|
274
|
-
start_editor_in_background
|
275
|
-
else
|
276
|
-
optional_delay = 0
|
277
|
-
if i.size > 3
|
278
|
-
opn; e "More than 3 arguments were given, thus we will use "\
|
279
|
-
"a delay of #{simp(N_DELAY.to_s)} seconds."
|
280
|
-
optional_delay = N_DELAY
|
281
|
-
end
|
282
|
-
i.each {|entry|
|
283
|
-
open_in_editor(entry, optional_delay)
|
284
|
-
}
|
285
|
-
end
|
286
|
-
else
|
287
|
-
open_in_editor(i)
|
288
|
-
end
|
289
|
-
end
|
463
|
+
end; alias open_in_editor open_this_file_in_the_editor # === open_in_editor
|
290
464
|
|
291
465
|
# ========================================================================= #
|
292
466
|
# === run (run tag)
|
293
467
|
# ========================================================================= #
|
294
468
|
def run
|
469
|
+
menu
|
295
470
|
consider_opening_files
|
296
471
|
end
|
297
472
|
|
@@ -309,21 +484,39 @@ end
|
|
309
484
|
# =========================================================================== #
|
310
485
|
# === Open.in_editor
|
311
486
|
#
|
487
|
+
# Note that the behaviour of Open.in_editor() is in-sync with the
|
488
|
+
# method Open.in_browser(), in regards to joinable arguments
|
489
|
+
# (typically an Array as input). If you do not want this behaviour
|
490
|
+
# then you may have to prepare for this in your own code, such
|
491
|
+
# as by having an Array and iterating over it before passing
|
492
|
+
# the individual entries into Open.in_editor().
|
493
|
+
#
|
312
494
|
# Usage examples:
|
313
495
|
#
|
314
496
|
# Open.in_editor('/home/x/programming/ruby/src/open/open.gemspec')
|
315
497
|
#
|
316
|
-
# Or
|
498
|
+
# Or the lock variant:
|
317
499
|
#
|
318
500
|
# Open.in_editor {{
|
319
501
|
# this_file: first_argument?,
|
320
502
|
# use_this_editor: :nano
|
321
503
|
# }}
|
322
504
|
#
|
505
|
+
# Which may also look like this:
|
506
|
+
#
|
507
|
+
# ::Open.in_editor {{
|
508
|
+
# this_file: _,
|
509
|
+
# use_this_editor: :bluefish
|
510
|
+
# }}
|
511
|
+
#
|
323
512
|
# =========================================================================== #
|
324
513
|
def self.in_editor(
|
325
|
-
i = ARGV,
|
514
|
+
i = ARGV,
|
515
|
+
&block
|
326
516
|
)
|
517
|
+
if i.respond_to? :join
|
518
|
+
i.join(' ').strip
|
519
|
+
end
|
327
520
|
::Open::InEditor.new(i, &block)
|
328
521
|
end
|
329
522
|
|
@@ -333,9 +526,9 @@ end
|
|
333
526
|
# === open_in_editor
|
334
527
|
# =========================================================================== #
|
335
528
|
def open_in_editor(i, &block)
|
336
|
-
Open.in_editor(i, &block)
|
529
|
+
::Open.in_editor(i, &block)
|
337
530
|
end
|
338
531
|
|
339
532
|
if __FILE__ == $PROGRAM_NAME
|
340
|
-
Open
|
341
|
-
end # openineditor
|
533
|
+
ARGV.each {|entry| Open.in_editor(entry) }
|
534
|
+
end # openineditor localruby
|