rcfiles 1.1.1137
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rcfiles might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +401 -0
- data/bin/rcfiles +7 -0
- data/bin/rcfiles_run_it +7 -0
- data/doc/README.gen +384 -0
- data/lib/rcfiles.rb +1 -0
- data/lib/rcfiles/class/colours.rb +54 -0
- data/lib/rcfiles/class/initialize.rb +66 -0
- data/lib/rcfiles/class/misc.rb +299 -0
- data/lib/rcfiles/class/rcfiles.rb +31 -0
- data/lib/rcfiles/class/reset.rb +26 -0
- data/lib/rcfiles/class/run.rb +17 -0
- data/lib/rcfiles/colours/colours.rb +107 -0
- data/lib/rcfiles/commandline/commandline.rb +170 -0
- data/lib/rcfiles/constants/custom_files.rb +80 -0
- data/lib/rcfiles/constants/encodings.rb +85 -0
- data/lib/rcfiles/constants/misc.rb +75 -0
- data/lib/rcfiles/constants/namespace.rb +18 -0
- data/lib/rcfiles/expand_cd_aliases/constants.rb +50 -0
- data/lib/rcfiles/expand_cd_aliases/expand_cd_aliases.rb +626 -0
- data/lib/rcfiles/expand_cd_aliases/run.rb +18 -0
- data/lib/rcfiles/files/file_aliases.rb +78 -0
- data/lib/rcfiles/files/file_cd_aliases.rb +85 -0
- data/lib/rcfiles/files/file_ls_colours.rb +76 -0
- data/lib/rcfiles/files/file_path_variable.rb +74 -0
- data/lib/rcfiles/files/file_pkgconfig.rb +74 -0
- data/lib/rcfiles/files/file_programs_aliases.rb +68 -0
- data/lib/rcfiles/files/file_ps1.rb +80 -0
- data/lib/rcfiles/files/file_system_settings.rb +66 -0
- data/lib/rcfiles/help/help.rb +46 -0
- data/lib/rcfiles/no_colours.rb +13 -0
- data/lib/rcfiles/project/project.rb +45 -0
- data/lib/rcfiles/rcfiles/README.md +5 -0
- data/lib/rcfiles/rcfiles/aliases_rc +18526 -0
- data/lib/rcfiles/rcfiles/cd_aliases_rc +13313 -0
- data/lib/rcfiles/rcfiles/cflags_rc +9 -0
- data/lib/rcfiles/rcfiles/compile_rc +11 -0
- data/lib/rcfiles/rcfiles/file_information_rc +16 -0
- data/lib/rcfiles/rcfiles/german_umlaute_rc +264 -0
- data/lib/rcfiles/rcfiles/gnome_rc +10 -0
- data/lib/rcfiles/rcfiles/kde_rc +17 -0
- data/lib/rcfiles/rcfiles/kernel_rc +12 -0
- data/lib/rcfiles/rcfiles/lang_rc +9 -0
- data/lib/rcfiles/rcfiles/ldflags_rc +8 -0
- data/lib/rcfiles/rcfiles/ls_colours_rc +9 -0
- data/lib/rcfiles/rcfiles/network_rc +37 -0
- data/lib/rcfiles/rcfiles/path_variable_rc +9 -0
- data/lib/rcfiles/rcfiles/pkgconfig_rc +9 -0
- data/lib/rcfiles/rcfiles/programs_aliases_rc +15597 -0
- data/lib/rcfiles/rcfiles/ps1_rc +9 -0
- data/lib/rcfiles/rcfiles/special_aliases_rc +23 -0
- data/lib/rcfiles/rcfiles/system_rc +13 -0
- data/lib/rcfiles/rcfiles/system_settings_rc +191 -0
- data/lib/rcfiles/rcfiles/term_rc +9 -0
- data/lib/rcfiles/rcfiles/video_rc +24 -0
- data/lib/rcfiles/requires/require_the_expand_cd_aliases.rb +7 -0
- data/lib/rcfiles/requires/require_the_rcfiles_constants.rb +21 -0
- data/lib/rcfiles/requires/require_the_rcfiles_project.rb +66 -0
- data/lib/rcfiles/requires/try_to_require_syck_and_psych.rb +18 -0
- data/lib/rcfiles/toplevel_methods/autogenerate_rc_file_from_this_yaml_file.rb +102 -0
- data/lib/rcfiles/toplevel_methods/change_directory.rb +16 -0
- data/lib/rcfiles/toplevel_methods/convert.rb +118 -0
- data/lib/rcfiles/toplevel_methods/create_windows_cd_aliases_bat_file.rb +51 -0
- data/lib/rcfiles/toplevel_methods/e.rb +16 -0
- data/lib/rcfiles/toplevel_methods/esystem.rb +19 -0
- data/lib/rcfiles/toplevel_methods/generate_yaml_files.rb +148 -0
- data/lib/rcfiles/toplevel_methods/infer.rb +83 -0
- data/lib/rcfiles/toplevel_methods/is_on_roebe.rb +16 -0
- data/lib/rcfiles/toplevel_methods/main_directory.rb +108 -0
- data/lib/rcfiles/toplevel_methods/misc.rb +304 -0
- data/lib/rcfiles/toplevel_methods/n_registered_aliases_in_total.rb +55 -0
- data/lib/rcfiles/toplevel_methods/no_file_exists_at.rb +19 -0
- data/lib/rcfiles/toplevel_methods/notifications.rb +33 -0
- data/lib/rcfiles/toplevel_methods/rds.rb +16 -0
- data/lib/rcfiles/toplevel_methods/remove_newlines.rb +29 -0
- data/lib/rcfiles/toplevel_methods/report.rb +53 -0
- data/lib/rcfiles/toplevel_methods/return_standard_header.rb +36 -0
- data/lib/rcfiles/toplevel_methods/run_it.rb +46 -0
- data/lib/rcfiles/toplevel_methods/save_file.rb +27 -0
- data/lib/rcfiles/toplevel_methods/use_psych_or_syck.rb +50 -0
- data/lib/rcfiles/toplevel_methods/use_quotes.rb +68 -0
- data/lib/rcfiles/toplevel_methods/verbosity.rb +28 -0
- data/lib/rcfiles/version/version.rb +26 -0
- data/lib/rcfiles/yaml/aliases.yml +20991 -0
- data/lib/rcfiles/yaml/cd_aliases.yml +13970 -0
- data/lib/rcfiles/yaml/ls_colours.yml +128 -0
- data/lib/rcfiles/yaml/path_variable.yml +12 -0
- data/lib/rcfiles/yaml/pkgconfig.yml +46 -0
- data/lib/rcfiles/yaml/programs_aliases.yml +17081 -0
- data/lib/rcfiles/yaml/ps1.yml +82 -0
- data/lib/rcfiles/yaml/store_into_this_directory.yml +1 -0
- data/lib/rcfiles/yaml/system_settings.yml +513 -0
- data/lib/rcfiles/yaml/use_psych_or_syck.yml +1 -0
- data/rcfiles.gemspec +56 -0
- data/test/testing_expand_cd_aliases.rb +47 -0
- data/test/testing_yaml_to_rcfiles.rb +9 -0
- metadata +201 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'rcfiles/toplevel_methods/change_directory.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module Rcfiles
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === Rcfiles.change_directory
|
11
|
+
# ========================================================================= #
|
12
|
+
def self.change_directory(i)
|
13
|
+
Dir.chdir(i) if File.directory? i
|
14
|
+
end; self.instance_eval { alias cd change_directory } # === Rcfiles.cd
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# This file contains code that can convert a .yml file into a bash
|
6
|
+
# rcfile, either using "alias" or "export" statements.
|
7
|
+
# =========================================================================== #
|
8
|
+
# require 'rcfiles/toplevel_methods/convert.rb'
|
9
|
+
# Rcfiles.convert_this_hash_to_export_file
|
10
|
+
# =========================================================================== #
|
11
|
+
require 'rcfiles/toplevel_methods/remove_newlines.rb'
|
12
|
+
require 'rcfiles/toplevel_methods/use_quotes.rb'
|
13
|
+
require 'rcfiles/constants/encodings.rb'
|
14
|
+
|
15
|
+
module Rcfiles
|
16
|
+
|
17
|
+
# ========================================================================= #
|
18
|
+
# === Rcfiles.convert_this_hash_to_alias_file
|
19
|
+
#
|
20
|
+
# This method expects a Hash as input.
|
21
|
+
# ========================================================================= #
|
22
|
+
def self.convert_this_hash_to_alias_file(
|
23
|
+
hash
|
24
|
+
)
|
25
|
+
_ = ''.dup # <- Our return String.
|
26
|
+
hash.each_pair {|key, value|
|
27
|
+
value = remove_newlines(value.to_s.strip)
|
28
|
+
if @use_quotes
|
29
|
+
_ << "alias '#{key}'=\"#{value}\"#{N}"
|
30
|
+
else
|
31
|
+
_ << "alias #{key}=#{value}#{N}"
|
32
|
+
end
|
33
|
+
} if hash
|
34
|
+
return _
|
35
|
+
end; self.instance_eval { alias convert_hash_to_alias_file convert_this_hash_to_alias_file } # === Rcfiles.convert_hash_to_alias_file
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === Rcfiles.convert_this_array_to_export_file
|
39
|
+
#
|
40
|
+
# This method expects an Array as input.
|
41
|
+
#
|
42
|
+
# Arrays are handled a bit differently, though - they will be aggregated
|
43
|
+
# into one input value for "export".
|
44
|
+
# ========================================================================= #
|
45
|
+
def self.convert_this_array_to_export_file(
|
46
|
+
array,
|
47
|
+
optional_second_input_as_name_of_the_export_variable = 'PKG_CONFIG_PATH'
|
48
|
+
)
|
49
|
+
if array and array.is_a?(Array)
|
50
|
+
_ = ''.dup # <- Our return String.
|
51
|
+
joined = array.join(':').strip
|
52
|
+
_ << "export #{optional_second_input_as_name_of_the_export_variable}=\"#{joined}\"#{N}"
|
53
|
+
return _
|
54
|
+
else
|
55
|
+
array
|
56
|
+
end
|
57
|
+
end; self.instance_eval { alias convert_array_to_export_file convert_this_array_to_export_file } # === Rcfiles.convert_array_to_export_file
|
58
|
+
|
59
|
+
# ========================================================================= #
|
60
|
+
# === Rcfiles.convert_this_input_to_export_file
|
61
|
+
# ========================================================================= #
|
62
|
+
def self.convert_this_input_to_export_file(
|
63
|
+
i, optional_second_input_as_name_of_the_export_variable = nil
|
64
|
+
)
|
65
|
+
case i
|
66
|
+
when Hash
|
67
|
+
# ===================================================================== #
|
68
|
+
# Hashes will ignore the optional second argument to this method, even
|
69
|
+
# if it has been provided. The reason is primarily because we expect
|
70
|
+
# a key -> value entry of a Hash already, so the kew is known; whereas
|
71
|
+
# for an Array, we actually need the user to supply the name of the
|
72
|
+
# key at hand.
|
73
|
+
# ===================================================================== #
|
74
|
+
convert_this_hash_to_export_file(i)
|
75
|
+
when Array
|
76
|
+
convert_this_array_to_export_file(i, optional_second_input_as_name_of_the_export_variable)
|
77
|
+
when String
|
78
|
+
convert_this_array_to_export_file([i], optional_second_input_as_name_of_the_export_variable)
|
79
|
+
else
|
80
|
+
e "Unregistered input-class (#{i.class})"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# ========================================================================= #
|
85
|
+
# === Rcfiles.convert_this_hash_to_export_file
|
86
|
+
#
|
87
|
+
# This method expects a Hash as input. If you need a bit more flexibility
|
88
|
+
# then you are encouraged to use the other method, called
|
89
|
+
# Rcfiles.convert_this_input_to_export_file() instead.
|
90
|
+
# ========================================================================= #
|
91
|
+
def self.convert_this_hash_to_export_file(
|
92
|
+
hash,
|
93
|
+
ensure_proper_encoding = false
|
94
|
+
)
|
95
|
+
case ensure_proper_encoding
|
96
|
+
when :ensure_proper_encoding
|
97
|
+
ensure_proper_encoding = true
|
98
|
+
end
|
99
|
+
_ = ''.dup # <- Our return String.
|
100
|
+
hash.each_pair {|key, value|
|
101
|
+
value = value.to_s.strip
|
102
|
+
if ensure_proper_encoding
|
103
|
+
value = ensure_proper_encoding_for(value)
|
104
|
+
key = ensure_proper_encoding_for(value)
|
105
|
+
end
|
106
|
+
value = value.tr("\n", ' ').squeeze(' ')
|
107
|
+
_ << "export #{key}=\"#{value}\"#{N}"
|
108
|
+
} if hash
|
109
|
+
return _
|
110
|
+
end; self.instance_eval { alias convert_hash_to_export_file convert_this_hash_to_export_file } # === Rcfiles.convert_hash_to_export_file
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
if __FILE__ == $PROGRAM_NAME
|
115
|
+
Rcfiles.convert_this_hash_to_export_file(
|
116
|
+
{ cat: :tom, mouse: :jerry }
|
117
|
+
)
|
118
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'rcfiles/toplevel_methods/create_windows_cd_aliases_bat_file.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module Rcfiles
|
8
|
+
|
9
|
+
require 'rcfiles/files/file_cd_aliases.rb'
|
10
|
+
require 'rcfiles/toplevel_methods/e.rb'
|
11
|
+
require 'rcfiles/toplevel_methods/save_file.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === Rcfiles.create_windows_cd_aliases_bat_file
|
15
|
+
# ========================================================================= #
|
16
|
+
def self.create_windows_cd_aliases_bat_file
|
17
|
+
_ = ::Rcfiles.file_cd_aliases?
|
18
|
+
if File.exist? _
|
19
|
+
require 'yaml'
|
20
|
+
dataset = YAML.load_file(_)
|
21
|
+
_ = ''.dup
|
22
|
+
begin
|
23
|
+
require 'convert_global_env'
|
24
|
+
rescue LoadError; end
|
25
|
+
dataset.each_pair {|key, value|
|
26
|
+
# =================================================================== #
|
27
|
+
# value may contain a $, such as in $MAIN_WORK.
|
28
|
+
# If this is the case then we will as ConvertGlobalEnv[]
|
29
|
+
# to translate this for us.
|
30
|
+
# =================================================================== #
|
31
|
+
if value.include? '$'
|
32
|
+
value = ConvertGlobalEnv[value]
|
33
|
+
end
|
34
|
+
_ << 'function '+key.to_s+' { set-location "'+value.to_s+'" }'+N
|
35
|
+
}
|
36
|
+
# ===================================================================== #
|
37
|
+
# Now we can simply store this String into a file.
|
38
|
+
# ===================================================================== #
|
39
|
+
into = 'cd_aliases.bat'
|
40
|
+
e 'Storing into the file '+into+' next.'
|
41
|
+
write_what_into(_, into)
|
42
|
+
else
|
43
|
+
e 'No file exists at '+_+'.'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
if __FILE__ == $PROGRAM_NAME
|
50
|
+
Rcfiles.create_windows_cd_aliases_bat_file
|
51
|
+
end # rb create_windows_cd_aliases_bat_file.rb
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'rcfiles/toplevel_methods/e.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module Rcfiles
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === Rcfiles.e
|
11
|
+
# ========================================================================= #
|
12
|
+
def self.e(i = '')
|
13
|
+
puts i
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'rcfiles/toplevel_methods/esystem.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'rcfiles/toplevel_methods/e.rb'
|
8
|
+
|
9
|
+
module Rcfiles
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === Rcfiles.esystem
|
13
|
+
# ========================================================================= #
|
14
|
+
def self.esystem(i)
|
15
|
+
e i
|
16
|
+
system i
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Rcfiles.generate_yaml_files
|
6
|
+
#
|
7
|
+
# This file will generate .yml files that will conform to UTF8 by default.
|
8
|
+
#
|
9
|
+
# Usage example:
|
10
|
+
#
|
11
|
+
# Rcfiles.generate_yaml_files
|
12
|
+
#
|
13
|
+
# =========================================================================== #
|
14
|
+
# require 'rcfiles/toplevel_methods/generate_yaml_files.rb'
|
15
|
+
# =========================================================================== #
|
16
|
+
module Rcfiles
|
17
|
+
|
18
|
+
require 'fileutils'
|
19
|
+
require 'rcfiles/files/file_cd_aliases.rb'
|
20
|
+
require 'rcfiles/files/file_aliases.rb'
|
21
|
+
require 'rcfiles/files/file_programs_aliases.rb'
|
22
|
+
require 'rcfiles/constants/encodings.rb'
|
23
|
+
require 'rcfiles/toplevel_methods/e.rb'
|
24
|
+
require 'rcfiles/toplevel_methods/esystem.rb'
|
25
|
+
require 'rcfiles/toplevel_methods/save_file.rb'
|
26
|
+
|
27
|
+
# ========================================================================= #
|
28
|
+
# === Rcfiles.generate_yaml_files
|
29
|
+
#
|
30
|
+
# The main idea behind this method is to be able to work with UTF8
|
31
|
+
# encoded files.
|
32
|
+
# ========================================================================= #
|
33
|
+
def self.generate_yaml_files(
|
34
|
+
use_this_encoding = :utf8
|
35
|
+
)
|
36
|
+
require 'yaml'
|
37
|
+
# ======================================================================= #
|
38
|
+
# === Handle the file 'cd_aliases.yml' next
|
39
|
+
# ======================================================================= #
|
40
|
+
_ = file_cd_aliases?
|
41
|
+
if File.exist? _
|
42
|
+
string = ''.dup
|
43
|
+
begin
|
44
|
+
dataset_hash = YAML.load_file(_)
|
45
|
+
dataset_hash.each_pair {|key, value|
|
46
|
+
key = ensure_main_encoding(key.to_s, use_this_encoding)
|
47
|
+
value = ensure_main_encoding(value.to_s, use_this_encoding)
|
48
|
+
unless key.start_with? '"'
|
49
|
+
key = "\"#{key}\""
|
50
|
+
end
|
51
|
+
unless value.start_with? '"'
|
52
|
+
value = "\"#{value}\""
|
53
|
+
end
|
54
|
+
key = ensure_main_encoding(key.to_s, use_this_encoding)
|
55
|
+
value = ensure_main_encoding(value.to_s, use_this_encoding)
|
56
|
+
string << "#{key}: #{value}\n"
|
57
|
+
}
|
58
|
+
what = string
|
59
|
+
target_file = '/Depot/'+File.basename(_)
|
60
|
+
new_target_file = '/Depot/'+File.basename(_).sub(/\.#{File.extname(_)}$/,'')+'2.yml'
|
61
|
+
e 'Will store into the file `'+target_file+'`.'
|
62
|
+
write_what_into(what, target_file)
|
63
|
+
system 'iconv -f ISO-8859-1 -t UTF-8 '+target_file+' >> '+new_target_file
|
64
|
+
File.delete(target_file)
|
65
|
+
FileUtils.mv(new_target_file, target_file)
|
66
|
+
rescue ArgumentError => error
|
67
|
+
pp error
|
68
|
+
end
|
69
|
+
else
|
70
|
+
e 'No file could be found at `'+_+'`.'
|
71
|
+
end
|
72
|
+
# ======================================================================= #
|
73
|
+
# === Handle the file 'aliases.yml' next
|
74
|
+
# ======================================================================= #
|
75
|
+
_ = file_aliases?
|
76
|
+
if File.exist? _
|
77
|
+
string = ''.dup
|
78
|
+
begin
|
79
|
+
dataset_hash = YAML.load_file(_)
|
80
|
+
dataset_hash.each_pair {|key, value|
|
81
|
+
key = ensure_main_encoding(key.to_s, use_this_encoding)
|
82
|
+
value = ensure_main_encoding(value.to_s, use_this_encoding)
|
83
|
+
unless key.start_with? '"'
|
84
|
+
key = "\"#{key}\""
|
85
|
+
end
|
86
|
+
unless value.start_with? '"'
|
87
|
+
value = "\"#{value}\""
|
88
|
+
end
|
89
|
+
key = ensure_main_encoding(key.to_s, use_this_encoding)
|
90
|
+
value = ensure_main_encoding(value.to_s, use_this_encoding)
|
91
|
+
string << "#{key}: #{value}\n"
|
92
|
+
}
|
93
|
+
what = string
|
94
|
+
target_file = "/Depot/#{File.basename(_)}"
|
95
|
+
new_target_file = '/Depot/'+File.basename(_).sub(/\.#{File.extname(_)}$/,'')+'2.yml'
|
96
|
+
e 'Will store into the file `'+target_file+'`.'
|
97
|
+
write_what_into(what, target_file)
|
98
|
+
system 'iconv -f ISO-8859-1 -t UTF-8 '+target_file+' >> '+new_target_file
|
99
|
+
File.delete(target_file)
|
100
|
+
FileUtils.mv(new_target_file, target_file)
|
101
|
+
rescue ArgumentError => error
|
102
|
+
pp error
|
103
|
+
end
|
104
|
+
else
|
105
|
+
e 'No file could be found at `'+_+'`.'
|
106
|
+
end
|
107
|
+
# ======================================================================= #
|
108
|
+
# === Handle the file 'programs_aliases.yml' next
|
109
|
+
# ======================================================================= #
|
110
|
+
_ = file_programs_aliases?
|
111
|
+
if File.exist? _
|
112
|
+
string = ''.dup
|
113
|
+
begin
|
114
|
+
dataset_hash = YAML.load_file(_)
|
115
|
+
dataset_hash.each_pair {|key, value|
|
116
|
+
key = ensure_main_encoding(key.to_s, use_this_encoding)
|
117
|
+
value = ensure_main_encoding(value.to_s, use_this_encoding)
|
118
|
+
unless key.start_with? '"'
|
119
|
+
key = "\"#{key}\""
|
120
|
+
end
|
121
|
+
unless value.start_with? '"'
|
122
|
+
value = "\"#{value}\""
|
123
|
+
end
|
124
|
+
key = ensure_main_encoding(key.to_s, use_this_encoding)
|
125
|
+
value = ensure_main_encoding(value.to_s, use_this_encoding)
|
126
|
+
string << "#{key}: #{value}\n"
|
127
|
+
}
|
128
|
+
what = string
|
129
|
+
target_file = '/Depot/'+File.basename(_)
|
130
|
+
new_target_file = '/Depot/'+File.basename(_).sub(/\.#{File.extname(_)}$/,'')+'2.yml'
|
131
|
+
e 'Will store into the file `'+target_file+'`.'
|
132
|
+
write_what_into(what, target_file)
|
133
|
+
system 'iconv -f ISO-8859-1 -t UTF-8 '+target_file+' >> '+new_target_file
|
134
|
+
File.delete(target_file)
|
135
|
+
FileUtils.mv(new_target_file, target_file)
|
136
|
+
rescue ArgumentError => error
|
137
|
+
pp error
|
138
|
+
end
|
139
|
+
else
|
140
|
+
e "No file could be found at `#{_}`."
|
141
|
+
end
|
142
|
+
end; self.instance_eval { alias syck_generate generate_yaml_files } # === Rcfiles.syck_generate
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
if __FILE__ == $PROGRAM_NAME
|
147
|
+
Rcfiles.generate_yaml_files
|
148
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'rcfiles/toplevel_methods/infer.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'rcfiles/toplevel_methods/e.rb'
|
8
|
+
require 'rcfiles/toplevel_methods/main_directory.rb'
|
9
|
+
require 'rcfiles/files/file_aliases.rb'
|
10
|
+
require 'rcfiles/files/file_cd_aliases.rb'
|
11
|
+
require 'rcfiles/files/file_programs_aliases.rb'
|
12
|
+
|
13
|
+
module Rcfiles
|
14
|
+
|
15
|
+
# ========================================================================= #
|
16
|
+
# === Rcfiles.infer
|
17
|
+
#
|
18
|
+
# This method can be used to automatically infer, based on the input,
|
19
|
+
# what we may wish to do - in particular setting the path to one
|
20
|
+
# of the three major alias-groups of the Rcfiles project.
|
21
|
+
#
|
22
|
+
# For example, take the following API:
|
23
|
+
#
|
24
|
+
# Rcfiles.infer 'programs_aliases.yml'
|
25
|
+
#
|
26
|
+
# which will be translated into the following, longer variant:
|
27
|
+
#
|
28
|
+
# Rcfiles.set_programs_aliases(File.absolute_path('programs_aliases.yml'))
|
29
|
+
#
|
30
|
+
# As you can see, the first variant is significantly shorter to use. The
|
31
|
+
# trailing '.yml' part can be omitted as well, so the following is
|
32
|
+
# also possible:
|
33
|
+
#
|
34
|
+
# Rcfiles.infer 'programs_aliases.yml'
|
35
|
+
#
|
36
|
+
# Generic usage examples:
|
37
|
+
#
|
38
|
+
# Rcfiles.infer 'aliases.yml' # => "/Depot/j/aliases.yml"
|
39
|
+
# Rcfiles.infer 'cd_aliases.yml' # => "/Depot/j/cd_aliases.yml"
|
40
|
+
# Rcfiles.infer 'programs_aliases.yml' # => "/Depot/j/programs_aliases.yml"
|
41
|
+
# Rcfiles.infer 'system_settings.yml' # => "/Depot/j/system_settings.yml"
|
42
|
+
#
|
43
|
+
# ========================================================================= #
|
44
|
+
def self.infer(
|
45
|
+
i = 'programs_aliases'
|
46
|
+
)
|
47
|
+
if i.is_a? String
|
48
|
+
i = i.dup if i.frozen?
|
49
|
+
i << '.yml' unless i.end_with? '.yml' # Append the '.yml' substring in this case.
|
50
|
+
end
|
51
|
+
case i
|
52
|
+
# ======================================================================= #
|
53
|
+
# === system_settings.yml
|
54
|
+
# ======================================================================= #
|
55
|
+
when /system_?settings\.yml$/
|
56
|
+
set_file_aliases(
|
57
|
+
File.absolute_path(i)
|
58
|
+
)
|
59
|
+
# ======================================================================= #
|
60
|
+
# === aliases.yml
|
61
|
+
# ======================================================================= #
|
62
|
+
when /aliases\.yml$/
|
63
|
+
set_file_aliases(
|
64
|
+
File.absolute_path(i)
|
65
|
+
)
|
66
|
+
# ======================================================================= #
|
67
|
+
# === cd_aliases.yml
|
68
|
+
# ======================================================================= #
|
69
|
+
when /cd_?aliases\.yml$/
|
70
|
+
set_cd_aliases(
|
71
|
+
File.absolute_path(i)
|
72
|
+
)
|
73
|
+
# ======================================================================= #
|
74
|
+
# === programs_aliases.yml
|
75
|
+
# ======================================================================= #
|
76
|
+
when /programs_?aliases\.yml$/
|
77
|
+
set_programs_aliases(
|
78
|
+
File.absolute_path(i)
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|