rcfiles 1.2.46
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 +559 -0
- data/bin/rcfiles +12 -0
- data/bin/rcfiles_run_it +7 -0
- data/doc/README.gen +516 -0
- data/img/LOGO_FOR_THE_RCFILES_PROJECT.png +0 -0
- data/lib/rcfiles/aggregate_all_rcfiles/aggregate_all_rcfiles.rb +137 -0
- data/lib/rcfiles/class/colours.rb +54 -0
- data/lib/rcfiles/class/initialize.rb +66 -0
- data/lib/rcfiles/class/misc.rb +300 -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 +111 -0
- data/lib/rcfiles/commandline/commandline.rb +177 -0
- data/lib/rcfiles/constants/constants.rb +253 -0
- data/lib/rcfiles/directory_aliases/README.md +2 -0
- data/lib/rcfiles/directory_aliases/directory_aliases.rb +647 -0
- data/lib/rcfiles/directory_aliases/toplevel_stored_dataset.rb +177 -0
- data/lib/rcfiles/directory_aliases/yaml_file_used_by_class_directory_aliases.rb +67 -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 +20431 -0
- data/lib/rcfiles/rcfiles/cd_aliases_rc +14980 -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/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 +17571 -0
- data/lib/rcfiles/rcfiles/ps1_rc +9 -0
- data/lib/rcfiles/rcfiles/special_aliases_rc +8 -0
- data/lib/rcfiles/rcfiles/system_rc +13 -0
- data/lib/rcfiles/rcfiles/system_settings_rc +192 -0
- data/lib/rcfiles/rcfiles/term_rc +9 -0
- data/lib/rcfiles/rcfiles/video_rc +24 -0
- data/lib/rcfiles/requires/require_the_directory_aliases.rb +7 -0
- data/lib/rcfiles/requires/require_the_rcfiles_constants.rb +18 -0
- data/lib/rcfiles/requires/require_the_rcfiles_project.rb +67 -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/convert_global_variables_in_the_cd_aliases_file_to_a_standalone_yaml_file.rb +50 -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 +341 -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 +35 -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 +23069 -0
- data/lib/rcfiles/yaml/cd_aliases.yml +15699 -0
- data/lib/rcfiles/yaml/global_variables/README.md +3 -0
- data/lib/rcfiles/yaml/global_variables/global_variables_extracted_from_the_file_cd_aliases.yml +121 -0
- data/lib/rcfiles/yaml/ls_colours.yml +128 -0
- data/lib/rcfiles/yaml/path_variable.yml +13 -0
- data/lib/rcfiles/yaml/pkgconfig.yml +46 -0
- data/lib/rcfiles/yaml/programs_aliases.yml +19203 -0
- data/lib/rcfiles/yaml/programs_aliases.yml~ +19086 -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 +526 -0
- data/lib/rcfiles/yaml/use_psych_or_syck.yml +1 -0
- data/lib/rcfiles.rb +1 -0
- data/rcfiles.gemspec +57 -0
- data/test/testing_directory_aliases.rb +47 -0
- data/test/testing_using_another_path_to_directory_aliases.rb +17 -0
- data/test/testing_yaml_to_rcfiles.rb +9 -0
- metadata +205 -0
@@ -0,0 +1,647 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === Rcfiles::DirectoryAliases
|
6
|
+
#
|
7
|
+
# The purpose of this class is to map between e. g. "pwdj" to "/Depot/j".
|
8
|
+
#
|
9
|
+
# On my home system "pwdj" is an alias to cd into the directory "/Depot/j/",
|
10
|
+
# if said directory exists.
|
11
|
+
#
|
12
|
+
# Thus the class will expand my cd-aliases, which are usually stored
|
13
|
+
# in the file "cd_aliases.yml". These are also part of the Rcfiles
|
14
|
+
# project, for convenience reasons mostly.
|
15
|
+
#
|
16
|
+
# The benefit of being able to expand from my local aliases is that we
|
17
|
+
# can provide these aliases to other ruby projects easily. In fact, this
|
18
|
+
# has been a primary reason for creating this class in the first place -
|
19
|
+
# it was to make all cd_aliases available within the Roebe::Shell project,
|
20
|
+
# specifically. Since the latter can be used on windows, I can then use
|
21
|
+
# vanilla "cmd.exe" and have my shell work with support for all my
|
22
|
+
# custom cd ("change directory") operations. So I can type "tosongs",
|
23
|
+
# and hit the enter-key, and it will change directory to the directory
|
24
|
+
# where I keep all my songs. How convenient! \o/
|
25
|
+
#
|
26
|
+
# Usage example for this class:
|
27
|
+
#
|
28
|
+
# Rcfiles::DirectoryAliases.new(ARGV)
|
29
|
+
# Rcfiles::DirectoryAliases.is_included?('pwdsongs') # => true
|
30
|
+
#
|
31
|
+
# =========================================================================== #
|
32
|
+
# require 'rcfiles/directory_aliases/directory_aliases.rb'
|
33
|
+
# Rcfiles::DirectoryAliases.is_included?('ABC')
|
34
|
+
# =========================================================================== #
|
35
|
+
module Rcfiles
|
36
|
+
|
37
|
+
class DirectoryAliases # === Rcfiles::DirectoryAliases
|
38
|
+
|
39
|
+
alias e puts
|
40
|
+
|
41
|
+
require 'rcfiles/directory_aliases/toplevel_stored_dataset.rb'
|
42
|
+
require 'rcfiles/directory_aliases/yaml_file_used_by_class_directory_aliases.rb'
|
43
|
+
require 'rcfiles/constants/constants.rb'
|
44
|
+
require 'rcfiles/colours/colours.rb'
|
45
|
+
require 'rcfiles/version/version.rb'
|
46
|
+
|
47
|
+
begin
|
48
|
+
require 'opn'
|
49
|
+
rescue LoadError; end
|
50
|
+
|
51
|
+
begin
|
52
|
+
require 'convert_global_env'
|
53
|
+
rescue LoadError; end
|
54
|
+
|
55
|
+
# ========================================================================= #
|
56
|
+
# === NAMESPACE
|
57
|
+
# ========================================================================= #
|
58
|
+
NAMESPACE = inspect
|
59
|
+
|
60
|
+
# ========================================================================= #
|
61
|
+
# === Rcfiles::DirectoryAliases::NAME_OF_FILE
|
62
|
+
# ========================================================================= #
|
63
|
+
NAME_OF_FILE = 'directory_aliases.rb'
|
64
|
+
|
65
|
+
# ========================================================================= #
|
66
|
+
# === Rcfiles::DirectoryAliases::SHALL_WE_SHOW_EXCEPTIONS
|
67
|
+
# ========================================================================= #
|
68
|
+
SHALL_WE_SHOW_EXCEPTIONS = false
|
69
|
+
|
70
|
+
# ========================================================================= #
|
71
|
+
# === Rcfiles::DirectoryAliases::DEFAULT_RUN_MODE
|
72
|
+
# ========================================================================= #
|
73
|
+
DEFAULT_RUN_MODE = true # or false
|
74
|
+
|
75
|
+
# ========================================================================= #
|
76
|
+
# === initialize
|
77
|
+
#
|
78
|
+
# The first argument is typically the key that is sought. It is optional,
|
79
|
+
# though, as the method .find() or .points_at?() can be used with an
|
80
|
+
# argument at any moment in time. That way a cd-alias can be used to
|
81
|
+
# query the dataset.
|
82
|
+
# ========================================================================= #
|
83
|
+
def initialize(
|
84
|
+
commandline_arguments = ARGV,
|
85
|
+
run_already = DEFAULT_RUN_MODE
|
86
|
+
)
|
87
|
+
reset
|
88
|
+
set_commandline_arguments(
|
89
|
+
commandline_arguments
|
90
|
+
)
|
91
|
+
# ======================================================================= #
|
92
|
+
# === Handle blocks given to this class next
|
93
|
+
# ======================================================================= #
|
94
|
+
if block_given?
|
95
|
+
yielded = yield
|
96
|
+
case yielded
|
97
|
+
# ===================================================================== #
|
98
|
+
# === :run
|
99
|
+
# ===================================================================== #
|
100
|
+
when :run
|
101
|
+
run_already = true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
case run_already
|
105
|
+
# ======================================================================= #
|
106
|
+
# === :be_silent
|
107
|
+
# ======================================================================= #
|
108
|
+
when :be_silent
|
109
|
+
be_silent
|
110
|
+
run_already = DEFAULT_RUN_MODE
|
111
|
+
# ======================================================================= #
|
112
|
+
# === :do_not_report_errors
|
113
|
+
# ======================================================================= #
|
114
|
+
when :do_not_report_errors
|
115
|
+
set_report_errors(false)
|
116
|
+
run_already = DEFAULT_RUN_MODE
|
117
|
+
end
|
118
|
+
run if run_already
|
119
|
+
end
|
120
|
+
|
121
|
+
# ========================================================================= #
|
122
|
+
# === reset (reset tag)
|
123
|
+
# ========================================================================= #
|
124
|
+
def reset
|
125
|
+
# ======================================================================= #
|
126
|
+
# === @namespace
|
127
|
+
# ======================================================================= #
|
128
|
+
@namespace = NAMESPACE
|
129
|
+
# ======================================================================= #
|
130
|
+
# === @internal_hash
|
131
|
+
# ======================================================================= #
|
132
|
+
@internal_hash = {}
|
133
|
+
# ======================================================================= #
|
134
|
+
# === :be_verbose
|
135
|
+
# ======================================================================= #
|
136
|
+
@internal_hash[:be_verbose] = true
|
137
|
+
# ======================================================================= #
|
138
|
+
# === :report_errors
|
139
|
+
#
|
140
|
+
# The next variable determines whether we will report errors or
|
141
|
+
# whether we will not. By default this class will report errors.
|
142
|
+
#
|
143
|
+
# An example error may be Encoding::InvalidByteSequenceError being
|
144
|
+
# raised due to the .yml file being incorrect. In my own yaml files
|
145
|
+
# this error no longer happens, so the class no longer has to handle
|
146
|
+
# this - but in the event that we may re-enable this feature one
|
147
|
+
# day, for other users, I considered it useful in May 2022 to
|
148
|
+
# still retain the :report_errors flag.
|
149
|
+
#
|
150
|
+
# The old code looked something like this:
|
151
|
+
#
|
152
|
+
# rescue Encoding::InvalidByteSequenceError => error
|
153
|
+
# if be_verbose? and show_exceptions? and report_errors?
|
154
|
+
# opnn; e "#{NAME_OF_FILE}: An exception/error happened for → #{simp(key.to_s)}"
|
155
|
+
# opnn; e 'We will now feedback this error:'
|
156
|
+
# pp error
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
# ======================================================================= #
|
161
|
+
@internal_hash[:report_errors] = true
|
162
|
+
be_quiet # Do not be too noisy by default.
|
163
|
+
load_the_dataset_from_the_file_cd_aliases
|
164
|
+
end
|
165
|
+
|
166
|
+
# ========================================================================= #
|
167
|
+
# === be_verbose
|
168
|
+
# ========================================================================= #
|
169
|
+
def be_verbose
|
170
|
+
@internal_hash[:be_verbose] = true
|
171
|
+
end
|
172
|
+
|
173
|
+
# ========================================================================= #
|
174
|
+
# === be_silent
|
175
|
+
# ========================================================================= #
|
176
|
+
def be_silent
|
177
|
+
@internal_hash[:be_verbose] = false
|
178
|
+
end; alias be_quiet be_silent # === be_quiet
|
179
|
+
|
180
|
+
# ========================================================================= #
|
181
|
+
# === be_verbose?
|
182
|
+
# ========================================================================= #
|
183
|
+
def be_verbose?
|
184
|
+
@internal_hash[:be_verbose]
|
185
|
+
end
|
186
|
+
|
187
|
+
# ========================================================================= #
|
188
|
+
# === dataset?
|
189
|
+
#
|
190
|
+
# This is the query-method to access the main dataset of this class,
|
191
|
+
# which is a Hash.
|
192
|
+
# ========================================================================= #
|
193
|
+
def dataset?
|
194
|
+
@internal_hash[:dataset]
|
195
|
+
end; alias hash? dataset? # === hash?
|
196
|
+
alias hash dataset? # === hash
|
197
|
+
alias cd_aliases? dataset? # === cd_aliases?
|
198
|
+
|
199
|
+
# ========================================================================= #
|
200
|
+
# === set_commandline_arguments
|
201
|
+
# ========================================================================= #
|
202
|
+
def set_commandline_arguments(i = '')
|
203
|
+
i = [i].flatten.compact
|
204
|
+
@commandline_arguments = i
|
205
|
+
end
|
206
|
+
|
207
|
+
# ========================================================================= #
|
208
|
+
# === commandline_arguments?
|
209
|
+
# ========================================================================= #
|
210
|
+
def commandline_arguments?
|
211
|
+
@commandline_arguments
|
212
|
+
end
|
213
|
+
|
214
|
+
# ========================================================================= #
|
215
|
+
# === first_argument?
|
216
|
+
# ========================================================================= #
|
217
|
+
def first_argument?
|
218
|
+
@commandline_arguments.first
|
219
|
+
end; alias first? first_argument? # === first?
|
220
|
+
alias seek_this_key? first_argument? # === seek_this_key?
|
221
|
+
alias seek_which_key? first_argument? # === seek_which_key?
|
222
|
+
|
223
|
+
# ========================================================================= #
|
224
|
+
# === report_version
|
225
|
+
# ========================================================================= #
|
226
|
+
def report_version
|
227
|
+
e "The version is: #{sfancy(version?)}"
|
228
|
+
end
|
229
|
+
|
230
|
+
# ========================================================================= #
|
231
|
+
# === opnn
|
232
|
+
# ========================================================================= #
|
233
|
+
def opnn
|
234
|
+
if Object.const_defined? :Opn
|
235
|
+
Opn.opn(namespace: NAMESPACE)
|
236
|
+
end
|
237
|
+
end; alias opn opnn # === opn
|
238
|
+
|
239
|
+
# ========================================================================= #
|
240
|
+
# === report_errors?
|
241
|
+
# ========================================================================= #
|
242
|
+
def report_errors?
|
243
|
+
@internal_hash[:report_errors]
|
244
|
+
end
|
245
|
+
|
246
|
+
# ========================================================================= #
|
247
|
+
# === set_report_errors
|
248
|
+
# ========================================================================= #
|
249
|
+
def set_report_errors(i)
|
250
|
+
@internal_hash[:report_errors] = i
|
251
|
+
end
|
252
|
+
|
253
|
+
# ========================================================================= #
|
254
|
+
# === translate_key_into_value
|
255
|
+
#
|
256
|
+
# This method will NOT do any additional sanitizing. It will simply
|
257
|
+
# query the main hash, as-is.
|
258
|
+
# ========================================================================= #
|
259
|
+
def translate_key_into_value(key)
|
260
|
+
@internal_hash[:dataset][key]
|
261
|
+
end
|
262
|
+
|
263
|
+
# ========================================================================= #
|
264
|
+
# === rds
|
265
|
+
# ========================================================================= #
|
266
|
+
def rds(i)
|
267
|
+
i.squeeze('/')
|
268
|
+
end
|
269
|
+
|
270
|
+
# ========================================================================= #
|
271
|
+
# === version?
|
272
|
+
#
|
273
|
+
# This is mostly a convenience method, to quickly query the current
|
274
|
+
# version of the rcfiles gem in use.
|
275
|
+
# ========================================================================= #
|
276
|
+
def version?
|
277
|
+
::Rcfiles::VERSION
|
278
|
+
end
|
279
|
+
|
280
|
+
# ========================================================================= #
|
281
|
+
# === keys?
|
282
|
+
# ========================================================================= #
|
283
|
+
def keys?
|
284
|
+
dataset?.keys
|
285
|
+
end; alias keys keys? # === keys
|
286
|
+
|
287
|
+
# ========================================================================= #
|
288
|
+
# === size?
|
289
|
+
#
|
290
|
+
# Query how many keys we have registered.
|
291
|
+
# ========================================================================= #
|
292
|
+
def size?
|
293
|
+
keys?.size
|
294
|
+
end; alias size size? # === size
|
295
|
+
alias keys size? # === keys
|
296
|
+
|
297
|
+
# ========================================================================= #
|
298
|
+
# === is_this_key_included?
|
299
|
+
#
|
300
|
+
# This method can be used to query whether our expanded directory-aliases
|
301
|
+
# contains the given key (first input argument to this method) or
|
302
|
+
# whether it does not.
|
303
|
+
# ========================================================================= #
|
304
|
+
def is_this_key_included?(
|
305
|
+
key = first_argument?
|
306
|
+
)
|
307
|
+
key = key.to_s unless key.is_a?(String)
|
308
|
+
dataset?.has_key?(key)
|
309
|
+
end; alias included? is_this_key_included? # === included?
|
310
|
+
alias is_included? is_this_key_included? # === is_included?
|
311
|
+
alias is_this_input_a_cd_alias? is_this_key_included? # === is_this_input_a_cd_alias?
|
312
|
+
alias is_this_key_registered? is_this_key_included? # === is_this_key_registered?
|
313
|
+
alias is_this_alias_included? is_this_key_included? # === is_this_alias_included?
|
314
|
+
alias has_key? is_this_key_included? # === has_key?
|
315
|
+
|
316
|
+
# ========================================================================= #
|
317
|
+
# === file?
|
318
|
+
#
|
319
|
+
# Delegate to the main yaml file in use.
|
320
|
+
# ========================================================================= #
|
321
|
+
def file?
|
322
|
+
::Rcfiles::DirectoryAliases.yaml_file?
|
323
|
+
end
|
324
|
+
|
325
|
+
# ========================================================================= #
|
326
|
+
# === test
|
327
|
+
# ========================================================================= #
|
328
|
+
def test(
|
329
|
+
i = seek_this_key?
|
330
|
+
)
|
331
|
+
verbose_points_to?(i)
|
332
|
+
end
|
333
|
+
|
334
|
+
# ========================================================================= #
|
335
|
+
# === show_exceptions?
|
336
|
+
# ========================================================================= #
|
337
|
+
def show_exceptions?
|
338
|
+
SHALL_WE_SHOW_EXCEPTIONS
|
339
|
+
end
|
340
|
+
|
341
|
+
# ========================================================================= #
|
342
|
+
# === do_sanitize_the_loaded_dataset (sanitize tag)
|
343
|
+
#
|
344
|
+
# This method will sanitize the dataset at hand.
|
345
|
+
#
|
346
|
+
# All changes will be copied back onto the main hash, as-is - thus
|
347
|
+
# we lose the original data.
|
348
|
+
# ========================================================================= #
|
349
|
+
def do_sanitize_the_loaded_dataset(
|
350
|
+
hash = hash?,
|
351
|
+
# ===================================================================== #
|
352
|
+
# Use a yaml-file containing the correct variables next:
|
353
|
+
# ===================================================================== #
|
354
|
+
use_this_yaml_file = ::Rcfiles.project_base_directory?+
|
355
|
+
'yaml/global_variables/'\
|
356
|
+
'global_variables_extracted_from_the_file_cd_aliases.yml'
|
357
|
+
)
|
358
|
+
dataset_from_the_global_variables = YAML.load_file(
|
359
|
+
use_this_yaml_file
|
360
|
+
)
|
361
|
+
_ = {}
|
362
|
+
hash.each {|key, value|
|
363
|
+
# ===================================================================== #
|
364
|
+
# Next, work on all value-entries that include a '$' character. This
|
365
|
+
# will work on Linux, but on Windows this may not work, so we may
|
366
|
+
# have to use another solution for windows specifically. However
|
367
|
+
# had, we actually do not need to use ConvertGlobalEnv here,
|
368
|
+
# as the autogenerated .yml file already contains the sanitized
|
369
|
+
# dataset. The line has been commented out in May 2022.
|
370
|
+
#
|
371
|
+
# Examples for a key and value pair may be the following:
|
372
|
+
#
|
373
|
+
# 'to_valheru' => 'cd $VALHERU'
|
374
|
+
# 'pwdshell' => 'cd $LINUX/SHELL/
|
375
|
+
#
|
376
|
+
# We need to map it towards e. g.:
|
377
|
+
#
|
378
|
+
# ROEBE_SRC: '/home/x/programming/ruby/src/roebe/lib/roebe'
|
379
|
+
# LINUX: '/home/x/programming/ruby/src/roebe/lib/roebe/www/linux'
|
380
|
+
# UNI_WIEN: '/home/x/studium/UNI_WIEN'
|
381
|
+
#
|
382
|
+
# ===================================================================== #
|
383
|
+
if value.include? '$'
|
384
|
+
value = value.dup # Work on a copy past this point.
|
385
|
+
value.gsub!(/cd /,'') if value.include? 'cd '
|
386
|
+
value.gsub!(/ ll/,'') if value.include? ' ll'
|
387
|
+
value.gsub!(/ ls/,'') if value.include? ' ls'
|
388
|
+
value.gsub!(/> \/dev\/null/,'') if value.include? '> /dev/null'
|
389
|
+
value.gsub!(/2>&1/,'') if value.include? '2>&1'
|
390
|
+
# =================================================================== #
|
391
|
+
# The next line has been commented out on 03.05.2022:
|
392
|
+
#
|
393
|
+
# value = ConvertGlobalEnv.convert(value, report_errors?)
|
394
|
+
#
|
395
|
+
# =================================================================== #
|
396
|
+
shortened_value = value.delete_prefix('cd ').dup # Now it is e. g. '$LINUX/SHELL/'.
|
397
|
+
# =================================================================== #
|
398
|
+
# In the past, until May 2014, we chopped off trailing occurences
|
399
|
+
# of 'pwd', but I decided that this is no longer wanted. Certain
|
400
|
+
# aliases such as "pwdusb4" would misfunction as a result of
|
401
|
+
# the following .gsub:
|
402
|
+
#
|
403
|
+
# value.gsub!(/pwd$/,'') if value.include? 'pwd'
|
404
|
+
#
|
405
|
+
# =================================================================== #
|
406
|
+
# =================================================================== #
|
407
|
+
# As of May 2014, we no longer get rid of ; characters.
|
408
|
+
#
|
409
|
+
# value.gsub!(/;/,'') if value.include? ';'
|
410
|
+
#
|
411
|
+
# =================================================================== #
|
412
|
+
if value and value.include?('/') # In this case it is more complicated.
|
413
|
+
shortened_value = value.scan(/\$(\w+)\//).flatten.first.to_s # See: https://rubular.com/r/L2rAbtKVnnmBfd
|
414
|
+
value.sub!(/\$#{shortened_value}/, dataset_from_the_global_variables[shortened_value].to_s)
|
415
|
+
else # else no modification is necessary.
|
416
|
+
replace_via = dataset_from_the_global_variables[shortened_value.delete('$')].to_s
|
417
|
+
value.gsub!(/#{Regexp.quote(value)}/, replace_via)
|
418
|
+
end
|
419
|
+
end
|
420
|
+
if hash.has_key?(value)
|
421
|
+
value = hash[value]
|
422
|
+
end
|
423
|
+
value = rds(value) if value.include? '//'
|
424
|
+
_[key] = value.strip # We don't need trailing empty characters.
|
425
|
+
}
|
426
|
+
@internal_hash[:dataset] = _
|
427
|
+
end; alias sanitize_hash do_sanitize_the_loaded_dataset # === sanitize_hash
|
428
|
+
alias sanitize_the_hash do_sanitize_the_loaded_dataset # === sanitize_the_hash
|
429
|
+
alias sanitize_cd_aliases do_sanitize_the_loaded_dataset # === sanitize_cd_aliases
|
430
|
+
|
431
|
+
# ========================================================================= #
|
432
|
+
# === report_to_user
|
433
|
+
#
|
434
|
+
# This is a "poor man's" debug variant.
|
435
|
+
# ========================================================================= #
|
436
|
+
def report_to_user
|
437
|
+
pp hash?
|
438
|
+
end
|
439
|
+
|
440
|
+
# ========================================================================= #
|
441
|
+
# === load_the_dataset_from_the_file_cd_aliases
|
442
|
+
#
|
443
|
+
# An alternative argument to this method would be
|
444
|
+
# ::Rcfiles.file_cd_aliases?.
|
445
|
+
# ========================================================================= #
|
446
|
+
def load_the_dataset_from_the_file_cd_aliases(
|
447
|
+
file_cd_aliases =
|
448
|
+
::Rcfiles::DirectoryAliases.yaml_file?
|
449
|
+
)
|
450
|
+
if File.exist? file_cd_aliases
|
451
|
+
@internal_hash[:dataset] =
|
452
|
+
YAML.load_file(file_cd_aliases)
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
# ========================================================================= #
|
457
|
+
# === replacement_or_original_input?
|
458
|
+
# ========================================================================= #
|
459
|
+
def replacement_or_original_input?(
|
460
|
+
_ = first_argument?
|
461
|
+
)
|
462
|
+
if is_this_key_included?(_)
|
463
|
+
translate_key_into_value(_)
|
464
|
+
else
|
465
|
+
return _
|
466
|
+
end
|
467
|
+
end; alias corresponds_to replacement_or_original_input? # === corresponds_to
|
468
|
+
alias corresponds_to? replacement_or_original_input? # === corresponds_to?
|
469
|
+
alias find_this_cd_alias replacement_or_original_input? # === find_this_cd_alias
|
470
|
+
alias find_this_sanitized_cd_alias replacement_or_original_input? # === find_this_sanitized_cd_alias
|
471
|
+
alias find replacement_or_original_input? # === find
|
472
|
+
alias points_at replacement_or_original_input? # === points_at
|
473
|
+
alias points_at? replacement_or_original_input? # === points_at?
|
474
|
+
alias result? replacement_or_original_input? # === result?
|
475
|
+
alias convert replacement_or_original_input? # === convert
|
476
|
+
alias _ replacement_or_original_input? # === _
|
477
|
+
|
478
|
+
# ========================================================================= #
|
479
|
+
# === n_entries?
|
480
|
+
# ========================================================================= #
|
481
|
+
def n_entries?
|
482
|
+
dataset?.size
|
483
|
+
end
|
484
|
+
|
485
|
+
# ========================================================================= #
|
486
|
+
# === verbose_points_to?
|
487
|
+
# ========================================================================= #
|
488
|
+
def verbose_points_to?(i = seek_which_key?)
|
489
|
+
i = i.to_s
|
490
|
+
if is_included? i
|
491
|
+
opnn; e "#{::Rcfiles.rev}Yes, the key `#{::Rcfiles.sfancy(i)}` is included."
|
492
|
+
opnn; e "#{::Rcfiles.rev}It points to the directory: #{::Rcfiles.sdir(hash?[i])}"
|
493
|
+
else
|
494
|
+
opnn; e "#{::Rcfiles.rev}No, the key `#{::Rcfiles.sfancy(i)}` is not "\
|
495
|
+
"included in the cd-aliases."
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
# ========================================================================= #
|
500
|
+
# === run (run tag)
|
501
|
+
# ========================================================================= #
|
502
|
+
def run
|
503
|
+
# ======================================================================= #
|
504
|
+
# We will do several clean-ups. This is extremely hackish, but also
|
505
|
+
# very simple and it kind of works. We got rid of all the $ values.
|
506
|
+
# How often to call it? Well, it seems 4x is more than enough;
|
507
|
+
# perhaps we can reduce it even more, but for now this is the way
|
508
|
+
# it is.
|
509
|
+
# ======================================================================= #
|
510
|
+
do_sanitize_the_loaded_dataset
|
511
|
+
do_sanitize_the_loaded_dataset
|
512
|
+
do_sanitize_the_loaded_dataset
|
513
|
+
do_sanitize_the_loaded_dataset
|
514
|
+
# do_sanitize_the_loaded_dataset
|
515
|
+
end
|
516
|
+
|
517
|
+
# ========================================================================= #
|
518
|
+
# === []
|
519
|
+
# ========================================================================= #
|
520
|
+
def [](i)
|
521
|
+
replacement_or_original_input?(i)
|
522
|
+
end
|
523
|
+
|
524
|
+
# ========================================================================= #
|
525
|
+
# === Rcfiles::DirectoryAliases.is_included?
|
526
|
+
#
|
527
|
+
# Note that this instantiates a new DirectoryAliases object, so it
|
528
|
+
# is more expensive than instantiating on your own and then simply
|
529
|
+
# using .is_included? on that object. The reason why this method
|
530
|
+
# still exists, then, is mostly because it is convenient to NOT
|
531
|
+
# have to instantiate something specifically, as that normally
|
532
|
+
# takes two lines of code.
|
533
|
+
# ========================================================================= #
|
534
|
+
def self.is_included?(i)
|
535
|
+
_ = new(i)
|
536
|
+
return _.is_included?(i)
|
537
|
+
end; self.instance_eval { alias does_include? is_included? } # === Rcfiles::DirectoryAliases.does_include?
|
538
|
+
self.instance_eval { alias is_this_alias_included? is_included? } # === Rcfiles::DirectoryAliases.is_this_alias_included?
|
539
|
+
self.instance_eval { alias is_this_input_a_cd_alias? is_included? } # === Rcfiles::DirectoryAliases.is_this_input_a_cd_alias?
|
540
|
+
# Rcfiles::DirectoryAliases.include? # ← This here would conflict, hence we can not use it.
|
541
|
+
|
542
|
+
# ========================================================================= #
|
543
|
+
# === Rcfiles::DirectoryAliases.points_at?
|
544
|
+
# ========================================================================= #
|
545
|
+
def self.points_at?(i)
|
546
|
+
_ = new(i)
|
547
|
+
return _.points_at?
|
548
|
+
end
|
549
|
+
|
550
|
+
# ========================================================================= #
|
551
|
+
# === Rcfiles::DirectoryAliases.e
|
552
|
+
# ========================================================================= #
|
553
|
+
def self.e(i = '')
|
554
|
+
::Rcfiles.e(i)
|
555
|
+
end
|
556
|
+
|
557
|
+
# ========================================================================= #
|
558
|
+
# === Rcfiles::DirectoryAliases[]
|
559
|
+
#
|
560
|
+
# This must return a String - either the original input, or the
|
561
|
+
# replacement.
|
562
|
+
#
|
563
|
+
# Usage example:
|
564
|
+
#
|
565
|
+
# Rcfiles::DirectoryAliases['pwdj'] # => '/Depot/j/'
|
566
|
+
#
|
567
|
+
# ========================================================================= #
|
568
|
+
def self.[](i = '')
|
569
|
+
new(i).replacement_or_original_input?
|
570
|
+
end
|
571
|
+
|
572
|
+
end
|
573
|
+
|
574
|
+
# ========================================================================= #
|
575
|
+
# === Rcfiles.is_this_alias_included?
|
576
|
+
#
|
577
|
+
# This method can be used to determine whether a given key is included
|
578
|
+
# or not.
|
579
|
+
#
|
580
|
+
# Usage example:
|
581
|
+
#
|
582
|
+
# Rcfiles.is_this_alias_included? 'pwdsongs'
|
583
|
+
#
|
584
|
+
# ========================================================================= #
|
585
|
+
def self.is_this_alias_included?(i)
|
586
|
+
::Rcfiles::DirectoryAliases.is_this_alias_included?(i)
|
587
|
+
end; self.instance_eval { alias is_this_input_a_cd_alias? is_this_alias_included? } # === Rcfiles.is_this_input_a_cd_alias?
|
588
|
+
self.instance_eval { alias is_this_key_available? is_this_alias_included? } # === Rcfiles.is_this_key_available?
|
589
|
+
self.instance_eval { alias is_this_key_registered? is_this_alias_included? } # === Rcfiles.is_this_key_registered?
|
590
|
+
|
591
|
+
# =========================================================================== #
|
592
|
+
# === Rcfiles.directory_aliases
|
593
|
+
#
|
594
|
+
# This method will instantiate a new DirectoryAliases object.
|
595
|
+
# =========================================================================== #
|
596
|
+
def self.directory_aliases(i)
|
597
|
+
::Rcfiles::DirectoryAliases.new(i)
|
598
|
+
end; self.instance_eval { alias cd_alias directory_aliases } # === Rcfiles.cd_alias
|
599
|
+
self.instance_eval { alias expand_cd_aliases directory_aliases } # === Rcfiles.expand_cd_aliases
|
600
|
+
|
601
|
+
# =========================================================================== #
|
602
|
+
# === Rcfiles.find_this_cd_alias
|
603
|
+
#
|
604
|
+
# Usage example for this method:
|
605
|
+
#
|
606
|
+
# Rcfiles.find_this_cd_alias('pwdj') # => "cd /Depot/j"
|
607
|
+
#
|
608
|
+
# =========================================================================== #
|
609
|
+
def self.find_this_cd_alias(i)
|
610
|
+
::Rcfiles::DirectoryAliases[i]
|
611
|
+
end
|
612
|
+
|
613
|
+
end
|
614
|
+
|
615
|
+
if __FILE__ == $PROGRAM_NAME # Testing class Rcfiles::DirectoryAliases here.
|
616
|
+
alias e puts
|
617
|
+
require 'colours'
|
618
|
+
directory_aliases = Rcfiles::DirectoryAliases.new(ARGV)
|
619
|
+
print ::Colours.rev
|
620
|
+
e '='*80
|
621
|
+
e 'The version of the rcfiles gem in use is: '+directory_aliases.version?.to_s
|
622
|
+
e directory_aliases.n_entries?.to_s+
|
623
|
+
' keys are registered as being cd-aliases.'
|
624
|
+
e 'Is the key `tova` included: '+directory_aliases.is_this_key_included?('tova').to_s
|
625
|
+
e 'It corresponds to: '+directory_aliases.corresponds_to('tova')
|
626
|
+
e 'Is the key `tovaa` included: '+directory_aliases.is_this_key_included?('tovaa').to_s
|
627
|
+
e 'Is the key `pwdsongs` included: '+directory_aliases.is_this_key_included?('pwdsongs').to_s
|
628
|
+
e 'It corresponds to: '+directory_aliases.corresponds_to('pwdsongs')
|
629
|
+
# e 'The expanded value is: '+
|
630
|
+
# directory_aliases.expanded_key?('pwdsongs')
|
631
|
+
e 'Is the key `tosongs` included: '+directory_aliases.is_this_key_included?('tosongs').to_s
|
632
|
+
e 'It corresponds to: '+directory_aliases.corresponds_to('tosongs')
|
633
|
+
# e 'The expanded value is: '+
|
634
|
+
# directory_aliases.expanded_key?('tosongs')
|
635
|
+
e 'Next testing Rcfiles.is_this_alias_included?(): is
|
636
|
+
"pwdsongs" included? '+
|
637
|
+
Rcfiles.is_this_alias_included?('pwdsongs').to_s
|
638
|
+
e 'Next testing Rcfiles.find_this_cd_alias() - pwdj equals '\
|
639
|
+
' '+Rcfiles.find_this_cd_alias('pwdj') # => "cd /Depot/j" # => "cd /Depot/j"
|
640
|
+
e '='*80
|
641
|
+
directory_aliases.test('toxx')
|
642
|
+
e '='*80
|
643
|
+
directory_aliases._.class
|
644
|
+
end # directoryaliases
|
645
|
+
# ecdaliases
|
646
|
+
# exda pwwdusr; exda pwddwwd
|
647
|
+
# exda pwdusb4
|