universal_pipe_handler 0.0.10
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.
- checksums.yaml +7 -0
- data/README.md +461 -0
- data/doc/README.gen +417 -0
- data/doc/todo/todo_for_the_universal_pipe_handler_project.md +300 -0
- data/img/UNIVERSAL_PIPE_HANDLER_LOGO.jpg +0 -0
- data/img/pipe_paradise.png +0 -0
- data/lib/universal_pipe_handler/base/base.rb +147 -0
- data/lib/universal_pipe_handler/cmdlet/cmdlet.rb +287 -0
- data/lib/universal_pipe_handler/cmdlets/add.rb +15 -0
- data/lib/universal_pipe_handler/cmdlets/add_audio.rb +22 -0
- data/lib/universal_pipe_handler/cmdlets/all.rb +37 -0
- data/lib/universal_pipe_handler/cmdlets/any.rb +25 -0
- data/lib/universal_pipe_handler/cmdlets/ascii_video.rb +30 -0
- data/lib/universal_pipe_handler/cmdlets/assign.rb +24 -0
- data/lib/universal_pipe_handler/cmdlets/capture_screen.rb +46 -0
- data/lib/universal_pipe_handler/cmdlets/colourize.rb +35 -0
- data/lib/universal_pipe_handler/cmdlets/convert_to.rb +21 -0
- data/lib/universal_pipe_handler/cmdlets/convert_to_images.rb +17 -0
- data/lib/universal_pipe_handler/cmdlets/convert_to_mp3.rb +28 -0
- data/lib/universal_pipe_handler/cmdlets/convert_to_wav.rb +17 -0
- data/lib/universal_pipe_handler/cmdlets/copy_directories.rb +23 -0
- data/lib/universal_pipe_handler/cmdlets/count_character.rb +31 -0
- data/lib/universal_pipe_handler/cmdlets/count_longest_row.rb +21 -0
- data/lib/universal_pipe_handler/cmdlets/crop.rb +26 -0
- data/lib/universal_pipe_handler/cmdlets/cut.rb +101 -0
- data/lib/universal_pipe_handler/cmdlets/days.rb +41 -0
- data/lib/universal_pipe_handler/cmdlets/decolourize.rb +25 -0
- data/lib/universal_pipe_handler/cmdlets/download.rb +30 -0
- data/lib/universal_pipe_handler/cmdlets/download_torrent.rb +17 -0
- data/lib/universal_pipe_handler/cmdlets/duration.rb +34 -0
- data/lib/universal_pipe_handler/cmdlets/extract.rb +27 -0
- data/lib/universal_pipe_handler/cmdlets/extract_all.rb +23 -0
- data/lib/universal_pipe_handler/cmdlets/extract_audio.rb +30 -0
- data/lib/universal_pipe_handler/cmdlets/extract_video.rb +18 -0
- data/lib/universal_pipe_handler/cmdlets/find_all.rb +40 -0
- data/lib/universal_pipe_handler/cmdlets/generate_random_video.rb +29 -0
- data/lib/universal_pipe_handler/cmdlets/generate_string.rb +27 -0
- data/lib/universal_pipe_handler/cmdlets/get_all_audio_files.rb +33 -0
- data/lib/universal_pipe_handler/cmdlets/get_all_files.rb +61 -0
- data/lib/universal_pipe_handler/cmdlets/get_all_images.rb +47 -0
- data/lib/universal_pipe_handler/cmdlets/get_all_images_including_subdirs.rb +26 -0
- data/lib/universal_pipe_handler/cmdlets/get_all_video_files.rb +34 -0
- data/lib/universal_pipe_handler/cmdlets/get_last_characters.rb +24 -0
- data/lib/universal_pipe_handler/cmdlets/help.rb +36 -0
- data/lib/universal_pipe_handler/cmdlets/identify.rb +29 -0
- data/lib/universal_pipe_handler/cmdlets/increase_audio.rb +26 -0
- data/lib/universal_pipe_handler/cmdlets/install.rb +32 -0
- data/lib/universal_pipe_handler/cmdlets/match_regex.rb +24 -0
- data/lib/universal_pipe_handler/cmdlets/n_directories.rb +25 -0
- data/lib/universal_pipe_handler/cmdlets/n_files.rb +20 -0
- data/lib/universal_pipe_handler/cmdlets/n_words.rb +25 -0
- data/lib/universal_pipe_handler/cmdlets/number_lines.rb +34 -0
- data/lib/universal_pipe_handler/cmdlets/open_in_browser.rb +40 -0
- data/lib/universal_pipe_handler/cmdlets/pad_left.rb +20 -0
- data/lib/universal_pipe_handler/cmdlets/pad_right.rb +20 -0
- data/lib/universal_pipe_handler/cmdlets/play.rb +18 -0
- data/lib/universal_pipe_handler/cmdlets/position.rb +21 -0
- data/lib/universal_pipe_handler/cmdlets/processes.rb +18 -0
- data/lib/universal_pipe_handler/cmdlets/random.rb +21 -0
- data/lib/universal_pipe_handler/cmdlets/random_video.rb +23 -0
- data/lib/universal_pipe_handler/cmdlets/read_file.rb +44 -0
- data/lib/universal_pipe_handler/cmdlets/read_line.rb +31 -0
- data/lib/universal_pipe_handler/cmdlets/read_n_lines.rb +38 -0
- data/lib/universal_pipe_handler/cmdlets/read_n_lines_inverted.rb +36 -0
- data/lib/universal_pipe_handler/cmdlets/remove_audio.rb +22 -0
- data/lib/universal_pipe_handler/cmdlets/remove_comments.rb +26 -0
- data/lib/universal_pipe_handler/cmdlets/remove_directories.rb +29 -0
- data/lib/universal_pipe_handler/cmdlets/remove_html.rb +25 -0
- data/lib/universal_pipe_handler/cmdlets/remove_newlines.rb +23 -0
- data/lib/universal_pipe_handler/cmdlets/remove_numbers.rb +25 -0
- data/lib/universal_pipe_handler/cmdlets/repackage_to.rb +27 -0
- data/lib/universal_pipe_handler/cmdlets/replace_underscores.rb +29 -0
- data/lib/universal_pipe_handler/cmdlets/resize.rb +39 -0
- data/lib/universal_pipe_handler/cmdlets/resize_image.rb +45 -0
- data/lib/universal_pipe_handler/cmdlets/reverse.rb +22 -0
- data/lib/universal_pipe_handler/cmdlets/screenshot.rb +41 -0
- data/lib/universal_pipe_handler/cmdlets/search_torrent.rb +24 -0
- data/lib/universal_pipe_handler/cmdlets/seconds.rb +23 -0
- data/lib/universal_pipe_handler/cmdlets/select.rb +23 -0
- data/lib/universal_pipe_handler/cmdlets/show_lines.rb +31 -0
- data/lib/universal_pipe_handler/cmdlets/shuffle.rb +16 -0
- data/lib/universal_pipe_handler/cmdlets/shuffle_csv.rb +55 -0
- data/lib/universal_pipe_handler/cmdlets/size.rb +21 -0
- data/lib/universal_pipe_handler/cmdlets/sort_alphabetical.rb +20 -0
- data/lib/universal_pipe_handler/cmdlets/sort_by_date.rb +23 -0
- data/lib/universal_pipe_handler/cmdlets/starts_with.rb +25 -0
- data/lib/universal_pipe_handler/cmdlets/stat_file.rb +61 -0
- data/lib/universal_pipe_handler/cmdlets/to_ascii.rb +38 -0
- data/lib/universal_pipe_handler/cmdlets/to_camel_case.rb +38 -0
- data/lib/universal_pipe_handler/cmdlets/to_dna.rb +31 -0
- data/lib/universal_pipe_handler/cmdlets/to_movie.rb +16 -0
- data/lib/universal_pipe_handler/cmdlets/to_pdf.rb +58 -0
- data/lib/universal_pipe_handler/cmdlets/translate.rb +36 -0
- data/lib/universal_pipe_handler/cmdlets/upload_to.rb +29 -0
- data/lib/universal_pipe_handler/cmdlets/word_count.rb +39 -0
- data/lib/universal_pipe_handler/cmdlets/word_wrap.rb +26 -0
- data/lib/universal_pipe_handler/cmdlets/write_to.rb +51 -0
- data/lib/universal_pipe_handler/cmdlets/years.rb +30 -0
- data/lib/universal_pipe_handler/cmdlets_handler/cmdlets_handler.rb +193 -0
- data/lib/universal_pipe_handler/colours/colourize.rb +112 -0
- data/lib/universal_pipe_handler/colours/colours.rb +54 -0
- data/lib/universal_pipe_handler/configuration/configuration.rb +18 -0
- data/lib/universal_pipe_handler/constants/constants.rb +201 -0
- data/lib/universal_pipe_handler/dataset/dataset.rb +14 -0
- data/lib/universal_pipe_handler/project/project.rb +36 -0
- data/lib/universal_pipe_handler/requires/do_require_the_individual_cmdlet_files.rb +21 -0
- data/lib/universal_pipe_handler/requires/require_the_universal_pipe_handler.rb +14 -0
- data/lib/universal_pipe_handler/shell/shell.rb +256 -0
- data/lib/universal_pipe_handler/toplevel_methods/all_actions.rb +48 -0
- data/lib/universal_pipe_handler/toplevel_methods/cmdlet_directory.rb +22 -0
- data/lib/universal_pipe_handler/toplevel_methods/e.rb +16 -0
- data/lib/universal_pipe_handler/toplevel_methods/misc.rb +54 -0
- data/lib/universal_pipe_handler/toplevel_methods/rds.rb +18 -0
- data/lib/universal_pipe_handler/toplevel_methods/token.rb +18 -0
- data/lib/universal_pipe_handler/version/version.rb +19 -0
- data/lib/universal_pipe_handler/yaml/aliases_to_cmdlets.yml +250 -0
- data/lib/universal_pipe_handler/yaml/allowed_cmdlets.yml +118 -0
- data/lib/universal_pipe_handler/yaml/predefined_methods.yml +15 -0
- data/lib/universal_pipe_handler.rb +5 -0
- data/test/testing_the_universal_pipe_handler.rb +65 -0
- data/test/this_file +46 -0
- data/universal_pipe_handler.gemspec +80 -0
- metadata +299 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# === UniversalPipeHandler::Cmdlet
|
|
6
|
+
#
|
|
7
|
+
# This class will evaluate a single cmdlet instruction.
|
|
8
|
+
#
|
|
9
|
+
# What is a cmdlet?
|
|
10
|
+
#
|
|
11
|
+
# A cmdlet, also known as a commandlet, is an individual pipe-element
|
|
12
|
+
# such as the two commandlets ls and nl in the following pipe
|
|
13
|
+
# instruction:
|
|
14
|
+
#
|
|
15
|
+
# 'ls | nl'
|
|
16
|
+
#
|
|
17
|
+
# Usage example for class Cmdlet:
|
|
18
|
+
#
|
|
19
|
+
# UniversalPipeHandler::Cmdlet.new(ARGV)
|
|
20
|
+
#
|
|
21
|
+
# =========================================================================== #
|
|
22
|
+
# require 'universal_pipe_handler/cmdlet/cmdlet.rb'
|
|
23
|
+
# =========================================================================== #
|
|
24
|
+
require 'universal_pipe_handler/base/base.rb'
|
|
25
|
+
|
|
26
|
+
module UniversalPipeHandler
|
|
27
|
+
|
|
28
|
+
class Cmdlet < Base # === UniversalPipeHandler::Cmdlet
|
|
29
|
+
|
|
30
|
+
require 'universal_pipe_handler/toplevel_methods/misc.rb'
|
|
31
|
+
|
|
32
|
+
# ========================================================================= #
|
|
33
|
+
# === NAMESPACE
|
|
34
|
+
# ========================================================================= #
|
|
35
|
+
NAMESPACE = inspect
|
|
36
|
+
|
|
37
|
+
# ========================================================================= #
|
|
38
|
+
# === initialize
|
|
39
|
+
# ========================================================================= #
|
|
40
|
+
def initialize(
|
|
41
|
+
commandline_arguments = ARGV,
|
|
42
|
+
run_already = true
|
|
43
|
+
)
|
|
44
|
+
reset
|
|
45
|
+
# ======================================================================= #
|
|
46
|
+
# Must ensure that it is an Array at all times:
|
|
47
|
+
# ======================================================================= #
|
|
48
|
+
commandline_arguments = [commandline_arguments].flatten.compact
|
|
49
|
+
set_commandline_arguments(
|
|
50
|
+
commandline_arguments
|
|
51
|
+
)
|
|
52
|
+
set_content(commandline_arguments.first)
|
|
53
|
+
case run_already
|
|
54
|
+
# ======================================================================= #
|
|
55
|
+
# === :do_not_run_yet
|
|
56
|
+
# ======================================================================= #
|
|
57
|
+
when :do_not_run_yet
|
|
58
|
+
run_already = false
|
|
59
|
+
end
|
|
60
|
+
run if run_already
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# ========================================================================= #
|
|
64
|
+
# === reset (reset tag)
|
|
65
|
+
# ========================================================================= #
|
|
66
|
+
def reset
|
|
67
|
+
super()
|
|
68
|
+
# ======================================================================= #
|
|
69
|
+
# === @namespace
|
|
70
|
+
# ======================================================================= #
|
|
71
|
+
@namespace = NAMESPACE
|
|
72
|
+
# ======================================================================= #
|
|
73
|
+
# === @internal_hash
|
|
74
|
+
# ======================================================================= #
|
|
75
|
+
@internal_hash = {}
|
|
76
|
+
# ======================================================================= #
|
|
77
|
+
# === :valid_action
|
|
78
|
+
#
|
|
79
|
+
# This will be true if the action is valid.
|
|
80
|
+
# ======================================================================= #
|
|
81
|
+
@internal_hash[:valid_action] = false
|
|
82
|
+
# ======================================================================= #
|
|
83
|
+
# === :content
|
|
84
|
+
# ======================================================================= #
|
|
85
|
+
@internal_hash[:content] = nil
|
|
86
|
+
# ======================================================================= #
|
|
87
|
+
# === :may_we_exit
|
|
88
|
+
# ======================================================================= #
|
|
89
|
+
@internal_hash[:may_we_exit] = true
|
|
90
|
+
set_start_dir
|
|
91
|
+
# ======================================================================= #
|
|
92
|
+
# === :pipe_aliases
|
|
93
|
+
# ======================================================================= #
|
|
94
|
+
@internal_hash[:pipe_aliases] = YAML.load_file(
|
|
95
|
+
UniversalPipeHandler.file_pipe_aliases
|
|
96
|
+
)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# ========================================================================= #
|
|
100
|
+
# === set_content
|
|
101
|
+
# ========================================================================= #
|
|
102
|
+
def set_content(i)
|
|
103
|
+
i = i.join(' ') if i.is_a? Array
|
|
104
|
+
@internal_hash[:content] = i.dup
|
|
105
|
+
# sanitize_content
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# ========================================================================= #
|
|
109
|
+
# === strip!
|
|
110
|
+
# ========================================================================= #
|
|
111
|
+
def strip!
|
|
112
|
+
@internal_hash[:content].strip! if @internal_hash[:content]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# ========================================================================= #
|
|
116
|
+
# === content?
|
|
117
|
+
# ========================================================================= #
|
|
118
|
+
def content?
|
|
119
|
+
@internal_hash[:content]
|
|
120
|
+
end; alias content content? # === content
|
|
121
|
+
alias string? content? # === string?
|
|
122
|
+
alias input? content? # === input?
|
|
123
|
+
|
|
124
|
+
# ========================================================================= #
|
|
125
|
+
# === to_s
|
|
126
|
+
# ========================================================================= #
|
|
127
|
+
def to_s
|
|
128
|
+
@internal_hash[:content].to_s
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# ========================================================================= #
|
|
132
|
+
# === pipe_aliases?
|
|
133
|
+
# ========================================================================= #
|
|
134
|
+
def pipe_aliases?
|
|
135
|
+
@internal_hash[:pipe_aliases]
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# ========================================================================= #
|
|
139
|
+
# === may_we_exit?
|
|
140
|
+
# ========================================================================= #
|
|
141
|
+
def may_we_exit?
|
|
142
|
+
@internal_hash[:may_we_exit]
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# ========================================================================= #
|
|
146
|
+
# === result?
|
|
147
|
+
# ========================================================================= #
|
|
148
|
+
def result?
|
|
149
|
+
::UniversalPipeHandler.result?
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# ========================================================================= #
|
|
153
|
+
# === run (run tag)
|
|
154
|
+
# ========================================================================= #
|
|
155
|
+
def run
|
|
156
|
+
try_to_find_an_alias
|
|
157
|
+
evaluate_the_content
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# ========================================================================= #
|
|
161
|
+
# === set_start_dir
|
|
162
|
+
# ========================================================================= #
|
|
163
|
+
def set_start_dir(i = return_pwd)
|
|
164
|
+
@internal_hash[:start_dir] = i
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# ========================================================================= #
|
|
168
|
+
# === start_dir?
|
|
169
|
+
# ========================================================================= #
|
|
170
|
+
def start_dir?
|
|
171
|
+
@internal_hash[:start_dir]
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# ========================================================================= #
|
|
175
|
+
# === set_result
|
|
176
|
+
# ========================================================================= #
|
|
177
|
+
def set_result(i)
|
|
178
|
+
::UniversalPipeHandler.set_result(i)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# ========================================================================= #
|
|
182
|
+
# === try_to_find_an_alias
|
|
183
|
+
#
|
|
184
|
+
# We try to find an alias here.
|
|
185
|
+
# ========================================================================= #
|
|
186
|
+
def try_to_find_an_alias
|
|
187
|
+
input_may_include_an_alias = false
|
|
188
|
+
first_command = content?.split(' ')
|
|
189
|
+
if pipe_aliases?.keys.include? first_command
|
|
190
|
+
# ===================================================================== #
|
|
191
|
+
# In this case, we don't need to do any replacement, because the
|
|
192
|
+
# key is already registered.
|
|
193
|
+
# ===================================================================== #
|
|
194
|
+
else # else try to find an alias.
|
|
195
|
+
# ===================================================================== #
|
|
196
|
+
# Grab the possible results next:
|
|
197
|
+
# ===================================================================== #
|
|
198
|
+
result = pipe_aliases?.keys.select { |entry|
|
|
199
|
+
content?.include? entry
|
|
200
|
+
}
|
|
201
|
+
# ===================================================================== #
|
|
202
|
+
# Next sort it by size so we get the highest entry first:
|
|
203
|
+
# ===================================================================== #
|
|
204
|
+
result = result.sort_by(&:length).reverse
|
|
205
|
+
# ===================================================================== #
|
|
206
|
+
# Result may now be something like this Array here:
|
|
207
|
+
#
|
|
208
|
+
# ["read file", "read"]
|
|
209
|
+
#
|
|
210
|
+
# ===================================================================== #
|
|
211
|
+
input_may_include_an_alias = true unless result.empty?
|
|
212
|
+
if input_may_include_an_alias
|
|
213
|
+
# =================================================================== #
|
|
214
|
+
# We grab the first entry.
|
|
215
|
+
# =================================================================== #
|
|
216
|
+
first = result.first
|
|
217
|
+
the_alias = pipe_aliases?[first]
|
|
218
|
+
content?.gsub!(/#{first}/,the_alias)
|
|
219
|
+
else # else we don't have an alias. Pass through then.
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# ========================================================================= #
|
|
225
|
+
# === evaluate_the_content
|
|
226
|
+
#
|
|
227
|
+
# Here we must fetch the toplevel method.
|
|
228
|
+
# ========================================================================= #
|
|
229
|
+
def evaluate_the_content(
|
|
230
|
+
content = content?
|
|
231
|
+
)
|
|
232
|
+
_ = content.dup
|
|
233
|
+
if _.include? ' '
|
|
234
|
+
_ = _.split(' ').first
|
|
235
|
+
end
|
|
236
|
+
::UniversalPipeHandler.set_working_directory(start_dir?)
|
|
237
|
+
_ = return_alias_to_this_cmdlet_or_leave_it_unmodified(_)
|
|
238
|
+
name_of_the_method = 'cmdlet_'+_.to_s
|
|
239
|
+
unless UniversalPipeHandler.respond_to?(name_of_the_method.to_sym)
|
|
240
|
+
# Require all toplevel methods next:
|
|
241
|
+
require 'universal_pipe_handler/requires/do_require_the_individual_cmdlet_files.rb'
|
|
242
|
+
UniversalPipeHandler.do_require_the_individual_cmdlet_files
|
|
243
|
+
end
|
|
244
|
+
_result = ::UniversalPipeHandler.send(name_of_the_method.to_sym)
|
|
245
|
+
if _result.is_a? Array
|
|
246
|
+
set_result(_result)
|
|
247
|
+
end
|
|
248
|
+
end; alias do_evaluate evaluate_the_content # === do_evaluate
|
|
249
|
+
|
|
250
|
+
# ========================================================================= #
|
|
251
|
+
# === return_alias_to_this_cmdlet_or_leave_it_unmodified
|
|
252
|
+
# ========================================================================= #
|
|
253
|
+
def return_alias_to_this_cmdlet_or_leave_it_unmodified(
|
|
254
|
+
i, pipe_aliases = pipe_aliases?
|
|
255
|
+
)
|
|
256
|
+
if pipe_aliases.has_key? i
|
|
257
|
+
i = pipe_aliases[i]
|
|
258
|
+
end
|
|
259
|
+
return i
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# ========================================================================= #
|
|
263
|
+
# === UniversalPipeHandler::Cmdlet[]
|
|
264
|
+
# ========================================================================= #
|
|
265
|
+
def self.[](i = '', optional_argument = nil)
|
|
266
|
+
new(i).data?
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
end; end
|
|
270
|
+
|
|
271
|
+
if __FILE__ == $PROGRAM_NAME
|
|
272
|
+
require 'colours/autoinclude'
|
|
273
|
+
# ========================================================================= #
|
|
274
|
+
# === test
|
|
275
|
+
# ========================================================================= #
|
|
276
|
+
def test(i = ARGV)
|
|
277
|
+
e 'In the method test: '+skyblue(
|
|
278
|
+
UniversalPipeHandler::Cmdlet.new(i) {{ may_we_exit: false }}
|
|
279
|
+
)
|
|
280
|
+
end
|
|
281
|
+
# ========================================================================= #
|
|
282
|
+
# Note that we will test the various formats not here but in the
|
|
283
|
+
# file test/testing_sanitize_pipe.rb instead.
|
|
284
|
+
# ========================================================================= #
|
|
285
|
+
test 'ls'
|
|
286
|
+
#test 'cat /home/x/programming/ruby/src/universal_pipe_handler/README.md'
|
|
287
|
+
end # cmdlet
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/add.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_add
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
def self.cmdlet_add(i = result?)
|
|
13
|
+
end; self.instance_eval { alias add cmdlet_add } # === UniversalPipeHandler.add
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/add_audio.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_add_audio
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
def self.cmdlet_add_audio(i = result?)
|
|
13
|
+
audio_to_add_audio = i
|
|
14
|
+
video_file = result?
|
|
15
|
+
output_file = 'new_'+video_file
|
|
16
|
+
_ = 'ffmpeg -vcodec copy -acodec copy -i '+audio_to_add_audio+' -i '+video_file+' '+output_file
|
|
17
|
+
run_sys_cmd _
|
|
18
|
+
set_result(output_file)
|
|
19
|
+
result?
|
|
20
|
+
end; self.instance_eval { alias add_audio cmdlet_add_audio } # === UniversalPipeHandler.add_audio
|
|
21
|
+
|
|
22
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/all.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_all
|
|
11
|
+
#
|
|
12
|
+
# This action attempts to obtain "all".
|
|
13
|
+
#
|
|
14
|
+
# The very first argument (or the first member of the Array, when i is
|
|
15
|
+
# an Array) is the pattern which we will use to match against.
|
|
16
|
+
# ========================================================================= #
|
|
17
|
+
def self.cmdlet_all(i)
|
|
18
|
+
_ = action_get_all_files
|
|
19
|
+
if i.is_a? Array
|
|
20
|
+
i.pop if i.last == 'files' # Discard "files" entry if it is the last entry.
|
|
21
|
+
end
|
|
22
|
+
if i.is_a? Array
|
|
23
|
+
i = i.first
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
case i
|
|
27
|
+
when 'files'
|
|
28
|
+
else
|
|
29
|
+
match_to_these_file_endings = i
|
|
30
|
+
_.reject! {|entry| entry !~ /#{match_to_these_file_endings}$/ }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
set_result(_)
|
|
34
|
+
return result?
|
|
35
|
+
end; self.instance_eval { alias all cmdlet_all } # === UniversalPipeHandler.all
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/any.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_any (any tag)
|
|
11
|
+
#
|
|
12
|
+
# Fetch any single file.
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
def self.cmdlet_any(i = 'avi')
|
|
15
|
+
to_match_against = i
|
|
16
|
+
_ = action_get_all_files
|
|
17
|
+
_.reject! {|file| file !~ /#{to_match_against}$/ }
|
|
18
|
+
if ! _.empty?
|
|
19
|
+
_ = _.sample # Return the first element.
|
|
20
|
+
end
|
|
21
|
+
set_result( _)
|
|
22
|
+
return result?
|
|
23
|
+
end; self.instance_eval { alias any cmdlet_any } # === UniversalPipeHandler.any
|
|
24
|
+
|
|
25
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/ascii_video.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_ascii_video
|
|
11
|
+
#
|
|
12
|
+
# Play a video through the aalib. We may however had also default to
|
|
13
|
+
# libcaca, which I am trying since March 2015.
|
|
14
|
+
# ========================================================================= #
|
|
15
|
+
def self.cmdlet_ascii_video(
|
|
16
|
+
i = result?,
|
|
17
|
+
play_how = :libcaca
|
|
18
|
+
)
|
|
19
|
+
i = i.first if i.is_a? Array
|
|
20
|
+
case play_how
|
|
21
|
+
when :libcaca
|
|
22
|
+
_ = "mplayer -vo caca #{i}"
|
|
23
|
+
else # Default to allib then.
|
|
24
|
+
_ = "mplayer -vo aa #{i}"
|
|
25
|
+
end
|
|
26
|
+
esystem(_)
|
|
27
|
+
set_result
|
|
28
|
+
end; self.instance_eval { alias ascii_video cmdlet_ascii_video } # === UniversalPipeHandler.ascii_video
|
|
29
|
+
|
|
30
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/assign.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_assign
|
|
11
|
+
#
|
|
12
|
+
# Simply assign something here.
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
def self.cmdlet_assign(i)
|
|
15
|
+
if i =~ /^\d+$/ # User did input a number only.
|
|
16
|
+
i = Dir['*'][i.to_i - 1]
|
|
17
|
+
end unless File.exist? i
|
|
18
|
+
i = sanitize_url(i) if i.start_with? ':' # assume it is a special keyword.
|
|
19
|
+
set_file(i) # We also keep track of the file here.
|
|
20
|
+
set_result(i) # This is our assignment-method for the @result variable.
|
|
21
|
+
return result?
|
|
22
|
+
end; self.instance_eval { alias assign cmdlet_assign } # === UniversalPipeHandler.assign
|
|
23
|
+
|
|
24
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/capture_screen.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_capture_screen
|
|
11
|
+
#
|
|
12
|
+
# Make a screencast with this method. The argument it accepts will break
|
|
13
|
+
# after n seconds, if given. Otherwise endless.
|
|
14
|
+
#
|
|
15
|
+
# A typical example for this would look like:
|
|
16
|
+
#
|
|
17
|
+
# ffmpeg -t 00:00:02 -f x11grab -y -r 12 -s 800x600 -i :0.0+480,200 -vcodec ffv1 -sameq out.avi
|
|
18
|
+
#
|
|
19
|
+
# ========================================================================= #
|
|
20
|
+
def self.cmdlet_capture_screen(
|
|
21
|
+
optional_how_many_seconds = nil
|
|
22
|
+
)
|
|
23
|
+
# output_file = '$MY_TEMP/GRABBED_X11_screencast.mov'
|
|
24
|
+
output_file = 'captured_screencast-'+return_date+'_'+get_time(':')+'.avi'
|
|
25
|
+
set_file(output_file) # Now we can use @file.
|
|
26
|
+
capture_screen = CaptureScreen.new :dont_run_yet
|
|
27
|
+
capture_screen.overwrite_if_the_file_already_exists
|
|
28
|
+
capture_screen.framerate 25
|
|
29
|
+
capture_screen.size '1280x720'
|
|
30
|
+
# capture_screen.size '1024x800'
|
|
31
|
+
# capture_screen.size '800x600'
|
|
32
|
+
capture_screen.vcodec 'ffv1'
|
|
33
|
+
capture_screen.sameq
|
|
34
|
+
capture_screen.no_threads
|
|
35
|
+
capture_screen.store_here = file?
|
|
36
|
+
if optional_how_many_seconds
|
|
37
|
+
twenty_four = TwentyfourHoursNotation.new
|
|
38
|
+
# Must convert the seconds into the long-variant. This is done
|
|
39
|
+
# By the TwentyfourHoursNotation class.
|
|
40
|
+
capture_screen.set_duration( twenty_four.simple_format(optional_how_many_seconds) )
|
|
41
|
+
end
|
|
42
|
+
capture_screen.run
|
|
43
|
+
set_result(file?)
|
|
44
|
+
end; self.instance_eval { alias capture_screen cmdlet_capture_screen } # === UniversalPipeHandler.capture_screen
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/colourize.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_colourize
|
|
11
|
+
#
|
|
12
|
+
# This instruction handles colourization; the method can be used
|
|
13
|
+
# specifically to colourize the given input.
|
|
14
|
+
#
|
|
15
|
+
# Before September 2012 we used an internal class for this, however
|
|
16
|
+
# since as of September 2012 we will prefer to use CodeRay instead,
|
|
17
|
+
# and optionally fallback to the Colourize class in the event
|
|
18
|
+
# that CodeRay is unavailable.
|
|
19
|
+
# ========================================================================= #
|
|
20
|
+
def self.cmdlet_colourize(i = result?)
|
|
21
|
+
# If Coderay is available, use that.
|
|
22
|
+
if Object.const_defined? :CodeRay
|
|
23
|
+
if i.is_a? Array
|
|
24
|
+
i = i.join # Won't need to join with newlines here.
|
|
25
|
+
end
|
|
26
|
+
_ = CodeRay.scan(i, :ruby).term # This will become a String.
|
|
27
|
+
else # Else use the project-internal Colourize class, which resides under addons/colours.rb.
|
|
28
|
+
_ = Colourize.new(i) # bl $PIPE_HANDLER/addons/colourize.rb
|
|
29
|
+
_ = _.string
|
|
30
|
+
end
|
|
31
|
+
set_result(_) # Better keep it in array form.
|
|
32
|
+
return result?
|
|
33
|
+
end; self.instance_eval { alias colourize cmdlet_colourize } # === UniversalPipeHandler.colourize
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/convert_to.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_convert_to
|
|
11
|
+
#
|
|
12
|
+
# This could in principle convert between different formats.
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
def self.cmdlet_convert_to(which_format)
|
|
15
|
+
case which_format
|
|
16
|
+
when 'wav'
|
|
17
|
+
set_result(MultimediaParadise.mp3_to_wav(@target_file))
|
|
18
|
+
end
|
|
19
|
+
end; self.instance_eval { alias convert_to cmdlet_convert_to } # === UniversalPipeHandler.convert_to
|
|
20
|
+
|
|
21
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/convert_to_images.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_convert_to_images
|
|
11
|
+
#
|
|
12
|
+
# This action converts a video file to images.
|
|
13
|
+
# ========================================================================= #
|
|
14
|
+
def self.cmdlet_convert_to_images(i = result?)
|
|
15
|
+
end; self.instance_eval { alias convert_to_images cmdlet_convert_to_images } # === UniversalPipeHandler.convert_to_images
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/convert_to_mp3.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_convert_to_mp3
|
|
11
|
+
#
|
|
12
|
+
# This will convert into .mp3. If the input file already is a .mp3 file
|
|
13
|
+
# then we won't have to do a conversion.
|
|
14
|
+
# ========================================================================= #
|
|
15
|
+
def self.cmdlet_convert_to_mp3
|
|
16
|
+
e 'Now converting all found audio files to .wav format.'
|
|
17
|
+
set_result result?.map { |entry|
|
|
18
|
+
if entry.include? '.ogg'
|
|
19
|
+
MultimediaParadise::MultimediaConversions.ogg_to_mp3(entry)
|
|
20
|
+
elsif entry.include? '.wav'
|
|
21
|
+
MultimediaParadise::MultimediaConversions.wav_to_mp3(entry)
|
|
22
|
+
else
|
|
23
|
+
entry
|
|
24
|
+
end
|
|
25
|
+
}
|
|
26
|
+
end; self.instance_eval { alias convert_to_mp3 cmdlet_convert_to_mp3 } # === UniversalPipeHandler.convert_to_mp3
|
|
27
|
+
|
|
28
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/convert_to_wav.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_convert_to_wav
|
|
11
|
+
# ========================================================================= #
|
|
12
|
+
def self.cmdlet_convert_to_wav
|
|
13
|
+
e 'Now converting all found audio files to .wav format.' if be_verbose?
|
|
14
|
+
result?.each { |entry| MultimediaParadise.mp3_to_wav(entry) }
|
|
15
|
+
end; self.instance_eval { alias convert_to_wav cmdlet_convert_to_wav } # === UniversalPipeHandler.convert_to_wav
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/copy_directories.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_copy_directories
|
|
11
|
+
#
|
|
12
|
+
# This method will simply copy directories. We tap into the method
|
|
13
|
+
# return_directories() which is defined in shared.rb
|
|
14
|
+
# ========================================================================= #
|
|
15
|
+
def self.cmdlet_copy_directories(
|
|
16
|
+
i = result?
|
|
17
|
+
)
|
|
18
|
+
@we_want_to_copy_something = true
|
|
19
|
+
set_result(return_directories)
|
|
20
|
+
return result?
|
|
21
|
+
end; self.instance_eval { alias copy_directories cmdlet_copy_directories } # === UniversalPipeHandler.copy_directories
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# Encoding: UTF-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
# =========================================================================== #
|
|
5
|
+
# require 'universal_pipe_handler/cmdlets/count_character.rb'
|
|
6
|
+
# =========================================================================== #
|
|
7
|
+
module UniversalPipeHandler
|
|
8
|
+
|
|
9
|
+
# ========================================================================= #
|
|
10
|
+
# === UniversalPipeHandler.cmdlet_count_character
|
|
11
|
+
#
|
|
12
|
+
# Count how many occurences we can find of a specific character.
|
|
13
|
+
#
|
|
14
|
+
# That character should be passed to this method.
|
|
15
|
+
# ========================================================================= #
|
|
16
|
+
def self.cmdlet_count_character(
|
|
17
|
+
this_char = :all
|
|
18
|
+
)
|
|
19
|
+
_ = result? # Work on a copy of @result here.
|
|
20
|
+
case this_char
|
|
21
|
+
when :all
|
|
22
|
+
_ = _.size
|
|
23
|
+
else
|
|
24
|
+
_ = _.join if _.is_a? Array
|
|
25
|
+
_ = _.scan(/#{this_char}/).size
|
|
26
|
+
end
|
|
27
|
+
set_result(_)
|
|
28
|
+
return result?
|
|
29
|
+
end; self.instance_eval { alias count_character cmdlet_count_character } # === UniversalPipeHandler.count_character
|
|
30
|
+
|
|
31
|
+
end
|