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