rcfiles 1.1.1137

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.

Potentially problematic release.


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

Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +401 -0
  3. data/bin/rcfiles +7 -0
  4. data/bin/rcfiles_run_it +7 -0
  5. data/doc/README.gen +384 -0
  6. data/lib/rcfiles.rb +1 -0
  7. data/lib/rcfiles/class/colours.rb +54 -0
  8. data/lib/rcfiles/class/initialize.rb +66 -0
  9. data/lib/rcfiles/class/misc.rb +299 -0
  10. data/lib/rcfiles/class/rcfiles.rb +31 -0
  11. data/lib/rcfiles/class/reset.rb +26 -0
  12. data/lib/rcfiles/class/run.rb +17 -0
  13. data/lib/rcfiles/colours/colours.rb +107 -0
  14. data/lib/rcfiles/commandline/commandline.rb +170 -0
  15. data/lib/rcfiles/constants/custom_files.rb +80 -0
  16. data/lib/rcfiles/constants/encodings.rb +85 -0
  17. data/lib/rcfiles/constants/misc.rb +75 -0
  18. data/lib/rcfiles/constants/namespace.rb +18 -0
  19. data/lib/rcfiles/expand_cd_aliases/constants.rb +50 -0
  20. data/lib/rcfiles/expand_cd_aliases/expand_cd_aliases.rb +626 -0
  21. data/lib/rcfiles/expand_cd_aliases/run.rb +18 -0
  22. data/lib/rcfiles/files/file_aliases.rb +78 -0
  23. data/lib/rcfiles/files/file_cd_aliases.rb +85 -0
  24. data/lib/rcfiles/files/file_ls_colours.rb +76 -0
  25. data/lib/rcfiles/files/file_path_variable.rb +74 -0
  26. data/lib/rcfiles/files/file_pkgconfig.rb +74 -0
  27. data/lib/rcfiles/files/file_programs_aliases.rb +68 -0
  28. data/lib/rcfiles/files/file_ps1.rb +80 -0
  29. data/lib/rcfiles/files/file_system_settings.rb +66 -0
  30. data/lib/rcfiles/help/help.rb +46 -0
  31. data/lib/rcfiles/no_colours.rb +13 -0
  32. data/lib/rcfiles/project/project.rb +45 -0
  33. data/lib/rcfiles/rcfiles/README.md +5 -0
  34. data/lib/rcfiles/rcfiles/aliases_rc +18526 -0
  35. data/lib/rcfiles/rcfiles/cd_aliases_rc +13313 -0
  36. data/lib/rcfiles/rcfiles/cflags_rc +9 -0
  37. data/lib/rcfiles/rcfiles/compile_rc +11 -0
  38. data/lib/rcfiles/rcfiles/file_information_rc +16 -0
  39. data/lib/rcfiles/rcfiles/german_umlaute_rc +264 -0
  40. data/lib/rcfiles/rcfiles/gnome_rc +10 -0
  41. data/lib/rcfiles/rcfiles/kde_rc +17 -0
  42. data/lib/rcfiles/rcfiles/kernel_rc +12 -0
  43. data/lib/rcfiles/rcfiles/lang_rc +9 -0
  44. data/lib/rcfiles/rcfiles/ldflags_rc +8 -0
  45. data/lib/rcfiles/rcfiles/ls_colours_rc +9 -0
  46. data/lib/rcfiles/rcfiles/network_rc +37 -0
  47. data/lib/rcfiles/rcfiles/path_variable_rc +9 -0
  48. data/lib/rcfiles/rcfiles/pkgconfig_rc +9 -0
  49. data/lib/rcfiles/rcfiles/programs_aliases_rc +15597 -0
  50. data/lib/rcfiles/rcfiles/ps1_rc +9 -0
  51. data/lib/rcfiles/rcfiles/special_aliases_rc +23 -0
  52. data/lib/rcfiles/rcfiles/system_rc +13 -0
  53. data/lib/rcfiles/rcfiles/system_settings_rc +191 -0
  54. data/lib/rcfiles/rcfiles/term_rc +9 -0
  55. data/lib/rcfiles/rcfiles/video_rc +24 -0
  56. data/lib/rcfiles/requires/require_the_expand_cd_aliases.rb +7 -0
  57. data/lib/rcfiles/requires/require_the_rcfiles_constants.rb +21 -0
  58. data/lib/rcfiles/requires/require_the_rcfiles_project.rb +66 -0
  59. data/lib/rcfiles/requires/try_to_require_syck_and_psych.rb +18 -0
  60. data/lib/rcfiles/toplevel_methods/autogenerate_rc_file_from_this_yaml_file.rb +102 -0
  61. data/lib/rcfiles/toplevel_methods/change_directory.rb +16 -0
  62. data/lib/rcfiles/toplevel_methods/convert.rb +118 -0
  63. data/lib/rcfiles/toplevel_methods/create_windows_cd_aliases_bat_file.rb +51 -0
  64. data/lib/rcfiles/toplevel_methods/e.rb +16 -0
  65. data/lib/rcfiles/toplevel_methods/esystem.rb +19 -0
  66. data/lib/rcfiles/toplevel_methods/generate_yaml_files.rb +148 -0
  67. data/lib/rcfiles/toplevel_methods/infer.rb +83 -0
  68. data/lib/rcfiles/toplevel_methods/is_on_roebe.rb +16 -0
  69. data/lib/rcfiles/toplevel_methods/main_directory.rb +108 -0
  70. data/lib/rcfiles/toplevel_methods/misc.rb +304 -0
  71. data/lib/rcfiles/toplevel_methods/n_registered_aliases_in_total.rb +55 -0
  72. data/lib/rcfiles/toplevel_methods/no_file_exists_at.rb +19 -0
  73. data/lib/rcfiles/toplevel_methods/notifications.rb +33 -0
  74. data/lib/rcfiles/toplevel_methods/rds.rb +16 -0
  75. data/lib/rcfiles/toplevel_methods/remove_newlines.rb +29 -0
  76. data/lib/rcfiles/toplevel_methods/report.rb +53 -0
  77. data/lib/rcfiles/toplevel_methods/return_standard_header.rb +36 -0
  78. data/lib/rcfiles/toplevel_methods/run_it.rb +46 -0
  79. data/lib/rcfiles/toplevel_methods/save_file.rb +27 -0
  80. data/lib/rcfiles/toplevel_methods/use_psych_or_syck.rb +50 -0
  81. data/lib/rcfiles/toplevel_methods/use_quotes.rb +68 -0
  82. data/lib/rcfiles/toplevel_methods/verbosity.rb +28 -0
  83. data/lib/rcfiles/version/version.rb +26 -0
  84. data/lib/rcfiles/yaml/aliases.yml +20991 -0
  85. data/lib/rcfiles/yaml/cd_aliases.yml +13970 -0
  86. data/lib/rcfiles/yaml/ls_colours.yml +128 -0
  87. data/lib/rcfiles/yaml/path_variable.yml +12 -0
  88. data/lib/rcfiles/yaml/pkgconfig.yml +46 -0
  89. data/lib/rcfiles/yaml/programs_aliases.yml +17081 -0
  90. data/lib/rcfiles/yaml/ps1.yml +82 -0
  91. data/lib/rcfiles/yaml/store_into_this_directory.yml +1 -0
  92. data/lib/rcfiles/yaml/system_settings.yml +513 -0
  93. data/lib/rcfiles/yaml/use_psych_or_syck.yml +1 -0
  94. data/rcfiles.gemspec +56 -0
  95. data/test/testing_expand_cd_aliases.rb +47 -0
  96. data/test/testing_yaml_to_rcfiles.rb +9 -0
  97. metadata +201 -0
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'rcfiles/constants/misc.rb'
6
+ # =========================================================================== #
7
+ module Rcfiles
8
+
9
+ require 'rcfiles/project/project.rb'
10
+
11
+ # ========================================================================= #
12
+ # === N
13
+ # ========================================================================= #
14
+ N = "\n"
15
+
16
+ # ========================================================================= #
17
+ # === HOME_DIR
18
+ # ========================================================================= #
19
+ HOME_DIR = '/home/'
20
+
21
+ # ========================================================================= #
22
+ # === DIRECTORY_CONTAINING_THE_RC_FILES_ON_MY_HOME_SYSTEM
23
+ #
24
+ # This constant is obviously not so useful for other people - it is
25
+ # for my home system only. The target is, in that case, hardcoded.
26
+ # ========================================================================= #
27
+ DIRECTORY_CONTAINING_THE_RC_FILES_ON_MY_HOME_SYSTEM =
28
+ "#{HOME_DIR}x/DATA/PC/OS/LINUX/yaml/"
29
+
30
+ # ========================================================================= #
31
+ # === LINUX_YAML_BASE_DIRECTORY
32
+ #
33
+ # Simply point to the environment variable $LINUX_YAML.
34
+ #
35
+ # cd $LINUX_YAML
36
+ #
37
+ # ========================================================================= #
38
+ if ENV['LINUX_YAML']
39
+ LINUX_YAML_BASE_DIRECTORY = "#{ENV['LINUX_YAML']}/"
40
+ else
41
+ LINUX_YAML_BASE_DIRECTORY = DIRECTORY_CONTAINING_THE_RC_FILES_ON_MY_HOME_SYSTEM
42
+ end
43
+
44
+ # ========================================================================= #
45
+ # === Rcfiles::FILE_STORE_INTO_THIS_DIRECTORY
46
+ # ========================================================================= #
47
+ FILE_STORE_INTO_THIS_DIRECTORY =
48
+ "#{project_yaml_dir?}store_into_this_directory.yml"
49
+
50
+ # ========================================================================= #
51
+ # === CREATE_RCFILES_WHERE
52
+ #
53
+ # Where to put the RC files by default. Must be a directory. But,
54
+ # we must first check whether the file exists.
55
+ # ========================================================================= #
56
+ _ = FILE_STORE_INTO_THIS_DIRECTORY
57
+ if File.exist? _
58
+ # ======================================================================= #
59
+ # This clause is the default one.
60
+ # ======================================================================= #
61
+ CREATE_RCFILES_WHERE = File.read(_).strip # '/AUTOGENERATED/'
62
+ else
63
+ # ======================================================================= #
64
+ # This one is just a rescued-variant defaulting to the home directory
65
+ # as base-directory.
66
+ # ======================================================================= #
67
+ CREATE_RCFILES_WHERE = File.expand_path('~/AUTOGENERATED/')
68
+ end
69
+
70
+ # ========================================================================= #
71
+ # === RUBY_SRC_DIR_AT_HOME
72
+ # ========================================================================= #
73
+ RUBY_SRC_DIR_AT_HOME = "#{HOME_DIR}x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/"
74
+
75
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'rcfiles/constants/namespace.rb'
6
+ # =========================================================================== #
7
+ module Rcfiles
8
+
9
+ # ========================================================================= #
10
+ # === NAMESPACE
11
+ # ========================================================================= #
12
+ NAMESPACE = inspect
13
+
14
+ end
15
+
16
+ if __FILE__ == $PROGRAM_NAME
17
+ p Rcfiles.constants.sort
18
+ end
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'rcfiles/expand_cd_aliases/constants.rb'
6
+ # =========================================================================== #
7
+ require 'rcfiles/files/file_cd_aliases.rb'
8
+
9
+ module Rcfiles
10
+
11
+ class ExpandCdAliases # === Rcfiles::ExpandCdAliases
12
+
13
+ # ========================================================================= #
14
+ # === NAMESPACE
15
+ # ========================================================================= #
16
+ NAMESPACE = inspect
17
+
18
+ # ========================================================================= #
19
+ # === Rcfiles::ExpandCdAliases::FILE_CD_ALIASES
20
+ #
21
+ # This constant, called FILE_CD_ALIASES, will store the path to the
22
+ # file called 'cd_aliases.yml'.
23
+ #
24
+ # We will query the toplevel module Rcfiles for the path to this file.
25
+ # ========================================================================= #
26
+ FILE_CD_ALIASES = ::Rcfiles.file_cd_aliases?
27
+
28
+ # ========================================================================= #
29
+ # === Rcfiles::ExpandCdAliases::NAME_OF_FILE
30
+ # ========================================================================= #
31
+ NAME_OF_FILE = 'expand_cd_aliases.rb'
32
+
33
+ # ========================================================================= #
34
+ # === Rcfiles::ExpandCdAliases::SHALL_WE_SHOW_EXCEPTIONS
35
+ # ========================================================================= #
36
+ SHALL_WE_SHOW_EXCEPTIONS = false
37
+
38
+ # ========================================================================= #
39
+ # === Rcfiles::ExpandCdAliases::DEFAULT_RUN_MODE
40
+ # ========================================================================= #
41
+ DEFAULT_RUN_MODE = false
42
+
43
+ # ========================================================================= #
44
+ # === EMPTY_STRING
45
+ #
46
+ # Dummy empty string object.
47
+ # ========================================================================= #
48
+ EMPTY_STRING = ''.dup
49
+
50
+ end; end
@@ -0,0 +1,626 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Rcfiles::ExpandCdAliases
6
+ #
7
+ # The purpose of this class is to expand my cd-aliases, which are usually
8
+ # stored in the file "cd_aliases.yml", which in turn is a part of the
9
+ # Rcfiles project.
10
+ #
11
+ # For example, "pwdj" is an alias to cd into the directory "/Depot/j/" on
12
+ # my home system(s).
13
+ #
14
+ # That way, we can provide these aliases to other ruby projects conveniently.
15
+ # In fact, this has been a primary reason for creating this class - it
16
+ # was to make all cd_aliases available within the DiamondShell project,
17
+ # specifically.
18
+ #
19
+ # Specific Usage Example and the main API:
20
+ #
21
+ # require 'rcfiles'
22
+ # expand_cd_aliases = Rcfiles::ExpandCdAliases.new(_)
23
+ # if Rcfiles::ExpandCdAliases.is_included? i # If we have thus found it.
24
+ # do_someting()
25
+ #
26
+ # =========================================================================== #
27
+ # require 'rcfiles/expand_cd_aliases/expand_cd_aliases.rb'
28
+ # =========================================================================== #
29
+ require 'rcfiles/toplevel_methods/e.rb'
30
+ require 'rcfiles/toplevel_methods/no_file_exists_at.rb'
31
+ require 'rcfiles/toplevel_methods/save_file.rb'
32
+ require 'rcfiles/version/version.rb'
33
+ require 'rcfiles/constants/encodings.rb'
34
+ require 'rcfiles/colours/colours.rb'
35
+ require 'rcfiles/expand_cd_aliases/constants.rb'
36
+ require 'rcfiles/expand_cd_aliases/run.rb'
37
+
38
+ module Rcfiles
39
+
40
+ class ExpandCdAliases # === Rcfiles::ExpandCdAliases
41
+
42
+ begin
43
+ require 'opn'
44
+ rescue LoadError; end
45
+
46
+ begin
47
+ require 'convert_global_env'
48
+ rescue LoadError; end
49
+
50
+ alias e puts
51
+
52
+ # ========================================================================= #
53
+ # === @cd_aliases
54
+ #
55
+ # This variable will hold the whole cd-aliases dataset. It should be
56
+ # kept as a Hash at all times.
57
+ #
58
+ # Do note that this variable will be an empty Hash by default. It will
59
+ # be filled only when we need to access the dataset; this should make
60
+ # the Rcfiles project a bit more lightweight by default.
61
+ # ========================================================================= #
62
+ @cd_aliases = {}
63
+
64
+ # ========================================================================= #
65
+ # === ExpandCdAliases.cd_aliases?
66
+ #
67
+ # Main getter over the cd-aliases. This will be our main datastructure.
68
+ # ========================================================================= #
69
+ def self.cd_aliases?
70
+ @cd_aliases
71
+ end
72
+
73
+ # ========================================================================= #
74
+ # === ExpandCdAliases.clear
75
+ #
76
+ # Reset the main Hash again.
77
+ # ========================================================================= #
78
+ def self.clear
79
+ @cd_aliases.clear
80
+ end
81
+
82
+ # ========================================================================= #
83
+ # === Rcfiles::ExpandCdAliases.register_sigint
84
+ # ========================================================================= #
85
+ def self.register_sigint
86
+ Signal.trap('SIGINT') { exit }
87
+ end
88
+
89
+ register_sigint # <- And call it at once.
90
+
91
+ # ========================================================================= #
92
+ # === @main_yaml_file
93
+ #
94
+ # This variable will keep track of the main yaml file, that is, the
95
+ # file that holds the dataset for "cd-aliases".
96
+ #
97
+ # It is nil initially here, but will be changed lateron through a method
98
+ # call.
99
+ # ========================================================================= #
100
+ @main_yaml_file = nil
101
+
102
+ # ========================================================================= #
103
+ # === ExpandCdAliases.set_main_yaml_file
104
+ #
105
+ # The user can modify which yaml file is to be used, via this method call.
106
+ # ========================================================================= #
107
+ def self.set_main_yaml_file(
108
+ i = :default
109
+ )
110
+ case i
111
+ when :default
112
+ i = FILE_CD_ALIASES
113
+ end
114
+ @main_yaml_file = i
115
+ end
116
+
117
+ # ========================================================================= #
118
+ # Define the main cd-aliases file next. The constant FILE_CD_ALIASES
119
+ # must be defined for this to work.
120
+ # ========================================================================= #
121
+ ExpandCdAliases.set_main_yaml_file(:default)
122
+
123
+ # ========================================================================= #
124
+ # === ExpandCdAliases.yaml_file?
125
+ # ========================================================================= #
126
+ def self.yaml_file?
127
+ @main_yaml_file
128
+ end
129
+
130
+ # ========================================================================= #
131
+ # === initialize
132
+ #
133
+ # The first argument is optional. If given then we will query for this
134
+ # particular key, aka whether it is a cd-alias or whether it is not.
135
+ # ========================================================================= #
136
+ def initialize(
137
+ optional_seek_this_key = nil,
138
+ run_already = DEFAULT_RUN_MODE
139
+ )
140
+ reset
141
+ if block_given?
142
+ yielded = yield
143
+ case yielded
144
+ when :run
145
+ run_already = true
146
+ end
147
+ end
148
+ case run_already
149
+ when :do_not_report_errors
150
+ @report_errors = false
151
+ run_already = DEFAULT_RUN_MODE
152
+ when :be_silent
153
+ be_silent
154
+ run_already = DEFAULT_RUN_MODE
155
+ end # This block must run before sanitize_cd_aliases() is called.
156
+ if optional_seek_this_key
157
+ set_return_string(optional_seek_this_key)
158
+ end
159
+ run if run_already
160
+ end
161
+
162
+ # ========================================================================= #
163
+ # === reset (reset tag)
164
+ # ========================================================================= #
165
+ def reset
166
+ @hash = {}
167
+ @return_string = nil # This is the return string. Nil on startup.
168
+ @seek_this_key = '' # The query-key that we are looking for.
169
+ # ======================================================================= #
170
+ # The next variable determines whether we will report errors or
171
+ # whether we will not. By default this class will report errors.
172
+ # ======================================================================= #
173
+ @report_errors = true
174
+ be_quiet # Do not be too noisy by default.
175
+ end
176
+
177
+ # ========================================================================= #
178
+ # === opnn
179
+ # ========================================================================= #
180
+ def opnn
181
+ super(NAMESPACE) if Object.const_defined? :Opn
182
+ end; alias opn opnn # === opn
183
+
184
+ # ========================================================================= #
185
+ # === verbose_points_to?
186
+ # ========================================================================= #
187
+ def verbose_points_to?(i)
188
+ i = i.to_s
189
+ if is_included? i
190
+ opnn; e "#{rev}Yes, the key `#{::Rcfiles.sfancy(i)}` is included."
191
+ opnn; e "#{rev}It points to the directory: #{sdir(@hash[i])}"
192
+ else
193
+ opnn; e "#{rev}No, the key `#{::Rcfiles.sfancy(i)}` is not "\
194
+ "included in the cd-aliases."
195
+ end
196
+ end
197
+
198
+ # ========================================================================= #
199
+ # === set_return_string
200
+ #
201
+ # Before this method is called, sanitize_cd_aliases() should have been
202
+ # called in order to initialize our dataset, and also set up the
203
+ # @hash variable properly.
204
+ #
205
+ # This method will assign to @seek_this_key and @return_string.
206
+ # ========================================================================= #
207
+ def set_return_string(i = '')
208
+ if @hash.empty?
209
+ # ===================================================================== #
210
+ # Initialize the main hash if it is empty.
211
+ # ===================================================================== #
212
+ initialize_main_hash
213
+ end
214
+ i = i.first if i.is_a? Array
215
+ i = i.to_s.dup
216
+ set_seek_this_key(i)
217
+ @return_string = @hash[i]
218
+ end; alias set set_return_string # === set
219
+
220
+ # ========================================================================= #
221
+ # === rev
222
+ # ========================================================================= #
223
+ def rev
224
+ if ::Rcfiles.use_colours?
225
+ ::Colours.rev
226
+ else
227
+ EMPTY_STRING
228
+ end
229
+ end
230
+
231
+ # ========================================================================= #
232
+ # === test
233
+ # ========================================================================= #
234
+ def test(i = @seek_this_key)
235
+ verbose_points_to?(i)
236
+ end
237
+
238
+ # ========================================================================= #
239
+ # === return_string?
240
+ # ========================================================================= #
241
+ def return_string?
242
+ @return_string # Return the expanded return string.
243
+ end; alias result? return_string? # === result?
244
+ alias _ return_string? # === _
245
+
246
+ # ========================================================================= #
247
+ # === size?
248
+ #
249
+ # Query how many keys we have.
250
+ # ========================================================================= #
251
+ def size?
252
+ @hash.keys.size
253
+ end; alias size size? # === size
254
+
255
+ # ========================================================================= #
256
+ # === seek_this_key?
257
+ # ========================================================================= #
258
+ def seek_this_key?
259
+ @seek_this_key
260
+ end
261
+
262
+ # ========================================================================= #
263
+ # === set_seek_this_key
264
+ # ========================================================================= #
265
+ def set_seek_this_key(i)
266
+ @seek_this_key = i
267
+ end
268
+
269
+ # ========================================================================= #
270
+ # === is_included?
271
+ #
272
+ # Query whether our expanded cd-aliases have the given key (first
273
+ # argument) included or whether they do not.
274
+ # ========================================================================= #
275
+ def is_included?(
276
+ i = @seek_this_key
277
+ )
278
+ @hash.has_key?(i)
279
+ end; alias has_key? is_included? # === has_key?
280
+ alias is_this_alias_included? is_included? # === is_this_alias_included?
281
+ alias is_this_input_a_cd_alias? is_included? # === is_this_input_a_cd_alias?
282
+
283
+ # ========================================================================= #
284
+ # === report_to_user
285
+ #
286
+ # This is a "poor man's" debug variant.
287
+ # ========================================================================= #
288
+ def report_to_user
289
+ pp @hash
290
+ end
291
+
292
+ # ========================================================================= #
293
+ # === show_exceptions?
294
+ # ========================================================================= #
295
+ def show_exceptions?
296
+ SHALL_WE_SHOW_EXCEPTIONS
297
+ end
298
+
299
+ # ========================================================================= #
300
+ # === be_verbose
301
+ # ========================================================================= #
302
+ def be_verbose
303
+ @be_verbose = true
304
+ end
305
+
306
+ # ========================================================================= #
307
+ # === be_silent
308
+ # ========================================================================= #
309
+ def be_silent
310
+ @be_verbose = false
311
+ end; alias be_quiet be_silent # === be_quiet
312
+
313
+ # ========================================================================= #
314
+ # === version?
315
+ # ========================================================================= #
316
+ def version?
317
+ ::Rcfiles::VERSION
318
+ end
319
+
320
+ # ========================================================================= #
321
+ # === report_version
322
+ # ========================================================================= #
323
+ def report_version
324
+ e "The version is: #{sfancy(version?)}"
325
+ end
326
+
327
+ # ========================================================================= #
328
+ # === be_verbose?
329
+ # ========================================================================= #
330
+ def be_verbose?
331
+ @be_verbose
332
+ end
333
+
334
+ # ========================================================================= #
335
+ # === report_errors?
336
+ # ========================================================================= #
337
+ def report_errors?
338
+ @report_errors
339
+ end
340
+
341
+ # ========================================================================= #
342
+ # === sanitize_hash
343
+ #
344
+ # We make @hash better here, by sanitizing some value entries.
345
+ # ========================================================================= #
346
+ def sanitize_hash
347
+ _ = {}
348
+ @hash.each {|key, value|
349
+ if value.include? '/' # assume it is ok here
350
+ else # else work on it.
351
+ value = @hash[value] if hash?.has_key? value
352
+ end
353
+ _[key] = value
354
+ }
355
+ @hash = _
356
+ end
357
+
358
+ # ========================================================================= #
359
+ # === initialize_main_hash
360
+ #
361
+ # This method will do two things:
362
+ #
363
+ # 1) initialize the main dataset
364
+ # 2) sanitize this dataset (for use within this class)
365
+ #
366
+ # ========================================================================= #
367
+ def initialize_main_hash
368
+ # ======================================================================= #
369
+ # Initialize the main dataset if it has not been loaded up yet.
370
+ # ======================================================================= #
371
+ if ::Rcfiles::ExpandCdAliases.cd_aliases?.empty?
372
+ ::Rcfiles::ExpandCdAliases.load_dataset_from_main_file
373
+ end
374
+ sanitize_cd_aliases
375
+ end; alias initialize_main_dataset initialize_main_hash # === initialize_main_dataset
376
+
377
+ # ========================================================================= #
378
+ # === sanitize_cd_aliases
379
+ #
380
+ # We sanitize the whole dataset. At first, we correct all $ entries.
381
+ #
382
+ # In order for this method to work, the main dataset has to be set.
383
+ # ========================================================================= #
384
+ def sanitize_cd_aliases(
385
+ use_this_dataset = ::Rcfiles::ExpandCdAliases.cd_aliases?
386
+ )
387
+ hash = {}
388
+ # ======================================================================= #
389
+ # First, set up our new hash and also replace all $ found.
390
+ # ======================================================================= #
391
+ use_this_dataset.each {|key, value|
392
+ begin
393
+ unless value.to_s.encoding.to_s == MAIN_ENCODING_TO_USE
394
+ value = value.to_s.encode(MAIN_ENCODING_TO_USE) # Work with the main-encoding past this point.
395
+ end
396
+ rescue Encoding::InvalidByteSequenceError => error
397
+ if be_verbose? and show_exceptions? and report_errors?
398
+ opnn; e "#{NAME_OF_FILE}: An exception/error happened for -> #{simp(key.to_s)}"
399
+ opnn; e 'We will now feedback this error:'
400
+ pp error
401
+ end
402
+ end
403
+ # ===================================================================== #
404
+ # Next, work on all value-entries that include a '$' character.
405
+ # ===================================================================== #
406
+ if value.include? '$'
407
+ value = ConvertGlobalEnv.convert(value, report_errors?)
408
+ end
409
+ # ===================================================================== #
410
+ # Next, we must perform a few batch-gsubs, but we must be careful,
411
+ # as this could lead to bugs.
412
+ # ===================================================================== #
413
+ unless value.encoding.to_s == 'UTF-8'
414
+ # =================================================================== #
415
+ # First, we chop off trailing occurences of 'pwd', but as of May
416
+ # 2014, I decided that this is no longer wanted. Certain aliases
417
+ # such as "pwdusb4" would misfunction as a result of
418
+ # the following .gsub:
419
+ # value.gsub!(/pwd$/,'') if value.include? 'pwd'
420
+ # =================================================================== #
421
+ value.gsub!(/cd /,'') if value.include? 'cd '
422
+ value.gsub!(/ ll/,'') if value.include? ' ll'
423
+ value.gsub!(/ ls/,'') if value.include? ' ls'
424
+ value.gsub!(/> \/dev\/null/,'') if value.include? '> /dev/null'
425
+ value.gsub!(/2>&1/,'') if value.include? '2>&1'
426
+ # =================================================================== #
427
+ # As of May 2014, we no longer get rid of ; characters.
428
+ # =================================================================== #
429
+ # value.gsub!(/;/,'') if value.include? ';'
430
+ value = value.strip
431
+ end
432
+ hash[key] = value
433
+ }
434
+ @hash = hash
435
+ # ======================================================================= #
436
+ # Ok, at this point we have our hash data, and we also sanitized
437
+ # it a little bit already, by getting rid of the $ values.
438
+ # So now we call another method to further clean our hash. This
439
+ # is evidently totally hackish, but it also sort of works.
440
+ # ======================================================================= #
441
+ sanitize_hash
442
+ sanitize_hash
443
+ sanitize_hash
444
+ sanitize_hash
445
+ end
446
+
447
+ # ========================================================================= #
448
+ # === hash?
449
+ #
450
+ # Query the main hash.
451
+ # ========================================================================= #
452
+ def hash?
453
+ @hash
454
+ end; alias hash hash? # === hash
455
+ alias cd_aliases? hash? # === cd_aliases?
456
+
457
+ # ========================================================================= #
458
+ # === []
459
+ # ========================================================================= #
460
+ def [](i)
461
+ @hash[i]
462
+ end
463
+ # ========================================================================= #
464
+ # === Rcfiles::ExpandCdAliases.is_included?
465
+ # ========================================================================= #
466
+ def self.is_included?(i)
467
+ _ = self.new(i)
468
+ return _.is_included?(i)
469
+ end; self.instance_eval { alias does_include? is_included? } # === Rcfiles::ExpandCdAliases.does_include?
470
+ # Rcfiles::ExpandCdAliases.include? # <-- This here would conflict, hence we can not use it.
471
+
472
+ # ========================================================================= #
473
+ # === Rcfiles::ExpandCdAliases.points_at?
474
+ # ========================================================================= #
475
+ def self.points_at?(i)
476
+ _ = self.new(i)
477
+ return _._
478
+ end
479
+
480
+ # ========================================================================= #
481
+ # === Load up the dataset next
482
+ #
483
+ # This determines the main cd-aliases file.
484
+ # ========================================================================= #
485
+ def self.load_dataset_from_main_file(
486
+ i = self.yaml_file?
487
+ )
488
+ if File.exist? i
489
+ begin
490
+ dataset = YAML.load_file(i) # This may be UTF-8 encoding.
491
+ # =================================================================== #
492
+ # Assign the cd-aliases via a toplevel method next:
493
+ # =================================================================== #
494
+ self.set_cd_aliases(dataset)
495
+ rescue Psych::SyntaxError => error
496
+ e 'A Psych::SyntaxError happened for the file `'+i+'`.'
497
+ pp error
498
+ end
499
+ else # Else use an empty dataset instead.
500
+ if is_on_roebe?
501
+ ::Rcfiles.no_file_exists_at(i)
502
+ end
503
+ self.set_cd_aliases {}
504
+ end
505
+ end
506
+
507
+ # ========================================================================= #
508
+ # === ExpandCdAliases.set_cd_aliases (set_cd_aliases tag)
509
+ #
510
+ # The @cd_aliases should always be a Hash. This is an explicit setter,
511
+ # though, so the user could always assign a non-Hash. No error will
512
+ # be raised in this case.
513
+ # ========================================================================= #
514
+ def self.set_cd_aliases(i = {})
515
+ @cd_aliases = i
516
+ end; self.instance_eval { alias set_cd_aliases= set_cd_aliases } # === ExpandCdAliases.set_cd_aliases=
517
+
518
+ # ========================================================================= #
519
+ # === ExpandCdAliases.n_entries?
520
+ #
521
+ # How many entries can be found in class ExpandCdAliases is answered
522
+ # by this toplevel method.
523
+ # ========================================================================= #
524
+ def self.n_entries?
525
+ @cd_aliases.keys.size
526
+ end
527
+
528
+ # ========================================================================= #
529
+ # === ExpandCdAliases.e
530
+ # ========================================================================= #
531
+ def self.e(i = '')
532
+ ::Rcfiles.e(i)
533
+ end
534
+
535
+ # ========================================================================= #
536
+ # === Rcfiles::ExpandCdAliases.is_this_alias_included?
537
+ # ========================================================================= #
538
+ def self.is_this_alias_included?(i)
539
+ self.new(i).is_included?
540
+ end; self.instance_eval { alias is_this_input_a_cd_alias? is_this_alias_included? } # === Rcfiles::ExpandCdAliases.is_this_input_a_cd_alias?
541
+
542
+ # ========================================================================= #
543
+ # === Rcfiles::ExpandCdAliases[]
544
+ # ========================================================================= #
545
+ def self.[](i)
546
+ i = i.to_s
547
+ if self.is_this_alias_included? i
548
+ _ = self.new(i)
549
+ i = _.hash[i]
550
+ end
551
+ return i
552
+ end
553
+
554
+ # ========================================================================= #
555
+ # === Rcfiles::ExpandCdAliases.save_into_ruby_file
556
+ #
557
+ # This method will store the hash in a CONSTANT, into a file (normally
558
+ # a .rb file).
559
+ #
560
+ # The first argument to this method denotes where to store this file, so
561
+ # you have the possibility to save into some special location instead.
562
+ #
563
+ # The name of the hash is provided via the the second argument to
564
+ # this method.
565
+ # ========================================================================= #
566
+ def self.save_into_ruby_file(
567
+ store_into_this_file = '/Depot/j/expand_cd_aliases_hash.rb',
568
+ name_of_the_main_hash = 'EXPAND_CD_ALIASES_HASH'
569
+ )
570
+ _ = ::Rcfiles::ExpandCdAliases.new
571
+ _.initialize_main_dataset
572
+ dataset = _.cd_aliases?
573
+ # ======================================================================= #
574
+ # First add the header:
575
+ # ======================================================================= #
576
+ what = '#!/usr/bin/ruby -w
577
+ # Encoding: UTF-8
578
+ # frozen_string_literal: true
579
+ # =========================================================================== #
580
+ '.dup
581
+ what << "#{name_of_the_main_hash} = {\n"
582
+ what = ::Rcfiles.ensure_main_encoding(what)
583
+ dataset.each_pair {|key, value|
584
+ key = key.to_s unless key.is_a? String
585
+ value = ConvertGlobalEnv.convert(value)
586
+ key = ::Rcfiles.ensure_main_encoding(key)
587
+ value = ::Rcfiles.ensure_main_encoding(value)
588
+ what << " \"#{key}\": \"#{value}\",\n"
589
+ }
590
+ what << "}\n"
591
+ into = store_into_this_file
592
+ ::Rcfiles.write_what_into(what, into)
593
+ end; self.instance_eval { alias generate_cd_aliases save_into_ruby_file } # === ExpandCdAliases.generate_cd_aliases
594
+
595
+ end
596
+
597
+ # =========================================================================== #
598
+ # === Rcfiles.expand_cd_aliases
599
+ # =========================================================================== #
600
+ def self.expand_cd_aliases(i)
601
+ ::Rcfiles::ExpandCdAliases.new(i)
602
+ end; self.instance_eval { alias cd_alias expand_cd_aliases } # === Rcfiles.cd_alias
603
+
604
+ # ========================================================================= #
605
+ # === Rcfiles.is_this_alias_included?
606
+ # ========================================================================= #
607
+ def self.is_this_alias_included?(i)
608
+ ::Rcfiles::ExpandCdAliases.is_this_alias_included?(i)
609
+ end; self.instance_eval { alias is_this_input_a_cd_alias? is_this_alias_included? } # === Rcfiles.is_this_input_a_cd_alias?
610
+
611
+ # =========================================================================== #
612
+ # === Rcfiles.find_this_cd_alias[]
613
+ # =========================================================================== #
614
+ def self.find_this_cd_alias(i)
615
+ ::Rcfiles::ExpandCdAliases[i]
616
+ end
617
+
618
+ end
619
+
620
+ if __FILE__ == $PROGRAM_NAME # Testing here.
621
+ expand_cd_aliases = Rcfiles::ExpandCdAliases.new(ARGV.first)
622
+ expand_cd_aliases.test
623
+ puts expand_cd_aliases._
624
+ end # ecdaliases
625
+ # exda pwwdusr; exda pwddwwd
626
+ # exda pwdusb4