universal_pipe_handler 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- 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,25 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/starts_with.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === UniversalPipeHandler.cmdlet_starts_with
|
11
|
+
#
|
12
|
+
# This method will iterate over our array and return a match.
|
13
|
+
# ========================================================================= #
|
14
|
+
def self.cmdlet_starts_with(
|
15
|
+
search_term = result?
|
16
|
+
)
|
17
|
+
result = []
|
18
|
+
|
19
|
+
result?.each { |line|
|
20
|
+
result << line.chomp if line.start_with?(search_term) #line[0, search_term.size] == search_term
|
21
|
+
} if result?.is_a? Array
|
22
|
+
set_result(result)
|
23
|
+
end; self.instance_eval { alias starts_with cmdlet_starts_with } # === UniversalPipeHandler.starts_with
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/stat_file.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'stat_file'
|
11
|
+
rescue LoadError; end
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === UniversalPipeHandler.cmdlet_stat_file (stat tag)
|
15
|
+
#
|
16
|
+
# Since as of August 2011 we get extended stat info, by tapping into
|
17
|
+
# class StatFile.
|
18
|
+
#
|
19
|
+
# To try this, you can do:
|
20
|
+
#
|
21
|
+
# assign :main_video | stat file
|
22
|
+
#
|
23
|
+
# ========================================================================= #
|
24
|
+
def self.cmdlet_stat_file(i = result?)
|
25
|
+
if i.is_a? Array
|
26
|
+
i.each {|entry|
|
27
|
+
action_stat_file(entry)
|
28
|
+
}
|
29
|
+
else
|
30
|
+
if i.nil?
|
31
|
+
e 'Please provide a valid argument.'
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
i = i.to_s
|
35
|
+
if File.exist? i.to_s
|
36
|
+
stat_file = StatFile.new(i, :dont_be_verbose)
|
37
|
+
stat_file.stat_file(i)
|
38
|
+
@result = '' if @result.is_a? Array # Reset the result here.
|
39
|
+
@result << stat_file.result
|
40
|
+
file_size = File.size(i).to_s
|
41
|
+
file_end = File.extname(i).gsub(/\./,'')
|
42
|
+
n_lines = 0 # safeguard.
|
43
|
+
n_characters = 0 # safeguard.
|
44
|
+
case file_end
|
45
|
+
when *ARRAY_MULTIMEDIA_FILES # Pass through here - we can't read these file types..
|
46
|
+
else
|
47
|
+
readlines = File.readlines(i)
|
48
|
+
n_lines = readlines.size.to_s
|
49
|
+
n_characters = readlines.join.split(/\s+/).size.to_s
|
50
|
+
end
|
51
|
+
file_size = Colours.slateblue(file_size.to_s)
|
52
|
+
@result << N+' The file `'+sfile(i.to_s)+'`'+N+' has '+n_lines.to_s+
|
53
|
+
' lines, '+sfancy(n_characters.to_s)+' characters and a '+
|
54
|
+
'file size of `'+file_size+'`.'
|
55
|
+
else
|
56
|
+
e 'No file could be found at `'+sfancy(i.to_s)+'`.'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/to_ascii.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === UniversalPipeHandler.cmdlet_to_ascii
|
11
|
+
#
|
12
|
+
# Convert image files to ascii format at once, using the program called
|
13
|
+
# jp2a. Obviously for this to work, jp2a must have been installed.
|
14
|
+
#
|
15
|
+
# Since as of May 2015, we also store in an .ascii file automatically.
|
16
|
+
#
|
17
|
+
# Standalone test, through the pipeshell:
|
18
|
+
#
|
19
|
+
# random image from :njoy_dir | to ascii
|
20
|
+
#
|
21
|
+
# ========================================================================= #
|
22
|
+
def self.cmdlet_to_ascii
|
23
|
+
cmd = 'jp2a'
|
24
|
+
if result?
|
25
|
+
result?.each { |entry|
|
26
|
+
_ = cmd+' '+entry
|
27
|
+
e _
|
28
|
+
return_value = `#{_}`
|
29
|
+
what = return_value
|
30
|
+
this_file = save_dir?+'ascii_'+
|
31
|
+
File.basename(entry.downcase).tr('.','_')+'.ascii'
|
32
|
+
write_what_into(what, this_file)
|
33
|
+
set_result(this_file)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end; self.instance_eval { alias to_ascii cmdlet_to_ascii } # === UniversalPipeHandler.to_ascii
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/to_camel_case.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
require 'fileutils'
|
10
|
+
require 'universal_pipe_handler/toplevel_methods/e.rb'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === UniversalPipeHandler.cmdlet_to_camel_case
|
14
|
+
# ========================================================================= #
|
15
|
+
def self.cmdlet_to_camel_case(
|
16
|
+
i = result?
|
17
|
+
)
|
18
|
+
array = []
|
19
|
+
if i.is_a? Array
|
20
|
+
i.each {|inner_entry|
|
21
|
+
base_dir = File.dirname(inner_entry)+'/'
|
22
|
+
if File.exist? inner_entry
|
23
|
+
new_name = File.basename(inner_entry).
|
24
|
+
split('_').map { |most_inner_entry| most_inner_entry.capitalize }.join
|
25
|
+
new_name = "#{base_dir}#{new_name}"
|
26
|
+
unless File.exist? new_name
|
27
|
+
FileUtils.mv(inner_entry, new_name)
|
28
|
+
end
|
29
|
+
array << new_name
|
30
|
+
end
|
31
|
+
}
|
32
|
+
end
|
33
|
+
set_result(array)
|
34
|
+
return result?
|
35
|
+
end; self.instance_eval { alias to_camel_case cmdlet_to_camel_case } # === UniversalPipeHandler.to_camel_case
|
36
|
+
self.instance_eval { alias camel_case cmdlet_to_camel_case } # === UniversalPipeHandler.camel_case
|
37
|
+
|
38
|
+
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/to_dna.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === UniversalPipeHandler.cmdlet_to_dna
|
11
|
+
#
|
12
|
+
# This method will convert the given input to a valid DNA string.
|
13
|
+
# We make use of the project called Bioroebe here.
|
14
|
+
#
|
15
|
+
# To test this, start the pipeshell and do:
|
16
|
+
#
|
17
|
+
# assign ACCACACCAUUUCCCAUGGGUGUGUGG | to dna
|
18
|
+
#
|
19
|
+
# ========================================================================= #
|
20
|
+
def self.cmdlet_to_dna(i = result?)
|
21
|
+
unless Object.const_defined? :Bioroebe
|
22
|
+
require 'bioroebe'
|
23
|
+
end
|
24
|
+
if Object.const_defined? :Bioroebe
|
25
|
+
_ = Bioroebe.to_dna(i)
|
26
|
+
set_result(_)
|
27
|
+
end
|
28
|
+
return result?
|
29
|
+
end; self.instance_eval { alias to_dna cmdlet_to_dna } # === UniversalPipeHandler.to_dna
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module UniversalPipeHandler
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === UniversalPipeHandler.cmdlet_to_movie
|
9
|
+
#
|
10
|
+
# This currently is somewhat dysfunct. More accurately, it was never
|
11
|
+
# written.
|
12
|
+
# ========================================================================= #
|
13
|
+
def self.cmdlet_to_movie
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/to_pdf.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === ALSO_OPEN_IN_PDF_VIEWER
|
11
|
+
#
|
12
|
+
# If true we also open it at once.
|
13
|
+
# ========================================================================= #
|
14
|
+
ALSO_OPEN_IN_PDF_VIEWER = true
|
15
|
+
|
16
|
+
# ========================================================================= #
|
17
|
+
# === USE_THIS_PDF_VIEWER
|
18
|
+
# ========================================================================= #
|
19
|
+
USE_THIS_PDF_VIEWER = 'evince' # okular
|
20
|
+
|
21
|
+
# ========================================================================= #
|
22
|
+
# === UniversalPipeHandler.cmdlet_to_pdf
|
23
|
+
#
|
24
|
+
# This currently is somewhat dysfunctional.
|
25
|
+
#
|
26
|
+
# To test this, we could try:
|
27
|
+
#
|
28
|
+
# cat :main_file | to pdf
|
29
|
+
#
|
30
|
+
# ========================================================================= #
|
31
|
+
def self.cmdlet_to_pdf(
|
32
|
+
text_to_write = result?
|
33
|
+
)
|
34
|
+
font_size = 18
|
35
|
+
alignment = :left
|
36
|
+
store_here = 'autogenerated_pdf.pdf'
|
37
|
+
text_to_write = text_to_write.join if text_to_write.is_a? Array
|
38
|
+
if text_to_write.count('"') == 2
|
39
|
+
text_to_write.delete!('"')
|
40
|
+
end
|
41
|
+
if text_to_write.include? '\\n'
|
42
|
+
text_to_write.gsub!(/\\n/, "\n")
|
43
|
+
end
|
44
|
+
Prawn::Document.generate(store_here) {
|
45
|
+
font 'Times-Roman'
|
46
|
+
text text_to_write,
|
47
|
+
align: alignment,
|
48
|
+
size: font_size
|
49
|
+
}
|
50
|
+
set_result(store_here)
|
51
|
+
if ALSO_OPEN_IN_PDF_VIEWER # Open the .pdf next.
|
52
|
+
esystem USE_THIS_PDF_VIEWER+' '+store_here+' &'
|
53
|
+
end
|
54
|
+
return result?
|
55
|
+
end; self.instance_eval { alias to_pdf cmdlet_to_pdf } # === UniversalPipeHandler.to_pdf
|
56
|
+
self.instance_eval { alias action_to_pdf cmdlet_to_pdf } # === UniversalPipeHandler.action_to_pdf
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/cmdlet_translate.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === UniversalPipeHandler.cmdlet_translate
|
11
|
+
#
|
12
|
+
# This method will try to translate english words.
|
13
|
+
#
|
14
|
+
# To try it, one can do:
|
15
|
+
#
|
16
|
+
# assign purview | translate
|
17
|
+
#
|
18
|
+
# ========================================================================= #
|
19
|
+
def self.cmdlet_translate(i = result?)
|
20
|
+
if i.is_a? Array
|
21
|
+
i.each {|entry| action_translate(entry) }
|
22
|
+
else
|
23
|
+
i = i.to_s.chomp
|
24
|
+
if Object.const_defined? :AskEnglishWord
|
25
|
+
do_not_show_the_result
|
26
|
+
@result = AskEnglishWord.new(i, :delay => 0).result
|
27
|
+
else
|
28
|
+
location = ENV['SCIENCE'].to_s+'/YAML/DICTIONARIES/english.yml'
|
29
|
+
english_data = YAML.load_file(location)
|
30
|
+
@result = english_data[i]
|
31
|
+
end
|
32
|
+
result?
|
33
|
+
end
|
34
|
+
end; self.instance_eval { alias translate cmdlet_translate } # === UniversalPipeHandler.translate
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/upload_to.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === UniversalPipeHandler.cmdlet_upload_to
|
11
|
+
#
|
12
|
+
# The first argument shall be where to upload to. We currently use
|
13
|
+
# the FtpParadise to upload to some remote site.
|
14
|
+
#
|
15
|
+
# To try this, do:
|
16
|
+
#
|
17
|
+
# assign :main_file | ftp_upload
|
18
|
+
#
|
19
|
+
# ========================================================================= #
|
20
|
+
def self.cmdlet_upload_to(
|
21
|
+
this_target = 'shevegen.square7.ch' # The target should not include leading http:
|
22
|
+
)
|
23
|
+
this = result?
|
24
|
+
where_to = this_target # Where to we shall upload something.
|
25
|
+
FtpParadise.upload(this, where_to)
|
26
|
+
return result?
|
27
|
+
end; self.instance_eval { alias upload_to cmdlet_upload_to } # === UniversalPipeHandler.upload_to
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/word_count.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === UniversalPipeHandler.cmdlet_word_count
|
11
|
+
#
|
12
|
+
# Count the words here.
|
13
|
+
#
|
14
|
+
# Note that this method will instantly output the results - see the
|
15
|
+
# part of the code that is run in the .each_pair section.
|
16
|
+
# ========================================================================= #
|
17
|
+
def self.cmdlet_word_count
|
18
|
+
pad_n = 80
|
19
|
+
hash = Hash.new(0)
|
20
|
+
result?.join.scan(/\w+\??/) { |word| hash[word] += 1 }
|
21
|
+
@result = hash
|
22
|
+
be_really_verbose_here = true # Hack. For now we will always instantly display the result.
|
23
|
+
if be_really_verbose_here
|
24
|
+
_ = result?.sort_by {|key, value| value }.reverse # Sort by size.
|
25
|
+
_.each { |key, value| # This is now an Array.
|
26
|
+
if Object.const_defined? :Konsole
|
27
|
+
e ('The key `'+mediumaquamarine(key)+'` has been found that '+
|
28
|
+
'many times: ').ljust(pad_n)+orange(value.to_s)
|
29
|
+
else # else use normal module Colours support.
|
30
|
+
e ('The key `'+sfancy(key)+'` has been found that '+
|
31
|
+
'many times: ').ljust(pad_n)+simp(value.to_s)
|
32
|
+
end
|
33
|
+
}
|
34
|
+
set_result nil # Not sure why we set to nil in this case.
|
35
|
+
end
|
36
|
+
do_not_show_the_result
|
37
|
+
end; self.instance_eval { alias word_count cmdlet_word_count } # === UniversalPipeHandler.word_count
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/word_wrap.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === UniversalPipeHandler.cmdlet_word_wrap
|
11
|
+
#
|
12
|
+
# By default, this method will limit the words up towards 80 characters
|
13
|
+
# per given line.
|
14
|
+
#
|
15
|
+
# The first argument to it specifies that 80 characters limit.
|
16
|
+
# ========================================================================= #
|
17
|
+
def self.cmdlet_word_wrap(
|
18
|
+
n_chars_limit = 80
|
19
|
+
)
|
20
|
+
set_result @result.map {|_|
|
21
|
+
_.gsub(/(.{1,#{n_chars_limit}})(\s+|$)/, "\\1\n")
|
22
|
+
}.join if result?
|
23
|
+
return result?
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'universal_pipe_handler/cmdlets/to_pdf.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === UniversalPipeHandler.cmdlet_write_to (write tag)
|
11
|
+
#
|
12
|
+
# This method writes into a text file on the local filesystem.
|
13
|
+
#
|
14
|
+
# It will also respect MACROS such as #APPEND# passed to it.
|
15
|
+
# ========================================================================= #
|
16
|
+
def self.cmdlet_write_to(
|
17
|
+
where_to = result?
|
18
|
+
)
|
19
|
+
require 'save_file'
|
20
|
+
what = result?
|
21
|
+
if where_to.include? '#' # Assume a macro like #APPEND# was given. For this to work, file? must return a non-nil value.
|
22
|
+
where_to = where_to.gsub(/#APPEND#/, file?)
|
23
|
+
end
|
24
|
+
if where_to.end_with? '.csv' # Then we assume this is a .csv file.
|
25
|
+
if what.is_a? Array
|
26
|
+
what.map! {|line|
|
27
|
+
line.join(',')+N
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
if what
|
32
|
+
if what.is_a? Array
|
33
|
+
what = what.join.strip
|
34
|
+
end
|
35
|
+
if File.directory? where_to
|
36
|
+
where_to << '/'+File.basename(what)
|
37
|
+
where_to = rds(where_to)
|
38
|
+
end
|
39
|
+
if File.exist? what
|
40
|
+
e 'Copying '+what+' to `'+sfile(where_to)+'`.' if be_verbose?
|
41
|
+
copy(what, where_to)
|
42
|
+
else
|
43
|
+
e 'Writing into `'+sfile(where_to)+'`.' if be_verbose?
|
44
|
+
SaveFile.write_what_into(what, where_to) # Delegate towards the SaveFile module here.
|
45
|
+
end
|
46
|
+
set_result where_to
|
47
|
+
return result?
|
48
|
+
end
|
49
|
+
end; self.instance_eval { alias write_to cmdlet_write_to } # === UniversalPipeHandler.write_to
|
50
|
+
|
51
|
+
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/years.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module UniversalPipeHandler
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === UniversalPipeHandler.cmdlet_years
|
11
|
+
#
|
12
|
+
# We will convert the amount of years into seconds.
|
13
|
+
#
|
14
|
+
# Usage example for the pipeshell:
|
15
|
+
#
|
16
|
+
# 20 years | n_days?
|
17
|
+
#
|
18
|
+
# ========================================================================= #
|
19
|
+
def self.cmdlet_years(i = result?)
|
20
|
+
# ======================================================================= #
|
21
|
+
# Calculate how many seconds there are.
|
22
|
+
# ======================================================================= #
|
23
|
+
n_days = (i.to_f * 365.25).floor # The 0.25 is included because of the leap years.
|
24
|
+
i = ONE_DAY_HAS_N_SECONDS * n_days
|
25
|
+
set_result(i)
|
26
|
+
return result?
|
27
|
+
end; self.instance_eval { alias action_years cmdlet_years } # === UniversalPipeHandler.action_years
|
28
|
+
self.instance_eval { alias action_days? cmdlet_years } # === UniversalPipeHandler.action_days?
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === UniversalPipeHandler::CmdletsHandler
|
6
|
+
#
|
7
|
+
# This class will handle individual cmdlets, that are part of a given
|
8
|
+
# pipe-instruction.
|
9
|
+
#
|
10
|
+
# It must be able to determine whether a pipe follows or whether it
|
11
|
+
# does not.
|
12
|
+
#
|
13
|
+
# Usage example:
|
14
|
+
#
|
15
|
+
# UniversalPipeHandlerCmdletsHandler.new(ARGV)
|
16
|
+
#
|
17
|
+
# =========================================================================== #
|
18
|
+
# require 'universal_pipe_handler/cmdlets_handler/cmdlets_handler.rb'
|
19
|
+
# UniversalPipeHandlerCmdletsHandler.new(ARGV)
|
20
|
+
# =========================================================================== #
|
21
|
+
require 'universal_pipe_handler/base/base.rb'
|
22
|
+
|
23
|
+
module UniversalPipeHandler
|
24
|
+
|
25
|
+
class CmdletsHandler < Base # === UniversalPipeHandler::CmdletsHandler
|
26
|
+
|
27
|
+
require 'universal_pipe_handler/cmdlet/cmdlet.rb'
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'convert_global_env'
|
31
|
+
rescue LoadError; end
|
32
|
+
|
33
|
+
# ========================================================================= #
|
34
|
+
# === NAMESPACE
|
35
|
+
# ========================================================================= #
|
36
|
+
NAMESPACE = inspect
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === initialize
|
40
|
+
# ========================================================================= #
|
41
|
+
def initialize(
|
42
|
+
commandline_arguments = nil,
|
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 (reset tag)
|
54
|
+
# ========================================================================= #
|
55
|
+
def reset
|
56
|
+
super()
|
57
|
+
# ======================================================================= #
|
58
|
+
# === @namespace
|
59
|
+
# ======================================================================= #
|
60
|
+
@namespace = NAMESPACE
|
61
|
+
# ======================================================================= #
|
62
|
+
# === @start_dir
|
63
|
+
# ======================================================================= #
|
64
|
+
@start_dir = return_pwd
|
65
|
+
end
|
66
|
+
|
67
|
+
# ========================================================================= #
|
68
|
+
# === assign_pipe
|
69
|
+
# ========================================================================= #
|
70
|
+
def assign_pipe(i)
|
71
|
+
if i.is_a? Array
|
72
|
+
i = i.join(' ')
|
73
|
+
end
|
74
|
+
i.strip!
|
75
|
+
# ======================================================================= #
|
76
|
+
# We do not need ' ' occurrences.
|
77
|
+
# ======================================================================= #
|
78
|
+
i.squeeze!(' ') if i.include? ' '
|
79
|
+
# ======================================================================= #
|
80
|
+
# Always assume that '$' refers to an ENV variable. They will be
|
81
|
+
# converted via the class ConvertGlobalEnv.
|
82
|
+
# ======================================================================= #
|
83
|
+
i = ConvertGlobalEnv.convert(i) if i.include? '$'
|
84
|
+
@pipe = i
|
85
|
+
end; alias set_pipe assign_pipe # === set_pipe
|
86
|
+
|
87
|
+
# ========================================================================= #
|
88
|
+
# === split_into_individual_cmdlets
|
89
|
+
#
|
90
|
+
# This method will assign towards @splitted (an Array).
|
91
|
+
# ========================================================================= #
|
92
|
+
def split_into_individual_cmdlets
|
93
|
+
if @pipe.include? PIPE_TOKEN
|
94
|
+
@splitted = @pipe.split(PIPE_TOKEN)
|
95
|
+
else
|
96
|
+
@splitted = [@pipe]
|
97
|
+
end
|
98
|
+
@splitted.flatten!
|
99
|
+
@splitted.compact!
|
100
|
+
end; alias split_on_pipe_token split_into_individual_cmdlets # === split_on_pipe_token
|
101
|
+
alias split_pipe split_into_individual_cmdlets # === split_pipe
|
102
|
+
|
103
|
+
# ========================================================================= #
|
104
|
+
# === map_the_splitted_components_onto_individual_cmdlets
|
105
|
+
# ========================================================================= #
|
106
|
+
def map_the_splitted_components_onto_individual_cmdlets
|
107
|
+
@splitted.map! {|line|
|
108
|
+
Cmdlet.new(line, :do_not_run_yet)
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
# ========================================================================= #
|
113
|
+
# === do_evaluate_the_pipe
|
114
|
+
# ========================================================================= #
|
115
|
+
def do_evaluate_the_pipe
|
116
|
+
@splitted.each {|cmdlet|
|
117
|
+
cmdlet.strip!
|
118
|
+
e
|
119
|
+
ewarn 'DEBUGGING GOING ON, REMOVE ME AT A LATER TIME: processing pipe '+sfile(cmdlet)+' next.'
|
120
|
+
e
|
121
|
+
cmdlet.set_start_dir(@start_dir)
|
122
|
+
cmdlet.do_evaluate
|
123
|
+
ewarn 'DEBUGGING GOING ON, REMOVE ME AT A LATER TIME: the result is now:'
|
124
|
+
pp result?
|
125
|
+
pp result?.class
|
126
|
+
e
|
127
|
+
}
|
128
|
+
end; alias process_pipe do_evaluate_the_pipe # === process_pipe
|
129
|
+
|
130
|
+
# ========================================================================= #
|
131
|
+
# === result?
|
132
|
+
# ========================================================================= #
|
133
|
+
def result?
|
134
|
+
UniversalPipeHandler.result?
|
135
|
+
end
|
136
|
+
|
137
|
+
# ========================================================================= #
|
138
|
+
# === ensure_that_the_log_directory_exists
|
139
|
+
# ========================================================================= #
|
140
|
+
def ensure_that_the_log_directory_exists
|
141
|
+
_ = '/home/Temp/universal_pipe_handler/'
|
142
|
+
mkdir(_) unless File.directory? _
|
143
|
+
cd(_)
|
144
|
+
pp Dir.pwd
|
145
|
+
end
|
146
|
+
|
147
|
+
# ========================================================================= #
|
148
|
+
# === run (run tag)
|
149
|
+
# ========================================================================= #
|
150
|
+
def run
|
151
|
+
_ = commandline_arguments?.join(' ').strip
|
152
|
+
ensure_that_the_log_directory_exists
|
153
|
+
assign_pipe(_)
|
154
|
+
split_into_individual_cmdlets
|
155
|
+
map_the_splitted_components_onto_individual_cmdlets
|
156
|
+
do_evaluate_the_pipe
|
157
|
+
end
|
158
|
+
|
159
|
+
# ========================================================================= #
|
160
|
+
# === UniversalPipeHandler::CmdletsHandler[]
|
161
|
+
# ========================================================================= #
|
162
|
+
def self.[](i = '')
|
163
|
+
new(i)
|
164
|
+
end
|
165
|
+
|
166
|
+
end; end
|
167
|
+
|
168
|
+
if __FILE__ == $PROGRAM_NAME
|
169
|
+
require 'colours/autoinclude' # Test the project next.
|
170
|
+
e 'Testing various aspects next allowed_actions.rb'
|
171
|
+
e
|
172
|
+
e 'The allowed actions/cmdlets are:'
|
173
|
+
e
|
174
|
+
p UniversalPipeHandler.allowed_actions?
|
175
|
+
e
|
176
|
+
pipe_handler = UniversalPipeHandler::CmdletsHandler.new(ARGV)
|
177
|
+
e
|
178
|
+
e 'Testing the pipe_aliases next (but we will show only 5 entries):'
|
179
|
+
pp pipe_handler.pipe_aliases?.values_at(*PipeHandler.pipe_aliases?.keys.sample(5))
|
180
|
+
e
|
181
|
+
p pipe_handler.pipe_aliases?
|
182
|
+
e
|
183
|
+
e 'Testing the allowed_actions:'
|
184
|
+
e
|
185
|
+
p pipe_handler.allowed_actions?
|
186
|
+
e
|
187
|
+
e 'Testing the predefined_methods next:'
|
188
|
+
p pipe_handler.predefined_methods?
|
189
|
+
p pipe_handler.predefined_methods?.has_key? 'enlarge'
|
190
|
+
e
|
191
|
+
p pipe_handler.pipe_aliases?
|
192
|
+
pipe_handler = UniversalPipeHandler::CmdletsHandler.new('ls | nl')
|
193
|
+
end # cmdlets_handler
|