open 0.1.3

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

Potentially problematic release.


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

@@ -0,0 +1,45 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'open/project/project.rb'
6
+ # =========================================================================== #
7
+ module Open
8
+
9
+ # ========================================================================= #
10
+ # === Open::PROJECT_BASE_DIRECTORY
11
+ # ========================================================================= #
12
+ PROJECT_BASE_DIRECTORY =
13
+ File.absolute_path("#{__dir__}/..")+'/'
14
+
15
+ # ========================================================================= #
16
+ # === Open.project_base_directory?
17
+ # ========================================================================= #
18
+ def self.project_base_directory?
19
+ PROJECT_BASE_DIRECTORY
20
+ end; self.instance_eval { alias project_base_dir? project_base_directory? } # === Open.project_base_dir?
21
+ self.instance_eval { alias project_dir? project_base_directory? } # === Open.project_dir?
22
+ self.instance_eval { alias base_dir? project_base_directory? } # === Open.base_dir?
23
+ self.instance_eval { alias base_directory? project_base_directory? } # === Open.base_directory?
24
+
25
+ # ========================================================================= #
26
+ # === Open::PROJECT_YAML_DIRECTORY
27
+ # ========================================================================= #
28
+ PROJECT_YAML_DIRECTORY = "#{Open.project_base_dir?}yaml/"
29
+
30
+ # ========================================================================= #
31
+ # === Open.project_yaml_dir?
32
+ #
33
+ # This is a query-method for the constant PROJECT_YAML_DIRECTORY.
34
+ # ========================================================================= #
35
+ def self.project_yaml_dir?
36
+ PROJECT_YAML_DIRECTORY
37
+ end; self.instance_eval { alias yaml_directory? project_yaml_dir? } # === Open.yaml_directory?
38
+ self.instance_eval { alias project_yaml_directory? project_yaml_dir? } # === Open.project_yaml_directory?
39
+
40
+ end
41
+
42
+ if __FILE__ == $PROGRAM_NAME
43
+ puts Open.project_base_dir?
44
+ puts Open.project_yaml_dir?
45
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'open/constants/constants.rb'
6
+ require 'open/toplevel_code/toplevel_code.rb'
7
+ require 'open/version/version.rb'
8
+ require 'open/in_browser/in_browser.rb'
9
+ require 'open/in_editor/in_editor.rb'
10
+ require 'open/last/last.rb'
11
+ require 'open/last_url/last_url.rb'
12
+ require 'open/with_delay/with_delay.rb'
13
+ require 'open/open.rb'
14
+ require 'open/nano_open/nano_open.rb'
15
+ require 'open/these_files/these_files.rb'
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Open::TheseFiles
6
+ #
7
+ # Usage example:
8
+ #
9
+ # require 'open/these_files/these_files.rb'
10
+ # Open.these_files(ARGV)
11
+ #
12
+ # =========================================================================== #
13
+ # require 'open/these_files/these_files.rb'
14
+ # =========================================================================== #
15
+ require 'open/base/base.rb'
16
+
17
+ module Open
18
+
19
+ class TheseFiles < Base # === Open::TheseFiles
20
+
21
+ require 'open/in_editor/in_editor.rb'
22
+
23
+ # ========================================================================= #
24
+ # === initialize
25
+ #
26
+ # The first argument should be the name of the file that we wish to open.
27
+ # ========================================================================= #
28
+ def initialize(
29
+ i = nil,
30
+ run_already = true
31
+ )
32
+ register_sigint
33
+ reset
34
+ set_input(i)
35
+ run if run_already
36
+ end
37
+
38
+ # ========================================================================= #
39
+ # === reset (reset tag)
40
+ # ========================================================================= #
41
+ def reset
42
+ super()
43
+ end
44
+
45
+ # ========================================================================= #
46
+ # === set_input
47
+ # ========================================================================= #
48
+ def set_input(i = '')
49
+ if i and i.is_a?(String) and i.include?("\n")
50
+ i = i.split("\n")
51
+ end
52
+ i = [i].flatten.compact.map {|entry|
53
+ if entry.include? ':'
54
+ entry = entry.split(':').first.strip
55
+ end
56
+ entry
57
+ }
58
+ @input = i # Must be an Array.
59
+ end
60
+
61
+ # ========================================================================= #
62
+ # === input?
63
+ # ========================================================================= #
64
+ def input?
65
+ @input
66
+ end
67
+
68
+ # ========================================================================= #
69
+ # === consider_opening_these_files
70
+ # ========================================================================= #
71
+ def consider_opening_these_files(
72
+ i = input?
73
+ )
74
+ i.each {|entry|
75
+ Open.in_editor(i)
76
+ sleep 0.76
77
+ }
78
+ end
79
+
80
+ # ========================================================================= #
81
+ # === run (run tag)
82
+ # ========================================================================= #
83
+ def run
84
+ consider_opening_these_files
85
+ end
86
+
87
+ # ========================================================================= #
88
+ # === Open::TheseFiles[]
89
+ # ========================================================================= #
90
+ def self.[](i, &block)
91
+ new(i, &block)
92
+ end
93
+
94
+ end
95
+
96
+ # =========================================================================== #
97
+ # === Open.these_files
98
+ # =========================================================================== #
99
+ def self.these_files(
100
+ i = ARGV, &block
101
+ )
102
+ ::Open::TheseFiles.new(i, &block)
103
+ end
104
+
105
+ end
106
+
107
+ # =========================================================================== #
108
+ # === open_these_files
109
+ # =========================================================================== #
110
+ def open_these_files(i = ARGV, &block)
111
+ Open.these_files(i, &block)
112
+ end
113
+
114
+ if __FILE__ == $PROGRAM_NAME
115
+ Open::TheseFiles.new(ARGV)
116
+ end # openthesefiles
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'open/toplevel_code/toplevel_code.rb'
6
+ # =========================================================================== #
7
+ module Open
8
+
9
+ require 'open/constants/constants.rb'
10
+
11
+ # ========================================================================= #
12
+ # === Open.is_on_windows?
13
+ # ========================================================================= #
14
+ def self.is_on_windows?
15
+ case RUBY_PLATFORM
16
+ when /win/,/mingw/
17
+ true
18
+ else
19
+ false
20
+ end
21
+ end
22
+
23
+ # ========================================================================= #
24
+ # === @use_this_editor
25
+ # ========================================================================= #
26
+ @use_this_editor = nil
27
+
28
+ # ========================================================================= #
29
+ # === Open.set_use_this_editor
30
+ #
31
+ # Modify the toplevel variable @use_this_editor through this method.
32
+ # ========================================================================= #
33
+ def self.set_use_this_editor(
34
+ i = USE_THIS_EDITOR
35
+ )
36
+ @use_this_editor = i
37
+ end
38
+
39
+ set_use_this_editor # Initialize it at once.
40
+
41
+ # ========================================================================= #
42
+ # === Open.use_which_editor?
43
+ # ========================================================================= #
44
+ def self.use_which_editor?
45
+ @use_this_editor
46
+ end
47
+
48
+ # ========================================================================= #
49
+ # === @use_this_browser
50
+ # ========================================================================= #
51
+ @use_this_browser = nil
52
+
53
+ # ========================================================================= #
54
+ # === Open.set_use_this_browser
55
+ # ========================================================================= #
56
+ def self.set_use_this_browser(
57
+ i = USE_THIS_BROWSER
58
+ )
59
+ @use_this_browser = i
60
+ end
61
+
62
+ set_use_this_browser # Initialize it at once.
63
+
64
+ # ========================================================================= #
65
+ # === Open.use_which_browser?
66
+ # ========================================================================= #
67
+ def self.use_which_browser?
68
+ @use_this_browser
69
+ end
70
+
71
+ # ========================================================================= #
72
+ # === Open[]
73
+ #
74
+ # This method defaults to Open.in_editor(), but if the input starts
75
+ # with "http" then we will use Open.in_browser() instead.
76
+ #
77
+ # Usage example:
78
+ #
79
+ # Open[TEST_THIS_FILE]
80
+ #
81
+ # ========================================================================= #
82
+ def self.[](i = ARGV, &block)
83
+ unless Open.respond_to? :in_browser
84
+ require 'open/in_browser/in_browser.rb'
85
+ end
86
+ unless Open.respond_to? :in_editor
87
+ require 'open/in_editor/in_editor.rb'
88
+ end
89
+ if i.is_a? Array
90
+ i = i.join(' ').strip
91
+ end
92
+ if i.start_with? 'http'
93
+ ::Open.in_browser(i, &block)
94
+ else # this is the default
95
+ ::Open.in_editor(i, &block)
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ if __FILE__ == $PROGRAM_NAME
102
+ puts Open.use_which_editor?
103
+ puts Open.use_which_browser?
104
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'open/version/version.rb'
6
+ # =========================================================================== #
7
+ module Open
8
+
9
+ # ========================================================================= #
10
+ # === VERSION
11
+ # ========================================================================= #
12
+ VERSION = '0.1.3'
13
+
14
+ # ========================================================================= #
15
+ # === LAST_UPDATE
16
+ # ========================================================================= #
17
+ LAST_UPDATE = '14.11.2021'
18
+
19
+ end
@@ -0,0 +1,261 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Open::WithDelay
6
+ #
7
+ # This class will open files in the current working directory, with a
8
+ # small delay. The idea behind this is that some editors, such as
9
+ # the old bluefish editor, had difficulties opening many large files
10
+ # rapidly.
11
+ #
12
+ # Usage example:
13
+ #
14
+ # Open::WithDelay.new(ARGV)
15
+ #
16
+ # =========================================================================== #
17
+ # require 'open/with_delay/_with_delay.rb'
18
+ # Open::WithDelay.new(ARGV)
19
+ # =========================================================================== #
20
+ require 'open/base/base.rb'
21
+
22
+ module Open
23
+
24
+ class WithDelay < Base # === Open::WithDelay
25
+
26
+ require 'open/in_editor/in_editor'
27
+
28
+ # ========================================================================= #
29
+ # === NAMESPACE
30
+ # ========================================================================= #
31
+ NAMESPACE = inspect
32
+
33
+ # ========================================================================= #
34
+ # === DEFAULT_DELAY
35
+ # ========================================================================= #
36
+ DEFAULT_DELAY = 1.0
37
+
38
+ # ========================================================================= #
39
+ # === initialize
40
+ # ========================================================================= #
41
+ def initialize(
42
+ commandline_arguments = DEFAULT_DELAY,
43
+ run_already = true
44
+ )
45
+ reset
46
+ set_commandline_arguments(
47
+ commandline_arguments
48
+ )
49
+ run if run_already
50
+ end
51
+
52
+ # ========================================================================= #
53
+ # === reset
54
+ # ========================================================================= #
55
+ def reset
56
+ super()
57
+ set_default_delay # We need a default value for the delay to be set.
58
+ determine_which_files_to_open
59
+ # ======================================================================= #
60
+ # === @namespace
61
+ # ======================================================================= #
62
+ @namespace = NAMESPACE
63
+ # ======================================================================= #
64
+ # === @pattern
65
+ # ======================================================================= #
66
+ @pattern = nil
67
+ end
68
+
69
+ # ========================================================================= #
70
+ # === search_for_this_pattern
71
+ # ========================================================================= #
72
+ def search_for_this_pattern(i)
73
+ @pattern = i
74
+ end; alias set_pattern search_for_this_pattern # === set_pattern
75
+
76
+ # ========================================================================= #
77
+ # === determine_which_files_to_open
78
+ # ========================================================================= #
79
+ def determine_which_files_to_open(
80
+ i = '*'
81
+ )
82
+ i = i.to_s.dup.delete('-')
83
+ case i
84
+ # ======================================================================= #
85
+ # === everything
86
+ # ======================================================================= #
87
+ when 'everything',
88
+ /^really(_|-)?everything$/i
89
+ @all_files = Dir['**/**'].select {|entry| File.file? entry }
90
+ else # This is the default entry-clause.
91
+ @all_files = Dir[i].select {|entry| File.file? entry }
92
+ end unless File.exist?('everything')
93
+ # ======================================================================= #
94
+ # And sort it next:
95
+ # ======================================================================= #
96
+ @all_files = @all_files.sort_by {|inner_entry|
97
+ # ===================================================================== #
98
+ # Must sort the files by last filename next.
99
+ # ===================================================================== #
100
+ File.basename(inner_entry)
101
+ }
102
+ end
103
+
104
+ # ========================================================================= #
105
+ # === set_use_this_delay
106
+ #
107
+ # Determine which delay to use before file-opening - in n seconds.
108
+ # ========================================================================= #
109
+ def set_use_this_delay(
110
+ i = DEFAULT_DELAY
111
+ )
112
+ i = i.first if i.is_a? Array
113
+ case i
114
+ # ======================================================================= #
115
+ # === :default_delay
116
+ # ======================================================================= #
117
+ when :default_delay, nil
118
+ i = DEFAULT_DELAY
119
+ end
120
+ i = i.to_f
121
+ @use_this_delay = i
122
+ end
123
+
124
+ # ========================================================================= #
125
+ # === set_default_delay
126
+ # ========================================================================= #
127
+ def set_default_delay
128
+ set_use_this_delay(:default_delay)
129
+ end
130
+
131
+ # ========================================================================= #
132
+ # === use_this_delay?
133
+ # ========================================================================= #
134
+ def use_this_delay?
135
+ @use_this_delay
136
+ end; alias delay? use_this_delay? # === delay?
137
+
138
+ # ========================================================================= #
139
+ # === report_the_delay_in_use
140
+ # ========================================================================= #
141
+ def report_the_delay_in_use
142
+ opnn; e "The delay is `#{simp(delay?.to_s)}` seconds."
143
+ end
144
+
145
+ # ========================================================================= #
146
+ # === menu (menu tag)
147
+ # ========================================================================= #
148
+ def menu(
149
+ i = @commandline_arguments
150
+ )
151
+ if i.is_a? Array
152
+ i.each {|entry| menu(entry) }
153
+ else
154
+ case i
155
+ # ===================================================================== #
156
+ # === odelay --pattern=input
157
+ # ===================================================================== #
158
+ when /^-?-?pattern=(.+)$/i
159
+ search_for_this_pattern($1.to_s.dup)
160
+ # ===================================================================== #
161
+ # === odelay --help
162
+ # ===================================================================== #
163
+ when /^-?-?help$/i
164
+ show_help
165
+ exit
166
+ # ===================================================================== #
167
+ # === odelay --everything
168
+ #
169
+ # This entry point allows us to open every file in all subdirectories
170
+ # found, under the current working directory (pwd, cwd).
171
+ # ===================================================================== #
172
+ when /^-?-?everything$/i
173
+ determine_which_files_to_open(i)
174
+ else # we assume this to be the default.
175
+ if i.include?('.') and is_there_a_file_with_that_file_end_in_this_directory?(i)
176
+ set_pattern(i)
177
+ else
178
+ set_use_this_delay(i)
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+ # ========================================================================= #
185
+ # === show_help (help tag)
186
+ # ========================================================================= #
187
+ def show_help
188
+ e
189
+ eparse ' --everything # Open all files in the current working '\
190
+ 'directory and all subdirectories, via the default delay'
191
+ eparse ' --pattern=criterium # Search for only files that match the '\
192
+ 'given criterium'
193
+ e
194
+ end
195
+
196
+ # ========================================================================= #
197
+ # === is_there_a_file_with_that_file_end_in_this_directory?
198
+ # ========================================================================= #
199
+ def is_there_a_file_with_that_file_end_in_this_directory?(i)
200
+ !Dir['*'].select {|file|
201
+ file.end_with? file
202
+ }.empty?
203
+ end
204
+
205
+ # ========================================================================= #
206
+ # === consider_applying_the_pattern_filter
207
+ #
208
+ # The filter is a positive-filter, aka we keep only those files that
209
+ # fulfil our criterium.
210
+ # ========================================================================= #
211
+ def consider_applying_the_pattern_filter
212
+ if @pattern
213
+ @all_files.select! {|this_file|
214
+ this_file.include? @pattern
215
+ }
216
+ end
217
+ end
218
+
219
+ # ========================================================================= #
220
+ # === do_process_all_files
221
+ # ========================================================================= #
222
+ def do_process_all_files(
223
+ i = @all_files
224
+ )
225
+ using_this_editor = use_which_editor?
226
+ delay = delay?.to_s
227
+ opnn; e "We will open all #{sfancy(i.size.to_s)} files "\
228
+ "in this directory."
229
+ i.each {|this_file|
230
+ opnn; e 'Next opening the file `'+sfile(this_file)+
231
+ '` via the editor '+sfancy(using_this_editor)+','
232
+ opnn; e "then sleeping for #{simp(delay)} seconds."
233
+ Open.in_editor(this_file)
234
+ sleep(delay.to_i)
235
+ }
236
+ end
237
+
238
+ # ========================================================================= #
239
+ # === run
240
+ # ========================================================================= #
241
+ def run
242
+ menu
243
+ report_the_delay_in_use
244
+ consider_applying_the_pattern_filter
245
+ do_process_all_files
246
+ end
247
+
248
+ end
249
+
250
+ # =========================================================================== #
251
+ # === Open.with_delay
252
+ # =========================================================================== #
253
+ def self.with_delay(i = ARGV)
254
+ Open::WithDelay.new(i)
255
+ end; self.instance_eval { alias open_with_delay with_delay } # === Open.open_with_delay
256
+
257
+ end
258
+
259
+ if __FILE__ == $PROGRAM_NAME
260
+ Open::WithDelay.new(ARGV)
261
+ end # openwithdelay 3
@@ -0,0 +1 @@
1
+ firefox
@@ -0,0 +1 @@
1
+ bluefish
data/lib/open.rb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'open/requires/require_the_project.rb'
data/open.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # =========================================================================== #
2
+ # Gemspec for this project.
3
+ # =========================================================================== #
4
+ require 'open'
5
+ require 'roebe'
6
+
7
+ Gem::Specification.new { |s|
8
+
9
+ s.name = 'open'
10
+ s.version = Open::VERSION
11
+ s.date = Time.now.strftime('%Y-%m-%d')
12
+
13
+ DESCRIPTION = <<-EOF
14
+
15
+ This project can be used to open an URL in a browser, usually
16
+ via a browser such as firefox or palemoon. It can also be used
17
+ to open a local file in an editor. The latter has been a reason
18
+ why the API was created in the first place, via Open.in_editor()
19
+ or Open.in_browser().
20
+
21
+ EOF
22
+
23
+ s.summary = DESCRIPTION
24
+ s.description = DESCRIPTION
25
+
26
+ s.authors = ['Robert A. Heiler']
27
+ s.email = Roebe.email?
28
+ s.files = Dir['**/*']
29
+ s.license = 'MIT'
30
+ s.homepage = 'https://rubygems.org/gems/open_in_browser'
31
+
32
+ s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
33
+ s.required_rubygems_version = '>= '+Gem::VERSION
34
+ s.rubygems_version = '>= '+Gem::VERSION
35
+
36
+ }
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'colours/autoinclude'
6
+ require 'open'
7
+
8
+ # =========================================================================== #
9
+ # === TEST_THIS_FILE
10
+ # =========================================================================== #
11
+ TEST_THIS_FILE = Open::RUBY_SRC+
12
+ 'open/lib/open/constants/constants.rb'
13
+
14
+ e
15
+ e 'First testing the browser-functionality of this gem.'
16
+ e
17
+ e ' - Testing open_in_browser() functionality next:'
18
+ e
19
+ open_in_browser 'google.at'
20
+ open_in_browser 'linux', '?pdf'
21
+ open_in_browser 'http://localhost/programming/ruby/src/chemistry_paradise/lib/chemistry_paradise/www/chemistry/chemistry.cgi',
22
+ 'Absolutkonfiguration'
23
+ e
24
+ e 'Next testing the project called '+sfancy('open')+'.'
25
+ e
26
+
27
+ e
28
+ Open.in_editor('/home/x/programming/ruby/src/open/open.gemspec')
29
+ e
30
+ e
31
+ e "Now opening file #{sfile(TEST_THIS_FILE)}."
32
+ e
33
+
34
+ Open::InEditor[TEST_THIS_FILE]
35
+ Open[TEST_THIS_FILE]