open 0.1.23
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 +292 -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 +248 -0
- data/lib/open/base/base.rb +311 -0
- data/lib/open/constants/constants.rb +110 -0
- data/lib/open/in_browser/in_browser.rb +572 -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 +1026 -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,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,162 @@
|
|
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.e
|
13
|
+
# ========================================================================= #
|
14
|
+
def self.e(i = '')
|
15
|
+
puts i
|
16
|
+
end
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === Open.host_os?
|
20
|
+
#
|
21
|
+
# Return the host-operating system via this method.
|
22
|
+
# ========================================================================= #
|
23
|
+
def self.host_os?
|
24
|
+
::RbConfig::CONFIG['host_os']
|
25
|
+
end
|
26
|
+
|
27
|
+
# ========================================================================= #
|
28
|
+
# === Open.is_on_windows?
|
29
|
+
# ========================================================================= #
|
30
|
+
def self.is_on_windows?(i = host_os?)
|
31
|
+
case i # or: RUBY_PLATFORM
|
32
|
+
when /win/,
|
33
|
+
/mingw/
|
34
|
+
true
|
35
|
+
else
|
36
|
+
false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# ========================================================================= #
|
41
|
+
# === @use_this_editor
|
42
|
+
# ========================================================================= #
|
43
|
+
@use_this_editor = nil
|
44
|
+
|
45
|
+
# ========================================================================= #
|
46
|
+
# === Open.set_use_this_editor
|
47
|
+
#
|
48
|
+
# Modify the toplevel variable @use_this_editor through this method.
|
49
|
+
# ========================================================================= #
|
50
|
+
def self.set_use_this_editor(
|
51
|
+
i = USE_THIS_EDITOR
|
52
|
+
)
|
53
|
+
@use_this_editor = i
|
54
|
+
end
|
55
|
+
|
56
|
+
set_use_this_editor # Initialize it at once.
|
57
|
+
|
58
|
+
# ========================================================================= #
|
59
|
+
# === Open.use_which_editor?
|
60
|
+
# ========================================================================= #
|
61
|
+
def self.use_which_editor?
|
62
|
+
@use_this_editor
|
63
|
+
end
|
64
|
+
|
65
|
+
# ========================================================================= #
|
66
|
+
# === @use_this_browser
|
67
|
+
# ========================================================================= #
|
68
|
+
@use_this_browser = nil
|
69
|
+
|
70
|
+
# ========================================================================= #
|
71
|
+
# === Open.set_use_this_browser
|
72
|
+
#
|
73
|
+
# This method can be used to assign a different browser.
|
74
|
+
# ========================================================================= #
|
75
|
+
def self.set_use_this_browser(
|
76
|
+
i = USE_THIS_BROWSER
|
77
|
+
)
|
78
|
+
@use_this_browser = i
|
79
|
+
end; self.instance_eval { alias use_this_browser= set_use_this_browser } # === Open.use_this_browser=
|
80
|
+
|
81
|
+
set_use_this_browser # Initialize it at once.
|
82
|
+
|
83
|
+
# ========================================================================= #
|
84
|
+
# === Open.use_which_browser?
|
85
|
+
#
|
86
|
+
# Query-method to determine which browser is currently designated to be
|
87
|
+
# the main browser, as far as the open-gem is concerned.
|
88
|
+
# ========================================================================= #
|
89
|
+
def self.use_which_browser?
|
90
|
+
@use_this_browser
|
91
|
+
end; self.instance_eval { alias browser? use_which_browser? } # === Open.browser?
|
92
|
+
|
93
|
+
# ========================================================================= #
|
94
|
+
# === Open.permanently_use_this_browser
|
95
|
+
#
|
96
|
+
# This method can be used to permanently store a new browser, for the
|
97
|
+
# open gem.
|
98
|
+
# ========================================================================= #
|
99
|
+
def self.permanently_use_this_browser(
|
100
|
+
this_browser = 'thorium',
|
101
|
+
store_into_this_file = ::Open::LOCATION_OF_BROWSER_YAML_FILE
|
102
|
+
)
|
103
|
+
this_browser = this_browser.to_s
|
104
|
+
e 'Storing into `'+store_into_this_file+'`.'
|
105
|
+
write_what_into(this_browser, store_into_this_file)
|
106
|
+
if is_on_roebe?
|
107
|
+
store_into_this_file = '/home/x/programming/ruby/src/open/lib/open/yaml/use_this_browser.yml'
|
108
|
+
e 'Storing into `'+store_into_this_file+'`.'
|
109
|
+
write_what_into(this_browser, store_into_this_file)
|
110
|
+
end
|
111
|
+
end; self.instance_eval { alias permanently_use_this_browser= permanently_use_this_browser } # === Open.permanently_use_this_browser=
|
112
|
+
|
113
|
+
# ========================================================================= #
|
114
|
+
# === Open.write_what_into
|
115
|
+
#
|
116
|
+
# Delegate towards SaveFile.
|
117
|
+
# ========================================================================= #
|
118
|
+
def self.write_what_into(what, into)
|
119
|
+
::SaveFile.write_what_into(what, into)
|
120
|
+
end
|
121
|
+
|
122
|
+
# ========================================================================= #
|
123
|
+
# === Open[]
|
124
|
+
#
|
125
|
+
# This method defaults to Open.in_editor(), but if the input starts
|
126
|
+
# with "http" then we will use Open.in_browser() instead.
|
127
|
+
#
|
128
|
+
# Usage example:
|
129
|
+
#
|
130
|
+
# Open[TEST_THIS_FILE]
|
131
|
+
#
|
132
|
+
# ========================================================================= #
|
133
|
+
def self.[](i = ARGV, &block)
|
134
|
+
unless Open.respond_to? :in_browser
|
135
|
+
require 'open/in_browser/in_browser.rb'
|
136
|
+
end
|
137
|
+
unless Open.respond_to? :in_editor
|
138
|
+
require 'open/in_editor/in_editor.rb'
|
139
|
+
end
|
140
|
+
if i.is_a? Array
|
141
|
+
i = i.join(' ').strip
|
142
|
+
end
|
143
|
+
if i.start_with? 'http'
|
144
|
+
::Open.in_browser(i, &block)
|
145
|
+
else # this is the default
|
146
|
+
::Open.in_editor(i, &block)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# ========================================================================= #
|
151
|
+
# === Roebe.is_on_roebe?
|
152
|
+
# ========================================================================= #
|
153
|
+
def self.is_on_roebe?
|
154
|
+
ENV['IS_ROEBE'].to_s == '1'
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
if __FILE__ == $PROGRAM_NAME
|
160
|
+
puts Open.use_which_editor?
|
161
|
+
puts Open.use_which_browser?
|
162
|
+
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.23'
|
13
|
+
|
14
|
+
# ========================================================================= #
|
15
|
+
# === LAST_UPDATE
|
16
|
+
# ========================================================================= #
|
17
|
+
LAST_UPDATE = '03.10.2022'
|
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
|
+
chrome # firefox
|
@@ -0,0 +1 @@
|
|
1
|
+
bluefish
|
data/lib/open.rb
ADDED
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 firefo, palemoon or vivaldi. 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
|
+
}
|