Module: Rcfiles
- Defined in:
- lib/rcfiles/class/run.rb,
lib/rcfiles/help/help.rb,
lib/rcfiles/class/misc.rb,
lib/rcfiles/class/reset.rb,
lib/rcfiles/class/colours.rb,
lib/rcfiles/files/file_ps1.rb,
lib/rcfiles/colours/colours.rb,
lib/rcfiles/project/project.rb,
lib/rcfiles/version/version.rb,
lib/rcfiles/class/initialize.rb,
lib/rcfiles/files/file_aliases.rb,
lib/rcfiles/toplevel_methods/e.rb,
lib/rcfiles/constants/constants.rb,
lib/rcfiles/files/file_pkgconfig.rb,
lib/rcfiles/toplevel_methods/rds.rb,
lib/rcfiles/files/file_cd_aliases.rb,
lib/rcfiles/files/file_ls_colours.rb,
lib/rcfiles/toplevel_methods/misc.rb,
lib/rcfiles/toplevel_methods/infer.rb,
lib/rcfiles/commandline/commandline.rb,
lib/rcfiles/toplevel_methods/report.rb,
lib/rcfiles/toplevel_methods/run_it.rb,
lib/rcfiles/files/file_path_variable.rb,
lib/rcfiles/toplevel_methods/convert.rb,
lib/rcfiles/toplevel_methods/esystem.rb,
lib/rcfiles/files/file_system_settings.rb,
lib/rcfiles/toplevel_methods/save_file.rb,
lib/rcfiles/toplevel_methods/verbosity.rb,
lib/rcfiles/files/file_programs_aliases.rb,
lib/rcfiles/toplevel_methods/use_quotes.rb,
lib/rcfiles/toplevel_methods/is_on_roebe.rb,
lib/rcfiles/toplevel_methods/notifications.rb,
lib/rcfiles/toplevel_methods/main_directory.rb,
lib/rcfiles/toplevel_methods/remove_newlines.rb,
lib/rcfiles/toplevel_methods/change_directory.rb,
lib/rcfiles/toplevel_methods/no_file_exists_at.rb,
lib/rcfiles/toplevel_methods/use_psych_or_syck.rb,
lib/rcfiles/directory_aliases/directory_aliases.rb,
lib/rcfiles/toplevel_methods/generate_yaml_files.rb,
lib/rcfiles/toplevel_methods/return_standard_header.rb,
lib/rcfiles/aggregate_all_rcfiles/aggregate_all_rcfiles.rb,
lib/rcfiles/toplevel_methods/n_registered_aliases_in_total.rb,
lib/rcfiles/toplevel_methods/create_windows_cd_aliases_bat_file.rb,
lib/rcfiles/toplevel_methods/autogenerate_rc_file_from_this_yaml_file.rb,
lib/rcfiles/toplevel_methods/convert_global_variables_in_the_cd_aliases_file_to_a_standalone_yaml_file.rb
Overview
#
require ‘rcfiles/toplevel_methods/convert_global_variables_in_the_cd_aliases_file_to_a_standalone_yaml_file.rb’
#
Defined Under Namespace
Classes: AggregateAllRcfiles, DirectoryAliases, Rcfiles
Constant Summary collapse
- VERSION =
#
VERSION
#
'1.3.54'
- LAST_UPDATE =
#
LAST_UPDATE
#
'16.04.2024'
- NAMESPACE =
#
NAMESPACE
#
inspect
- HASH_CUSTOM_FILES =
#
HASH_CUSTOM_FILES
The following Hash has two important entries:
(1) The file path where the file exists locally (2) How to generate the rc-file at hand, e. g. if it is a file with aliases (then the key :aliases should be used), or whether it is a file that makes use of export-statements (then :export should be used as second value).
Do note that the first entry, aka file path, does not necessarily have to be the full path per se. Code has been added to allow me to just give the name, and let ruby search for the local file at hand instead.
#
{ # ======================================================================= # # Not sure if roeberia should be included. Guess it would have to # be changed before it can be included, so it was removed on 10.04.2019 # 'roeberia_settings.yml' => :export, # ======================================================================= # # 'special_aliases.yml' => :aliases, # ^^^ this was merged back on 04.07.2021 so it is no longer needed here. # 'german_umlaute.yml' => :aliases, # ^^^ this was merged back on 24.06.2021 because now unicode works # properly. # 'colours.yml' => :aliases, # ^^^ colours.yml is dysfunct since 2018 or so - I am not sure if # it will make a comeback. Roebe.project_yaml_directory?+'file_information.yml' => :export, Roebe.project_yaml_directory?+'gnome/gnome.yml' => :export, Roebe.project_yaml_directory?+'kde/kde.yml' => :export, Roebe.project_yaml_directory?+'kernel/kernel.yml' => :export, Roebe.project_yaml_directory?+'system/system.yml' => :export, Roebe.project_yaml_directory?+'compile/compile.yml' => :export, '/home/x/data/personal/yaml/network/network.yml' => :export, '/home/x/programming/ruby/src/multimedia_paradise/lib/multimedia_paradise/yaml/video/video.yml' => :export, # ======================================================================= # # Next, entries under individual_environment_variables/ # ======================================================================= # Roebe.project_yaml_directory?+'individual_environment_variables/ldflags.yml' => :export, Roebe.project_yaml_directory?+'individual_environment_variables/cflags.yml' => :export, Roebe.project_yaml_directory?+'individual_environment_variables/lang.yml' => :export, Roebe.project_yaml_directory?+'individual_environment_variables/term.yml' => :export }
- N =
#
N
#
"\n"
- HOME_DIR =
#
HOME_DIR
#
'/home/'
- DIRECTORY_CONTAINING_THE_RC_FILES_ON_MY_HOME_SYSTEM =
#
DIRECTORY_CONTAINING_THE_RC_FILES_ON_MY_HOME_SYSTEM
This constant is obviously not so useful for other people - it is for my home system only. The target is, in that case, hardcoded.
#
"#{HOME_DIR}x/DATA/PC/OS/LINUX/yaml/"
- LINUX_YAML_BASE_DIRECTORY =
DIRECTORY_CONTAINING_THE_RC_FILES_ON_MY_HOME_SYSTEM
- FILE_STORE_INTO_THIS_DIRECTORY =
#
Rcfiles::FILE_STORE_INTO_THIS_DIRECTORY
#
"#{project_yaml_dir?}store_into_this_directory.yml"
- CREATE_RCFILES_WHERE =
#
This one is just a rescued-variant defaulting to the home directory as base-directory.
#
File.('~/AUTOGENERATED/')
- RUBY_SRC_DIR_AT_HOME =
#
RUBY_SRC_DIR_AT_HOME
#
"#{HOME_DIR}x/programming/ruby/src/"
- UTF_ENCODING =
#
UTF_ENCODING
#
'utf-8'
- UTF8_ENCODING =
UTF8_ENCODING
UTF_ENCODING
- ISO_ENCODING =
#
ISO_ENCODING
#
'ISO-8859-1'
- ENCODING_ISO =
ENCODING_ISO
ISO_ENCODING
- MAIN_ENCODING_TO_USE =
#
MAIN_ENCODING_TO_USE
This constant is very important - it denotes which is the main encoding for the rcfiles-project.
#
UTF_ENCODING
- USE_THIS_ENCODING =
MAIN_ENCODING_TO_USE
UTF_ENCODING
- FILE_ROEBERIA_SETTINGS =
#
FILE_ROEBERIA_SETTINGS
The next constant is only useful on my home setup:
#
"/home/x/data/personal/yaml/roeberia_settings.yml"
- ARRAY_MAIN_ALIASES_FILE =
#
Rcfiles::ARRAY_MAIN_ALIASES_FILE
#
[ file_cd_aliases?, file_aliases?, file_programs_aliases?, file_system_settings? ]
Class Method Summary collapse
-
.aliases? ⇒ Boolean
# === Rcfiles.aliases?.
-
.autogenerate_rc_file_from_this_yaml_file(this_yaml_file = 1, be_verbose = true) ⇒ Object
# === Rcfiles.autogenerate_rc_file_from_this_yaml_file.
-
.be_verbose? ⇒ Boolean
# === Rcfiles.be_verbose? ========================================================================= #.
-
.change_directory(i) ⇒ Object
# === Rcfiles.change_directory ========================================================================= #.
-
.convert_global_variables_in_the_cd_aliases_file_to_a_standalone_yaml_file(use_this_as_the_input_file = '/home/x/programming/ruby/src/rcfiles/lib/rcfiles/yaml/cd_aliases.yml') ⇒ Object
# === Rcfiles.convert_global_variables_in_the_cd_aliases_file_to_a_standalone_yaml_file.
-
.convert_this_array_to_export_file(array, optional_second_input_as_name_of_the_export_variable = 'PKG_CONFIG_PATH') ⇒ Object
# === Rcfiles.convert_this_array_to_export_file.
-
.convert_this_hash_to_alias_file(hash) ⇒ Object
# === Rcfiles.convert_this_hash_to_alias_file.
-
.convert_this_hash_to_export_file(hash, ensure_proper_encoding = false) ⇒ Object
# === Rcfiles.convert_this_hash_to_export_file.
-
.convert_this_input_to_export_file(i, optional_second_input_as_name_of_the_export_variable = nil) ⇒ Object
# === Rcfiles.convert_this_input_to_export_file ========================================================================= #.
-
.copy_rcfiles_to_the_current_directory ⇒ Object
# === Rcfiles.copy_rcfiles_to_the_current_directory.
-
.create_windows_cd_aliases_bat_file ⇒ Object
# === Rcfiles.create_windows_cd_aliases_bat_file ========================================================================= #.
-
.directory_aliases(i) ⇒ Object
# === Rcfiles.directory_aliases.
-
.disable_colours ⇒ Object
# === Rcfiles.disable_colours ========================================================================= #.
-
.disable_quotes ⇒ Object
# === Rcfiles.disable_quotes ========================================================================= #.
-
.disable_quotes_then_generate_the_files ⇒ Object
# === Rcfiles.disable_quotes_then_generate_the_files ========================================================================= #.
-
.do_use_custom_rcfiles_home_directory_as_target ⇒ Object
# === Rcfiles.do_use_custom_rcfiles_home_directory_as_target.
-
.do_use_syck ⇒ Object
# === Rcfiles.do_use_syck ========================================================================= #.
-
.e(i = '') ⇒ Object
# === Rcfiles.e ========================================================================= #.
-
.enable_colours ⇒ Object
# === Rcfiles.enable_colours ========================================================================= #.
-
.ensure_main_encoding(i, use_this_encoding = @use_this_encoding) ⇒ Object
# === Rcfiles.ensure_main_encoding.
-
.esystem(i) ⇒ Object
# === Rcfiles.esystem ========================================================================= #.
-
.file_aliases? ⇒ Boolean
# === Rcfiles.file_aliases? ========================================================================= #.
-
.file_cd_aliases? ⇒ Boolean
# === Rcfiles.file_cd_aliases?.
-
.file_global_variables ⇒ Object
# === Rcfiles.file_global_variables.
-
.file_ls_colours? ⇒ Boolean
# === Rcfiles.file_ls_colours? ========================================================================= #.
-
.file_path_variable? ⇒ Boolean
# === Rcfiles.file_path_variable? ========================================================================= #.
-
.file_pkgconfig? ⇒ Boolean
# === Rcfiles.file_pkgconfig? ========================================================================= #.
-
.file_programs_aliases? ⇒ Boolean
# === Rcfiles.file_programs_aliases? ========================================================================= #.
-
.file_ps1? ⇒ Boolean
# === Rcfiles.file_ps1? ========================================================================= #.
-
.file_system_settings? ⇒ Boolean
# === Rcfiles.file_system_settings? ========================================================================= #.
-
.find_this_cd_alias(i) ⇒ Object
# === Rcfiles.find_this_cd_alias.
-
.generate_aliases_rcfile ⇒ Object
# === Rcfiles.generate_aliases_rcfile ========================================================================= #.
-
.generate_cd_aliases_rcfile(be_verbose = ::Rcfiles.be_verbose?) ⇒ Object
# === Rcfiles.generate_cd_aliases_rcfile ========================================================================= #.
-
.generate_custom_roebe_rcfiles(hash = HASH_CUSTOM_FILES, be_verbose = ::Rcfiles.be_verbose?) ⇒ Object
# === Rcfiles.generate_custom_roebe_rcfiles.
-
.generate_ls_colours_rcfile ⇒ Object
# === Rcfiles.generate_ls_colours_rcfile ========================================================================= #.
-
.generate_path_variable_rcfile ⇒ Object
# === Rcfiles.generate_path_variable_rcfile ========================================================================= #.
-
.generate_pkgconfig_rcfile ⇒ Object
# === Rcfiles.generate_pkgconfig_rcfile ========================================================================= #.
-
.generate_programs_aliases_rcfile ⇒ Object
# === Rcfiles.generate_programs_aliases_rcfile ========================================================================= #.
-
.generate_ps1_rcfile ⇒ Object
# === Rcfiles.generate_ps1_rcfile ========================================================================= #.
-
.generate_system_settings_rcfile ⇒ Object
# === Rcfiles.generate_system_settings_rcfile ========================================================================= #.
-
.generate_the_main_rcfiles_without_the_custom_roebe_rcfiles ⇒ Object
# === generate_the_main_rcfiles_without_the_custom_roebe_rcfiles ========================================================================= #.
-
.generate_the_most_important_rcfiles(generate_which_files = :all, &block) ⇒ Object
# === Rcfiles.generate_the_most_important_rcfiles.
-
.generate_yaml_files(use_this_encoding = :utf8) ⇒ Object
# === Rcfiles.generate_yaml_files.
-
.infer(i = 'programs_aliases') ⇒ Object
# === Rcfiles.infer.
-
.install_the_rcfiles_project ⇒ Object
# === Rcfiles.install_the_rcfiles_project.
-
.is_on_roebe? ⇒ Boolean
# === Rcfiles.is_on_roebe? ========================================================================= #.
-
.is_this_alias_included?(i) ⇒ Boolean
# === Rcfiles.is_this_alias_included?.
-
.lightgreen(i = '') ⇒ Object
# === Rcfiles.lightgreen ========================================================================= #.
-
.main_directory?(i = FILE_STORE_INTO_THIS_DIRECTORY) ⇒ Boolean
# === Rcfiles.main_directory?.
-
.n_registered_aliases_in_total? ⇒ Boolean
# === Rcfiles.n_registered_aliases_in_total?.
-
.no_file_exists_at(i) ⇒ Object
# === Rcfiles.no_file_exists_at ========================================================================= #.
-
.notify_the_user_that_this_file_will_be_generated_from_that_existing_file(this_file, that_existing_file) ⇒ Object
# === Rcfiles.notify_the_user_that_this_file_will_be_generated_from_that_existing_file.
-
.parse_commandline(i = ARGV) ⇒ Object
# === Rcfiles.parse_commandline ========================================================================= #.
-
.populate_this_directory(i) ⇒ Object
# === Rcfiles.populate_this_directory ========================================================================= #.
-
.project_base_dir? ⇒ Boolean
# === Rcfiles.project_base_dir? ========================================================================= #.
-
.project_yaml_dir? ⇒ Boolean
# === Rcfiles.project_yaml_dir? ========================================================================= #.
-
.rds(i) ⇒ Object
# === Rcfiles.rds ========================================================================= #.
-
.remove_newlines(i, ensure_this_encoding = nil) ⇒ Object
# === Rcfiles.remove_newlines.
-
.report ⇒ Object
# === Rcfiles.report.
-
.return_standard_header(which_file = '', current_date = Time.now.strftime('%d.%m.%Y')) ⇒ Object
# === Rcfiles.return_standard_header.
-
.rev(use_colours = @use_colours) ⇒ Object
# === Rcfiles.rev ========================================================================= #.
-
.run_default_action(also_install_the_rcfiles_project = is_on_roebe? ) ⇒ Object
# === Rcfiles.run_default_action.
-
.run_it(optional_arguments = ARGV) ⇒ Object
# === Rcfiles.run_it ========================================================================= #.
-
.sdir(i = '', use_colours = @use_colours) ⇒ Object
# === Rcfiles.sdir ========================================================================= #.
-
.set_be_verbose(i) ⇒ Object
# === Rcfiles.set_be_verbose ========================================================================= #.
-
.set_cd_aliases(i = :default) ⇒ Object
# === Rcfiles.set_cd_aliases ========================================================================= #.
-
.set_file_aliases(i = :default) ⇒ Object
# === Rcfiles.set_file_aliases ========================================================================= #.
-
.set_file_ls_colours(i = :default) ⇒ Object
# === Rcfiles.set_file_ls_colours ========================================================================= #.
-
.set_file_path_variable(i = :default) ⇒ Object
# === Rcfiles.set_file_path_variable ========================================================================= #.
-
.set_file_pkgconfig(i = :default) ⇒ Object
# === Rcfiles.set_file_pkgconfig ========================================================================= #.
-
.set_file_ps1(i = :default) ⇒ Object
# === Rcfiles.set_file_ps1 ========================================================================= #.
-
.set_programs_aliases(i = :default) ⇒ Object
# === Rcfiles.set_programs_aliases ========================================================================= #.
-
.set_project_base_directory(i = :default) ⇒ Object
# === Rcfiles.set_project_base_directory ========================================================================= #.
-
.set_store_into_this_directory(i = :pwd, save_into_file = true) ⇒ Object
# === Rcfiles.set_store_into_this_directory.
-
.set_system_settings(i = :default) ⇒ Object
# === Rcfiles.set_system_settings.
-
.set_use_this_encoding(i = MAIN_ENCODING_TO_USE) ⇒ Object
# === Rcfiles.set_use_this_encoding.
-
.sfancy(i = '') ⇒ Object
# === Rcfiles.sfancy ========================================================================= #.
-
.sfile(i = '') ⇒ Object
# === Rcfiles.sfile ========================================================================= #.
-
.show_help ⇒ Object
# === Rcfiles.show_help (help tag).
-
.show_how_many_aliases_are_registered_in_this_project_in_total ⇒ Object
# === Rcfiles.show_how_many_aliases_are_registered_in_this_project_in_total.
-
.simp(i = '', use_colours = @use_colours) ⇒ Object
# === Rcfiles.simp ========================================================================= #.
-
.steelblue(i = '') ⇒ Object
# === Rcfiles.steelblue ========================================================================= #.
-
.store_at=(i) ⇒ Object
# === Rcfiles.store_at= ========================================================================= #.
-
.teal(i = '') ⇒ Object
# === Rcfiles.teal ========================================================================= #.
-
.toggle_quotes ⇒ Object
# === Rcfiles.toggle_quotes.
-
.use_colours? ⇒ Boolean
# === Rcfiles.use_colours? ========================================================================= #.
-
.use_psych_or_syck=(i = :psych) ⇒ Object
# === Rcfiles.use_psych_or_syck= ========================================================================= #.
-
.use_psych_or_syck? ⇒ Boolean
# === Rcfiles.use_psych_or_syck? ========================================================================= #.
-
.use_quotes=(i) ⇒ Object
# === Rcfiles.use_quotes= ========================================================================= #.
-
.use_quotes? ⇒ Boolean
# === Rcfiles.use_quotes? ========================================================================= #.
-
.use_this_encoding? ⇒ Boolean
# === Rcfiles.use_this_encoding? ========================================================================= #.
-
.version? ⇒ Boolean
# === Rcfiles.version? ========================================================================= #.
-
.write_what_into(what = '', into = '') ⇒ Object
# === Rcfiles.write_what_into.
Class Method Details
.aliases? ⇒ Boolean
#
Rcfiles.aliases?
This method will return all aliases, as a Hash.
#
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/rcfiles/toplevel_methods/misc.rb', line 209 def self.aliases? hash = {} _ = file_aliases? if File.exist? _ hash.merge!(YAML.load_file(_)) end _ = file_cd_aliases? if File.exist? _ hash.merge!(YAML.load_file(_)) end _ = file_programs_aliases? if File.exist? _ hash.merge!(YAML.load_file(_)) end return hash end |
.autogenerate_rc_file_from_this_yaml_file(this_yaml_file = 1, be_verbose = true) ⇒ Object
#
Rcfiles.autogenerate_rc_file_from_this_yaml_file
The first argument to this method shall denote the full path to an existing .yml file.
The second argument determines whether we will be verbose or silent. Verbose in this context means to display text to the user.
Invocation example:
Rcfiles.autogenerate_rc_file_from_this_yaml_file('/home/x/data/PROGRAMMING_LANGUAGES/RUBY/src/rcfile_generator/lib/rcfile_generator/yaml/cd_aliases.yml')
#
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rcfiles/toplevel_methods/autogenerate_rc_file_from_this_yaml_file.rb', line 41 def self.autogenerate_rc_file_from_this_yaml_file( this_yaml_file = 1, be_verbose = true ) # ======================================================================= # # Next denote the base directory to use. # ======================================================================= # base_directory_to_use = main_directory? # ======================================================================= # # Handle some common symbols next. These are assumed to be shortcuts. # Additionally we will support some numbers as well. # ======================================================================= # case this_yaml_file # case tag # ======================================================================= # # === :cd_aliases # ======================================================================= # when :cd_aliases, 1, '1' this_yaml_file = file_cd_aliases? # ======================================================================= # # === :aliases # ======================================================================= # when :aliases, 2, '2' this_yaml_file = file_aliases? # ======================================================================= # # === :program_aliases # ======================================================================= # when :program_aliases, 3, '3' this_yaml_file = file_programs_aliases? end if File.exist? this_yaml_file where = rds( base_directory_to_use+ File.basename(this_yaml_file). sub(/\.yml$/,'')+'_rc'.dup ) # ===================================================================== # # If the file exists, we can continue. We will assume that the # yaml file at hand is of export-type, that is, the variables # will be like: export FOO="bar" # ===================================================================== # if be_verbose opn; e "Next loading from the file #{sfile(this_yaml_file)}" end yaml_dataset = YAML.load_file(this_yaml_file) # store_this_data = ensure_main_encoding(''.dup) # store_this_data << ensure_main_encoding(return_standard_header(where)) store_this_data = return_standard_header(where).dup store_this_data << convert_hash_to_export_file(yaml_dataset, :ensure_proper_encoding) if be_verbose opn; e "Storing into -> `#{sfile(where)}`." end write_what_into(store_this_data.chomp, where) end end |
.be_verbose? ⇒ Boolean
#
Rcfiles.be_verbose?
#
17 18 19 |
# File 'lib/rcfiles/toplevel_methods/verbosity.rb', line 17 def self.be_verbose? @be_verbose end |
.change_directory(i) ⇒ Object
#
Rcfiles.change_directory
#
12 13 14 |
# File 'lib/rcfiles/toplevel_methods/change_directory.rb', line 12 def self.change_directory(i) Dir.chdir(i) if File.directory? i end |
.convert_global_variables_in_the_cd_aliases_file_to_a_standalone_yaml_file(use_this_as_the_input_file = '/home/x/programming/ruby/src/rcfiles/lib/rcfiles/yaml/cd_aliases.yml') ⇒ Object
#
Rcfiles.convert_global_variables_in_the_cd_aliases_file_to_a_standalone_yaml_file
This method will collect all $ global variables found in the file called “cd_aliases.yml” into a standalone .yml file. That .yml file can then be loaded by other projects.
#
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rcfiles/toplevel_methods/convert_global_variables_in_the_cd_aliases_file_to_a_standalone_yaml_file.rb', line 18 def self.convert_global_variables_in_the_cd_aliases_file_to_a_standalone_yaml_file( use_this_as_the_input_file = '/home/x/programming/ruby/src/rcfiles/lib/rcfiles/yaml/cd_aliases.yml' ) require 'yaml' require 'convert_global_env' require 'save_file' use_this_regex = /\$(\w+)/ # See: https://rubular.com/r/w75cLOvTTDfJvL _ = use_this_as_the_input_file if File.exist? _ dataset = File.read(_) scanned = dataset.scan(use_this_regex).flatten.uniq # Now we have the array. We next have to build up our main Hash. hash = {} scanned.each {|this_key| hash[this_key] = ConvertGlobalEnv['$'+this_key] } what = YAML.dump(hash) into = '/home/x/programming/ruby/src/rcfiles/lib/rcfiles/yaml/global_variables/'\ 'global_variables_extracted_from_the_file_cd_aliases.yml' e 'Storing into the file `'+into+'`.' SaveFile.write_what_into(what, into) _store_this = YAML.dump(scanned) else e "No file exists at #{_}." end end |
.convert_this_array_to_export_file(array, optional_second_input_as_name_of_the_export_variable = 'PKG_CONFIG_PATH') ⇒ Object
#
Rcfiles.convert_this_array_to_export_file
This method expects an Array as input.
Arrays are handled a bit differently, though - they will be aggregated into one input value for “export”.
#
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rcfiles/toplevel_methods/convert.rb', line 45 def self.convert_this_array_to_export_file( array, optional_second_input_as_name_of_the_export_variable = 'PKG_CONFIG_PATH' ) if array and array.is_a?(Array) _ = ''.dup # <- Our return String. joined = array.join(':').strip _ << "export #{optional_second_input_as_name_of_the_export_variable}=\"#{joined}\"#{N}" return _ else array end end |
.convert_this_hash_to_alias_file(hash) ⇒ Object
#
Rcfiles.convert_this_hash_to_alias_file
This method expects a Hash as input.
#
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rcfiles/toplevel_methods/convert.rb', line 22 def self.convert_this_hash_to_alias_file( hash ) _ = ''.dup # <- Our return String. hash.each_pair {|key, value| value = remove_newlines(value.to_s.strip) if @use_quotes _ << "alias '#{key}'=\"#{value}\"#{N}" else _ << "alias #{key}=#{value}#{N}" end } if hash return _ end |
.convert_this_hash_to_export_file(hash, ensure_proper_encoding = false) ⇒ Object
#
Rcfiles.convert_this_hash_to_export_file
This method expects a Hash as input. If you need a bit more flexibility then you are encouraged to use the other method, called Rcfiles.convert_this_input_to_export_file() instead.
#
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rcfiles/toplevel_methods/convert.rb', line 91 def self.convert_this_hash_to_export_file( hash, ensure_proper_encoding = false ) case ensure_proper_encoding when :ensure_proper_encoding ensure_proper_encoding = true end _ = ''.dup # <- Our return String. hash.each_pair {|key, value| value = value.to_s.strip if ensure_proper_encoding value = ensure_proper_encoding_for(value) key = ensure_proper_encoding_for(value) end value = value.tr("\n", ' ').squeeze(' ') _ << "export #{key}=\"#{value}\"#{N}" } if hash return _ end |
.convert_this_input_to_export_file(i, optional_second_input_as_name_of_the_export_variable = nil) ⇒ Object
#
Rcfiles.convert_this_input_to_export_file
#
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rcfiles/toplevel_methods/convert.rb', line 62 def self.convert_this_input_to_export_file( i, optional_second_input_as_name_of_the_export_variable = nil ) case i when Hash # ===================================================================== # # Hashes will ignore the optional second argument to this method, even # if it has been provided. The reason is primarily because we expect # a key -> value entry of a Hash already, so the kew is known; whereas # for an Array, we actually need the user to supply the name of the # key at hand. # ===================================================================== # convert_this_hash_to_export_file(i) when Array convert_this_array_to_export_file(i, optional_second_input_as_name_of_the_export_variable) when String convert_this_array_to_export_file([i], optional_second_input_as_name_of_the_export_variable) else e "Unregistered input-class (#{i.class})" end end |
.copy_rcfiles_to_the_current_directory ⇒ Object
#
Rcfiles.copy_rcfiles_to_the_current_directory
This method can be used to quickly copy the rc-files into a (local) directory. It is especially important when some error prevents the user from being able to autogenerate these rc-files.
#
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/rcfiles/toplevel_methods/misc.rb', line 185 def self.copy_rcfiles_to_the_current_directory target = "#{project_base_dir?}rcfiles/*rc" e "Trying to copy the rc-files from #{sdir(target)}" e 'into the current directory next:' available_files = Dir[target] available_files.each {|this_file| if File.exist?(this_file) and File.file?(this_file) and this_file.end_with?('_rc') target = ( Dir.pwd+'/'+File.basename(this_file) ).squeeze '/' e "Copying `#{sfile(this_file)}` to the current working directory next:" FileUtils.cp(this_file, target) end } end |
.create_windows_cd_aliases_bat_file ⇒ Object
#
Rcfiles.create_windows_cd_aliases_bat_file
#
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rcfiles/toplevel_methods/create_windows_cd_aliases_bat_file.rb', line 16 def self.create_windows_cd_aliases_bat_file _ = ::Rcfiles.file_cd_aliases? if File.exist? _ require 'yaml' dataset = YAML.load_file(_) _ = ''.dup begin require 'convert_global_env' rescue LoadError; end dataset.each_pair {|key, value| # =================================================================== # # value may contain a $, such as in $MAIN_WORK. # If this is the case then we will as ConvertGlobalEnv[] # to translate this for us. # =================================================================== # if value.include? '$' value = ConvertGlobalEnv[value] end _ << 'function '+key.to_s+' { set-location "'+value.to_s+'" }'+N } # ===================================================================== # # Now we can simply store this String into a file. # ===================================================================== # into = 'cd_aliases.bat' opn(namespace: NAMESPACE); e "Storing into the file #{into} next." write_what_into(_, into) else e 'No file exists at '+_+'.' end end |
.directory_aliases(i) ⇒ Object
#
Rcfiles.directory_aliases
This method will instantiate a new DirectoryAliases object.
#
813 814 815 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 813 def self.directory_aliases(i) ::Rcfiles::DirectoryAliases.new(i) end |
.disable_colours ⇒ Object
#
Rcfiles.disable_colours
#
51 52 53 |
# File 'lib/rcfiles/colours/colours.rb', line 51 def self.disable_colours @use_colours = false end |
.disable_quotes ⇒ Object
#
Rcfiles.disable_quotes
#
55 56 57 |
# File 'lib/rcfiles/toplevel_methods/use_quotes.rb', line 55 def self.disable_quotes @use_quotes = false end |
.disable_quotes_then_generate_the_files ⇒ Object
#
Rcfiles.disable_quotes_then_generate_the_files
#
62 63 64 65 66 |
# File 'lib/rcfiles/toplevel_methods/use_quotes.rb', line 62 def self.disable_quotes_then_generate_the_files disable_quotes require 'rcfiles/toplevel_methods/misc.rb' generate_files end |
.do_use_custom_rcfiles_home_directory_as_target ⇒ Object
#
Rcfiles.do_use_custom_rcfiles_home_directory_as_target
This presently uses a hardcoded path.
In the long run this method ought to become more flexible.
#
54 55 56 57 |
# File 'lib/rcfiles/toplevel_methods/misc.rb', line 54 def self.do_use_custom_rcfiles_home_directory_as_target @store_into_this_directory = RUBY_SRC_DIR_AT_HOME+'rcfiles/lib/rcfiles/rcfiles/' end |
.do_use_syck ⇒ Object
#
Rcfiles.do_use_syck
#
46 47 48 |
# File 'lib/rcfiles/toplevel_methods/use_psych_or_syck.rb', line 46 def self.do_use_syck @use_psych_or_syck = :syck end |
.e(i = '') ⇒ Object
#
Rcfiles.e
#
12 13 14 |
# File 'lib/rcfiles/toplevel_methods/e.rb', line 12 def self.e(i = '') puts i end |
.enable_colours ⇒ Object
#
Rcfiles.enable_colours
#
44 45 46 |
# File 'lib/rcfiles/colours/colours.rb', line 44 def self.enable_colours @use_colours = true end |
.ensure_main_encoding(i, use_this_encoding = @use_this_encoding) ⇒ Object
#
Rcfiles.ensure_main_encoding
The second argument to this method specifies which encoding we will use by default.
#
208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/rcfiles/constants/constants.rb', line 208 def self.ensure_main_encoding( i, use_this_encoding = @use_this_encoding ) i = i.dup if i.frozen? case use_this_encoding when :utf, :utf8 use_this_encoding = UTF8_ENCODING end i = i.dup if i.frozen? i.force_encoding(use_this_encoding) # Return this value here. end |
.esystem(i) ⇒ Object
#
Rcfiles.esystem
#
14 15 16 17 |
# File 'lib/rcfiles/toplevel_methods/esystem.rb', line 14 def self.esystem(i) e i system i end |
.file_aliases? ⇒ Boolean
#
Rcfiles.file_aliases?
#
51 52 53 |
# File 'lib/rcfiles/files/file_aliases.rb', line 51 def self.file_aliases? @file_aliases end |
.file_cd_aliases? ⇒ Boolean
#
Rcfiles.file_cd_aliases?
This method will keep the location to the cd_aliases.yml file (or the substitute for it, if the user specified another cd_aliases.yml file).
#
46 47 48 |
# File 'lib/rcfiles/files/file_cd_aliases.rb', line 46 def self.file_cd_aliases? @file_cd_aliases end |
.file_global_variables ⇒ Object
#
Rcfiles.file_global_variables
On my home system, in May 2022, this method yielded the following String:
/usr/lib/ruby/site_ruby/3.1.0/rcfiles/yaml/global_variables/global_variables_extracted_from_the_file_cd_aliases.yml
#
239 240 241 242 |
# File 'lib/rcfiles/constants/constants.rb', line 239 def self.file_global_variables "#{project_yaml_directory?}"\ "global_variables/global_variables_extracted_from_the_file_cd_aliases.yml" end |
.file_ls_colours? ⇒ Boolean
#
Rcfiles.file_ls_colours?
#
51 52 53 |
# File 'lib/rcfiles/files/file_ls_colours.rb', line 51 def self.file_ls_colours? @file_ls_colours end |
.file_path_variable? ⇒ Boolean
#
Rcfiles.file_path_variable?
#
51 52 53 |
# File 'lib/rcfiles/files/file_path_variable.rb', line 51 def self.file_path_variable? @file_path_variable end |
.file_pkgconfig? ⇒ Boolean
#
Rcfiles.file_pkgconfig?
#
46 47 48 |
# File 'lib/rcfiles/files/file_pkgconfig.rb', line 46 def self.file_pkgconfig? @file_pkgconfig end |
.file_programs_aliases? ⇒ Boolean
#
Rcfiles.file_programs_aliases?
#
41 42 43 |
# File 'lib/rcfiles/files/file_programs_aliases.rb', line 41 def self.file_programs_aliases? @file_programs_aliases end |
.file_ps1? ⇒ Boolean
#
Rcfiles.file_ps1?
#
48 49 50 |
# File 'lib/rcfiles/files/file_ps1.rb', line 48 def self.file_ps1? @file_ps1 end |
.file_system_settings? ⇒ Boolean
#
Rcfiles.file_system_settings?
#
50 51 52 |
# File 'lib/rcfiles/files/file_system_settings.rb', line 50 def self.file_system_settings? @file_system_settings end |
.find_this_cd_alias(i) ⇒ Object
827 828 829 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 827 def self.find_this_cd_alias(i) ::Rcfiles::DirectoryAliases[i] end |
.generate_aliases_rcfile ⇒ Object
#
Rcfiles.generate_aliases_rcfile
#
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rcfiles/files/file_aliases.rb', line 58 def self.generate_aliases_rcfile _ = @file_aliases if File.exist? _ into = "#{main_directory?}aliases_rc" notify_the_user_that_this_file_will_be_generated_from_that_existing_file(into, _) what = return_standard_header(into).dup hash_dataset = YAML.load_file(_) hash_dataset.each_pair {|key, value| if @use_quotes what << "alias '#{key}'=\"#{value}\"\n" else what << "alias #{key}=#{value}\n" end } write_what_into(what, into) else no_file_exists_at(_) end end |
.generate_cd_aliases_rcfile(be_verbose = ::Rcfiles.be_verbose?) ⇒ Object
#
Rcfiles.generate_cd_aliases_rcfile
#
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rcfiles/files/file_cd_aliases.rb', line 55 def self.generate_cd_aliases_rcfile( be_verbose = ::Rcfiles.be_verbose? ) _ = @file_cd_aliases if File.exist? _ if block_given? yielded = yield if yielded.has_key? :be_verbose be_verbose = yielded.delete(:be_verbose) end end into = "#{main_directory?}cd_aliases_rc" if be_verbose notify_the_user_that_this_file_will_be_generated_from_that_existing_file(into, _) end what = return_standard_header(into).dup hash_dataset = YAML.load_file(_) hash_dataset.each_pair {|key, value| if @use_quotes what << "alias '#{key}'=\"#{value}\"\n" else what << "alias #{key}=#{value}\n" end } write_what_into(what, into) else no_file_exists_at(_) if be_verbose end end |
.generate_custom_roebe_rcfiles(hash = HASH_CUSTOM_FILES, be_verbose = ::Rcfiles.be_verbose?) ⇒ Object
#
Rcfiles.generate_custom_roebe_rcfiles
The following method is mostly useful only on my home system, as there are some .yml files that are not distributed with this project, mostly because other people will not really benefit from these custom definitions, whereas they might benefit from e. g. the cd-aliases or shortcuts (aliased names) to programs, such as “gi” for “gimp” and so forth.
#
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/rcfiles/toplevel_methods/misc.rb', line 87 def self.generate_custom_roebe_rcfiles( hash = HASH_CUSTOM_FILES, be_verbose = ::Rcfiles.be_verbose? ) case be_verbose when :be_quiet, :be_silent be_verbose = false end if be_verbose opn(namespace: NAMESPACE) e "#{rev}Next generating #{teal('custom roebe rcfiles')}#{rev}:" end hash.each_pair {|path_to_the_yaml_file, type_to_use| unless File.exist? path_to_the_yaml_file # =================================================================== # # The file does not exist, but it may exist in the main directory # where these .yml files are typically stored on my home system. # =================================================================== # target = "#{LINUX_YAML_BASE_DIRECTORY}#{path_to_the_yaml_file}" if File.exist? target path_to_the_yaml_file = target end end # ===================================================================== # # Now we can begin to autogenerate the new rc-file, if the file exists: # ===================================================================== # _ = path_to_the_yaml_file if File.exist? _ require 'yaml' require 'rcfiles/toplevel_methods/convert.rb' case type_to_use # =================================================================== # # === :export # # Handle files that must use export= settings next. # =================================================================== # when :export new_dataset = convert_this_hash_to_export_file( YAML.load_file(path_to_the_yaml_file) ) # =================================================================== # # Handle files that must use alias settings next: # =================================================================== # when :aliases new_dataset = convert_this_hash_to_alias_file( YAML.load_file(path_to_the_yaml_file) ) end into = main_directory?+ File.basename(path_to_the_yaml_file).sub(/\.yml$/,'')+'_rc' new_dataset.prepend( standard_header?(into) ) write_what_into(new_dataset, into) if be_verbose opn(namespace: NAMESPACE); e "Storing into the file `#{sfile(into)}`." end else no_file_exists_at(_) if be_verbose end } return hash.keys.map {|entry| File.basename(entry).delete_suffix('.yml').to_sym } end |
.generate_ls_colours_rcfile ⇒ Object
#
Rcfiles.generate_ls_colours_rcfile
#
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rcfiles/files/file_ls_colours.rb', line 58 def self.generate_ls_colours_rcfile _ = @file_ls_colours if File.exist? _ into = "#{main_directory?}ls_colours_rc" notify_the_user_that_this_file_will_be_generated_from_that_existing_file(into, _) hash = YAML.load_file(_) dataset = hash.map {|key, value| "#{key}=#{value}"}.join(':') # ^^^ dataset is now a String past this point. what = return_standard_header(into).dup what << convert_this_input_to_export_file( dataset, 'LS_COLORS' ) write_what_into(what, into) else no_file_exists_at(_) end end |
.generate_path_variable_rcfile ⇒ Object
#
Rcfiles.generate_path_variable_rcfile
#
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rcfiles/files/file_path_variable.rb', line 58 def self.generate_path_variable_rcfile _ = @file_path_variable if File.exist? _ into = "#{main_directory?}path_variable_rc" notify_the_user_that_this_file_will_be_generated_from_that_existing_file(into, _) dataset = YAML.load_file(_) what = return_standard_header(into).dup what << convert_this_input_to_export_file( dataset, 'PATH' ) write_what_into(what, into) else no_file_exists_at(_) end end |
.generate_pkgconfig_rcfile ⇒ Object
#
Rcfiles.generate_pkgconfig_rcfile
#
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rcfiles/files/file_pkgconfig.rb', line 58 def self.generate_pkgconfig_rcfile _ = @file_pkgconfig if File.exist? _ into = "#{main_directory?}pkgconfig_rc" notify_the_user_that_this_file_will_be_generated_from_that_existing_file(into, _) dataset = YAML.load_file(_)['pkg_config_path'] what = return_standard_header(into).dup what << convert_this_input_to_export_file( dataset, 'PKG_CONFIG_PATH' ) write_what_into(what, into) else no_file_exists_at(_) end end |
.generate_programs_aliases_rcfile ⇒ Object
#
Rcfiles.generate_programs_aliases_rcfile
#
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rcfiles/files/file_programs_aliases.rb', line 48 def self.generate_programs_aliases_rcfile _ = @file_programs_aliases if File.exist? _ into = "#{main_directory?}programs_aliases_rc" notify_the_user_that_this_file_will_be_generated_from_that_existing_file(into, _) what = return_standard_header(into).dup hash_dataset = YAML.load_file(_) hash_dataset.each_pair {|key, value| if @use_quotes what << "alias '#{key}'=\"#{value}\"\n" else what << "alias #{key}=#{value}\n" end } write_what_into(what, into) else no_file_exists_at(_) end end |
.generate_ps1_rcfile ⇒ Object
#
Rcfiles.generate_ps1_rcfile
#
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rcfiles/files/file_ps1.rb', line 60 def self.generate_ps1_rcfile _ = @file_ps1 if File.exist? _ into = "#{main_directory?}ps1_rc" notify_the_user_that_this_file_will_be_generated_from_that_existing_file(into, _) dataset = YAML.load_file(_) what = return_standard_header(into).dup what << convert_this_hash_to_export_file( dataset ) write_what_into(what, into) else no_file_exists_at(_) end end |
.generate_system_settings_rcfile ⇒ Object
#
Rcfiles.generate_system_settings_rcfile
#
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rcfiles/files/file_system_settings.rb', line 59 def self.generate_system_settings_rcfile _ = @file_system_settings if File.exist? _ into = "#{main_directory?}system_settings_rc" notify_the_user_that_this_file_will_be_generated_from_that_existing_file(into, _) what = return_standard_header(into).dup hash_dataset = YAML.load_file(_) hash_dataset.each_pair {|key, value| what << "export #{key}=\"#{value}\"\n" } if hash_dataset write_what_into(what, into) else no_file_exists_at(_) end end |
.generate_the_main_rcfiles_without_the_custom_roebe_rcfiles ⇒ Object
#
generate_the_main_rcfiles_without_the_custom_roebe_rcfiles
#
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/rcfiles/toplevel_methods/misc.rb', line 156 def self.generate_the_main_rcfiles_without_the_custom_roebe_rcfiles generate_system_settings_rcfile generate_cd_aliases_rcfile generate_aliases_rcfile generate_programs_aliases_rcfile generate_pkgconfig_rcfile generate_ls_colours_rcfile generate_path_variable_rcfile generate_ps1_rcfile return [ :system_settings, :cd_aliases, :aliases, :programs_aliases, :pkgconfig, :ls_colours, :path_variable, :ps1 ] end |
.generate_the_most_important_rcfiles(generate_which_files = :all, &block) ⇒ Object
#
Rcfiles.generate_the_most_important_rcfiles
Presently, the main rc-files are:
(1) cd-aliases rcfile
(2) aliases rcfile
(3) programs aliases rcfile
(4) system settings rcfile
(5) pkgconfig rcfile
(6) ls_colours rcfile
(7) path variable rcfile
Keep in mind that the method may also be invoked in these ways:
Rcfiles.run { :disable_colours }
Rcfiles.run { :be_quiet }
#
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/rcfiles/toplevel_methods/misc.rb', line 260 def self.generate_the_most_important_rcfiles( generate_which_files = :all, &block ) be_verbose = true if block_given? yielded = yield case yielded when :be_quiet be_verbose = false ::Rcfiles.set_be_verbose(false) when :disable_colours disable_colours end end case generate_which_files # ======================================================================= # # === :all # ======================================================================= # when :all, :default array = generate_the_main_rcfiles_without_the_custom_roebe_rcfiles if is_on_roebe? # =================================================================== # # Next generate roeberia on my home system: # =================================================================== # if is_on_roebe? and File.exist?(FILE_ROEBERIA_SETTINGS) into = main_directory?+'roeberia_settings_rc' if be_verbose opn(namespace: NAMESPACE) e "#{rev}Also generating the rc-file from "\ "#{sfile(FILE_ROEBERIA_SETTINGS)} #{rev}into "\ "`#{sfile(into)}#{rev}` next." end what = convert_this_hash_to_export_file( YAML.load_file(FILE_ROEBERIA_SETTINGS) ) write_what_into(what, into) array.insert(1, :roeberia_settings) # Must be at the second position. end # =================================================================== # # The following subsection is entered only on "roebe-systems", # aka my home-systems. Other users do not really need this # subsection at all. # =================================================================== # array << generate_custom_roebe_rcfiles array.flatten! # =================================================================== # # Next create a new master.sh file. # =================================================================== # into = ::Rcfiles.main_dir?+'source_all_the_rc_files.sh' what = ''.dup array.each {|entry| what << "source "+::Rcfiles.main_dir?+"#{entry}_rc\n" } opn(namespace: NAMESPACE); e 'Storing into the file `'+sfile(into)+'`.' write_what_into(what, into) # =================================================================== # # Designate another directory as the main target directory: # =================================================================== # do_use_custom_rcfiles_home_directory_as_target generate_the_main_rcfiles_without_the_custom_roebe_rcfiles generate_custom_roebe_rcfiles @store_into_this_directory = nil end else case generate_which_files # ===================================================================== # # === :cd_aliases # ===================================================================== # when :cd_aliases generate_cd_aliases_rcfile(&block) end end end |
.generate_yaml_files(use_this_encoding = :utf8) ⇒ Object
#
Rcfiles.generate_yaml_files
The main idea behind this method is to be able to work with UTF8 encoded files.
#
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/rcfiles/toplevel_methods/generate_yaml_files.rb', line 33 def self.generate_yaml_files( use_this_encoding = :utf8 ) require 'yaml' # ======================================================================= # # === Handle the file 'cd_aliases.yml' next # ======================================================================= # _ = file_cd_aliases? if File.exist? _ string = ''.dup begin dataset_hash = YAML.load_file(_) dataset_hash.each_pair {|key, value| key = ensure_main_encoding(key.to_s, use_this_encoding) value = ensure_main_encoding(value.to_s, use_this_encoding) unless key.start_with? '"' key = "\"#{key}\"" end unless value.start_with? '"' value = "\"#{value}\"" end key = ensure_main_encoding(key.to_s, use_this_encoding) value = ensure_main_encoding(value.to_s, use_this_encoding) string << "#{key}: #{value}\n" } what = string target_file = '/Depot/'+File.basename(_) new_target_file = '/Depot/'+File.basename(_).sub(/\.#{File.extname(_)}$/,'')+'2.yml' e 'Will store into the file `'+target_file+'`.' write_what_into(what, target_file) system 'iconv -f ISO-8859-1 -t UTF-8 '+target_file+' >> '+new_target_file File.delete(target_file) FileUtils.mv(new_target_file, target_file) rescue ArgumentError => error pp error end else e 'No file could be found at `'+_+'`.' end # ======================================================================= # # === Handle the file 'aliases.yml' next # ======================================================================= # _ = file_aliases? if File.exist? _ string = ''.dup begin dataset_hash = YAML.load_file(_) dataset_hash.each_pair {|key, value| key = ensure_main_encoding(key.to_s, use_this_encoding) value = ensure_main_encoding(value.to_s, use_this_encoding) unless key.start_with? '"' key = "\"#{key}\"" end unless value.start_with? '"' value = "\"#{value}\"" end key = ensure_main_encoding(key.to_s, use_this_encoding) value = ensure_main_encoding(value.to_s, use_this_encoding) string << "#{key}: #{value}\n" } what = string target_file = "/Depot/#{File.basename(_)}" new_target_file = '/Depot/'+File.basename(_).sub(/\.#{File.extname(_)}$/,'')+'2.yml' e 'Will store into the file `'+target_file+'`.' write_what_into(what, target_file) system 'iconv -f ISO-8859-1 -t UTF-8 '+target_file+' >> '+new_target_file File.delete(target_file) FileUtils.mv(new_target_file, target_file) rescue ArgumentError => error pp error end else e 'No file could be found at `'+_+'`.' end # ======================================================================= # # === Handle the file 'programs_aliases.yml' next # ======================================================================= # _ = file_programs_aliases? if File.exist? _ string = ''.dup begin dataset_hash = YAML.load_file(_) dataset_hash.each_pair {|key, value| key = ensure_main_encoding(key.to_s, use_this_encoding) value = ensure_main_encoding(value.to_s, use_this_encoding) unless key.start_with? '"' key = "\"#{key}\"" end unless value.start_with? '"' value = "\"#{value}\"" end key = ensure_main_encoding(key.to_s, use_this_encoding) value = ensure_main_encoding(value.to_s, use_this_encoding) string << "#{key}: #{value}\n" } what = string target_file = '/Depot/'+File.basename(_) new_target_file = '/Depot/'+File.basename(_).sub(/\.#{File.extname(_)}$/,'')+'2.yml' e 'Will store into the file `'+target_file+'`.' write_what_into(what, target_file) system 'iconv -f ISO-8859-1 -t UTF-8 '+target_file+' >> '+new_target_file File.delete(target_file) FileUtils.mv(new_target_file, target_file) rescue ArgumentError => error pp error end else e "No file could be found at `#{_}`." end end |
.infer(i = 'programs_aliases') ⇒ Object
#
Rcfiles.infer
This method can be used to automatically infer, based on the input, what we may wish to do - in particular setting the path to one of the three major alias-groups of the Rcfiles project.
For example, take the following API:
Rcfiles.infer 'programs_aliases.yml'
which will be translated into the following, longer variant:
Rcfiles.set_programs_aliases(File.absolute_path('programs_aliases.yml'))
As you can see, the first variant is significantly shorter to use. The trailing ‘.yml’ part can be omitted as well, so the following is also possible:
Rcfiles.infer 'programs_aliases.yml'
Generic usage examples:
Rcfiles.infer 'aliases.yml' # => "/Depot/j/aliases.yml"
Rcfiles.infer 'cd_aliases.yml' # => "/Depot/j/cd_aliases.yml"
Rcfiles.infer 'programs_aliases.yml' # => "/Depot/j/programs_aliases.yml"
Rcfiles.infer 'system_settings.yml' # => "/Depot/j/system_settings.yml"
#
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rcfiles/toplevel_methods/infer.rb', line 44 def self.infer( i = 'programs_aliases' ) if i.is_a? String i = i.dup if i.frozen? i << '.yml' unless i.end_with? '.yml' # Append the '.yml' substring in this case. end case i # ======================================================================= # # === system_settings.yml # ======================================================================= # when /system_?settings\.yml$/ set_file_aliases( File.absolute_path(i) ) # ======================================================================= # # === aliases.yml # ======================================================================= # when /aliases\.yml$/ set_file_aliases( File.absolute_path(i) ) # ======================================================================= # # === cd_aliases.yml # ======================================================================= # when /cd_?aliases\.yml$/ set_cd_aliases( File.absolute_path(i) ) # ======================================================================= # # === programs_aliases.yml # ======================================================================= # when /programs_?aliases\.yml$/ set_programs_aliases( File.absolute_path(i) ) end end |
.install_the_rcfiles_project ⇒ Object
#
Rcfiles.install_the_rcfiles_project
This method is evidently only useful on my home system.
#
231 232 233 234 235 236 237 238 239 |
# File 'lib/rcfiles/toplevel_methods/misc.rb', line 231 def self.install_the_rcfiles_project target = ENV['USERS'].to_s.dup target = '/home' if target.nil? or target.empty? cd target+'/x/programming/ruby/src/rcfiles/' begin require 'roebe/toplevel_methods/rinstall2.rb' Roebe.rinstall2 rescue LoadError; end end |
.is_on_roebe? ⇒ Boolean
#
Rcfiles.is_on_roebe?
#
12 13 14 |
# File 'lib/rcfiles/toplevel_methods/is_on_roebe.rb', line 12 def self.is_on_roebe? ENV['IS_ROEBE'].to_s == '1' end |
.is_this_alias_included?(i) ⇒ Boolean
802 803 804 |
# File 'lib/rcfiles/directory_aliases/directory_aliases.rb', line 802 def self.is_this_alias_included?(i) ::Rcfiles::DirectoryAliases.is_this_alias_included?(i) end |
.lightgreen(i = '') ⇒ Object
#
Rcfiles.lightgreen
#
128 129 130 131 132 133 134 135 |
# File 'lib/rcfiles/colours/colours.rb', line 128 def self.lightgreen(i = '') if @use_colours and Object.const_defined?(:Colours) and Colours.respond_to?(:lightgreen) return ::Colours.lightgreen(i) else i end end |
.main_directory?(i = FILE_STORE_INTO_THIS_DIRECTORY) ⇒ Boolean
#
Rcfiles.main_directory?
This method will return e. g. “/AUTOGENERATED/”.
Note that you can modify this value, via the method stored in this file here, called Rcfiles.set_store_into_this_directory().
#
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rcfiles/toplevel_methods/main_directory.rb', line 31 def self.main_directory?( i = FILE_STORE_INTO_THIS_DIRECTORY ) # ======================================================================= # # The toplevel instance variable @store_into_this_directory will # have priority. (Ideally this should be the only way how to # query which directory is the current main one.) # ======================================================================= # if @store_into_this_directory return @store_into_this_directory elsif File.exist? i result = YAML.load_file(i) if result == false result = CREATE_RCFILES_WHERE end result = result.to_s.chomp return result else no_file_exists_at(i) end end |
.n_registered_aliases_in_total? ⇒ Boolean
#
Rcfiles.n_registered_aliases_in_total?
This method will return, as a Number, how many aliases are registered in total in this project.
We will only consider three files for the purpose of this method:
aliases.yml
cd_aliases.yml
programs_aliases.yml
#
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rcfiles/toplevel_methods/n_registered_aliases_in_total.rb', line 29 def self.n_registered_aliases_in_total? require 'yaml' # ======================================================================= # # We will store into the variable n_aliases how many entries are # registered in total. # ======================================================================= # n_aliases = 0 _ = file_aliases? if File.exist? _ n_aliases += YAML.load_file(_).keys.size # === aliases.yml end _ = file_cd_aliases? if File.exist? _ n_aliases += YAML.load_file(_).keys.size # === cd_aliases.yml end _ = file_programs_aliases? if File.exist? _ n_aliases += YAML.load_file(_).keys.size # === programs_aliases.yml end n_aliases end |
.no_file_exists_at(i) ⇒ Object
#
Rcfiles.no_file_exists_at
#
15 16 17 |
# File 'lib/rcfiles/toplevel_methods/no_file_exists_at.rb', line 15 def self.no_file_exists_at(i) e "No file exists at `#{sfile(i)}`." end |
.notify_the_user_that_this_file_will_be_generated_from_that_existing_file(this_file, that_existing_file) ⇒ Object
#
Rcfiles.notify_the_user_that_this_file_will_be_generated_from_that_existing_file
This method only notifies the user. It does not generate any file on its own.
#
27 28 29 30 31 32 33 |
# File 'lib/rcfiles/toplevel_methods/notifications.rb', line 27 def self.notify_the_user_that_this_file_will_be_generated_from_that_existing_file( this_file, that_existing_file ) opn(namespace: NAMESPACE); e "#{rev}Now generating `#{sfile(this_file)}#{rev}`, from " opn(namespace: NAMESPACE); e "#{sfile(that_existing_file)}." end |
.parse_commandline(i = ARGV) ⇒ Object
#
Rcfiles.parse_commandline
#
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/rcfiles/commandline/commandline.rb', line 31 def self.parse_commandline( i = ARGV ) if i.is_a? Array if i.empty? run_default_action elsif i.join(' ').include?('set ') i =~ /^-?-?set (.+)$/ set_store_into_this_directory($1.to_s.dup) else i.each {|entry| parse_commandline(entry)} end else case i # case tag # ===================================================================== # # === rcfiles --n_aliases? # ===================================================================== # when /^-?-?n(-|_)?aliases\??$/i, /^-?-?n(-|_)?entries\??$/i, /^-?-?stats\??$/i # === rcfiles --stats show_how_many_aliases_are_registered_in_this_project_in_total exit # ===================================================================== # # === rcfiles --sitelibdir # ===================================================================== # when /^-?-?sitelibdir$/ require 'rbconfig' e 'The sitelibdir can be found at:' e e " #{RbConfig::CONFIG['sitelibdir']}" e exit # ===================================================================== # # === rcfiles --help # ===================================================================== # when /help$/ show_help # ===================================================================== # # === rcfiles --aggregate # ===================================================================== # when /^-?-?aggregate$/ require 'rcfiles/aggregate_all_rcfiles/aggregate_all_rcfiles.rb' ::Rcfiles::AggregateAllRcfiles.new exit # ===================================================================== # # === rcfiles --windows-cd-aliases # ===================================================================== # when /^-?-?windows(-|_)?cd(-|_)?aliases$/ create_windows_cd_aliases_bat_file # ===================================================================== # # === rcfiles --set foobar # # or # # rcfiles --populate-this-dir=/Depot/Chroot/AUTOGENERATED/ # # ===================================================================== # when /^-?-?set (.+)$/, /^-?-?populate-this-dir=(.+)$/ set_store_into_this_directory($1.to_s.dup) # ===================================================================== # # === rcfiles --copy-rcfiles # === rcfiles --copy # === rcfiles --cp # ===================================================================== # when /^-?-?copy(-|_)?rcfiles$/i, /^-?-?copy$/i, /^-?-?cp$/i copy_the_rcfiles # ===================================================================== # # === rcfiles --aliases # ===================================================================== # when /^-?-?aliases$/i require 'rcfiles/files/file_aliases.rb' generate_aliases_rcfile # ===================================================================== # # === rcfiles --programs-aliases # ===================================================================== # when /^-?-?programs(_|-)?aliases$/i require 'rcfiles/files/file_programs_aliases.rb' generate_programs_aliases_rcfile # ===================================================================== # # === rcfiles --ps1 # ===================================================================== # when /^-?-?ps1$/i require 'rcfiles/files/file_ps1.rb' generate_ps1_rcfile # ===================================================================== # # === rcfiles --report # ===================================================================== # when /^-?-?report$/i ::Rcfiles.report # ===================================================================== # # === rcfiles --utf8 # ===================================================================== # when /^-?-?utf8$/ opn(namespace: 'Rcfiles') e 'Will generate Unicode-conforming (UTF8) yaml files.' set_use_this_encoding(:utf8) generate_yaml_files # ===================================================================== # # === rcfiles --no-quotes # ===================================================================== # when /^-?-?no(-|_)?quotes$/ disable_quotes_then_generate_the_files # ===================================================================== # # === rcfiles --directory? # ===================================================================== # when /^-?-?directory\??$/ # yrcfile --directory? e sdir(CREATE_RCFILES_WHERE) # ===================================================================== # # === rcfiles --cmder-target # ===================================================================== # when /^-?-?cmder(-|_)?target$/i, /^-?-?cmder$/, /^-?-?cmd$/ opn; e 'Generating cmder-conforming rc-files next.' disable_quotes_then_generate_the_files else # This is the default. # =================================================================== # # First, handle directly passing existing yaml files into the # rcfiles project here. # # Usage example: # # rcfiles cd_aliases.yml # # =================================================================== # if File.exist?(i) and (File.extname(i).delete('.') == 'yml') autogenerate_rc_file_from_this_yaml_file(i) # =================================================================== # # Else, autogenerate all the various rc-files. # =================================================================== # else run_default_action # === rcfiles end end end end |
.populate_this_directory(i) ⇒ Object
#
Rcfiles.populate_this_directory
#
22 23 24 25 |
# File 'lib/rcfiles/toplevel_methods/autogenerate_rc_file_from_this_yaml_file.rb', line 22 def self.populate_this_directory(i) self.store_at = i generate_the_most_important_rcfiles end |
.project_base_dir? ⇒ Boolean
#
Rcfiles.project_base_dir?
#
34 35 36 |
# File 'lib/rcfiles/project/project.rb', line 34 def self.project_base_dir? @project_base_directory end |
.project_yaml_dir? ⇒ Boolean
#
Rcfiles.project_yaml_dir?
#
41 42 43 |
# File 'lib/rcfiles/project/project.rb', line 41 def self.project_yaml_dir? "#{@project_base_directory}yaml/" end |
.rds(i) ⇒ Object
#
Rcfiles.rds
#
12 13 14 |
# File 'lib/rcfiles/toplevel_methods/rds.rb', line 12 def self.rds(i) i.squeeze('/') end |
.remove_newlines(i, ensure_this_encoding = nil) ⇒ Object
#
Rcfiles.remove_newlines
This method will remove all newlines of the given input. The given input is the first argument to this method.
The optional second input to this method can be used to also ensure that a proper encoding is used.
#
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rcfiles/toplevel_methods/remove_newlines.rb', line 18 def self.remove_newlines( i, ensure_this_encoding = nil # 'ISO-8859-1' # <- or nil. ) if ensure_this_encoding i = i.force_encoding(ensure_this_encoding) end i.delete!("\n") if i.include?("\n") return i end |
.report ⇒ Object
#
Rcfiles.report
This method will report some information about where the Rcfiles will collect information.
#
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rcfiles/toplevel_methods/report.rb', line 23 def self.report e 'The main directory is at:' e e " #{sdir(main_directory?)}" unless File.directory? main_directory? e 'This directory could, however had, NOT be found.' end e e 'The three main .yml aliases paths are:' e e ' file aliases: '+sfile(file_aliases?) unless File.exist? file_aliases? e 'This file could not be found.' end e ' file cd aliases: '+sfile(file_cd_aliases?) unless File.exist? file_cd_aliases? e 'This file could not be found.' end e ' file programs aliases: '+sfile(file_programs_aliases?) unless File.exist? file_programs_aliases? e 'This file could not be found.' end e end |
.return_standard_header(which_file = '', current_date = Time.now.strftime('%d.%m.%Y')) ⇒ Object
#
Rcfiles.return_standard_header
This adds a standard header to our RC-File in question.
The first input argument to this method should be the name of the rc-file at hand.
#
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rcfiles/toplevel_methods/return_standard_header.rb', line 18 def self.return_standard_header( which_file = '', current_date = Time.now.strftime('%d.%m.%Y') ) _ = <<-EOF # =========================================================================== # # This file was automatically generated at: #{current_date} # # The filename is: # # #{which_file} # # =========================================================================== # EOF return _ end |
.rev(use_colours = @use_colours) ⇒ Object
#
Rcfiles.rev
#
24 25 26 27 28 29 30 31 32 |
# File 'lib/rcfiles/colours/colours.rb', line 24 def self.rev( use_colours = @use_colours ) if use_colours return ::Colours.rev else return '' end end |
.run_default_action(also_install_the_rcfiles_project = is_on_roebe? ) ⇒ Object
#
Rcfiles.run_default_action
If the argument to this method is true then we will also install the rcfiles project.
#
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rcfiles/toplevel_methods/misc.rb', line 65 def self.run_default_action( also_install_the_rcfiles_project = is_on_roebe? ) # ======================================================================= # # If we are on roebe then we will also run rinstall2 first. # ======================================================================= # if also_install_the_rcfiles_project install_the_rcfiles_project end generate_the_most_important_rcfiles end |
.run_it(optional_arguments = ARGV) ⇒ Object
#
Rcfiles.run_it
#
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rcfiles/toplevel_methods/run_it.rb', line 19 def self.run_it( optional_arguments = ARGV ) require 'rcfiles/requires/require_the_rcfiles_project.rb' require 'convert_global_env' Dir.chdir(ConvertGlobalEnv['$RSRC/rcfiles/']) # cd to it. begin require 'roebe/toplevel_methods/setup.rb' Roebe.copy_setup_file_to_pwd rescue LoadError puts 'Could not load the file roebe/toplevel_methods/setup.rb' end if File.exist? 'setup.rb' system 'ruby setup.rb --quiet config' system 'ruby setup.rb --quiet setup' system 'ruby setup.rb --quiet install' File.delete('setup.rb') if File.exist? 'setup.rb' File.delete('InstalledFiles') if File.exist? 'InstalledFiles' File.delete('.config') if File.exist? '.config' ::Rcfiles[] { yield if block_given? } end end |
.sdir(i = '', use_colours = @use_colours) ⇒ Object
#
Rcfiles.sdir
#
58 59 60 61 62 63 64 65 |
# File 'lib/rcfiles/colours/colours.rb', line 58 def self.sdir( i = '', use_colours = @use_colours ) if use_colours and Object.const_defined?(:Colours) return ::Colours.sdir(i) end i end |
.set_be_verbose(i) ⇒ Object
#
Rcfiles.set_be_verbose
#
24 25 26 |
# File 'lib/rcfiles/toplevel_methods/verbosity.rb', line 24 def self.set_be_verbose(i) @be_verbose = i end |
.set_cd_aliases(i = :default) ⇒ Object
#
Rcfiles.set_cd_aliases
#
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rcfiles/files/file_cd_aliases.rb', line 18 def self.set_cd_aliases( i = :default ) case i when :default, nil if is_on_roebe? and File.exist?('/Depot/cd_aliases.yml') i = '/Depot/cd_aliases.yml' else i = "#{project_yaml_dir?}cd_aliases.yml" end end @file_cd_aliases = i end |
.set_file_aliases(i = :default) ⇒ Object
#
Rcfiles.set_file_aliases
#
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rcfiles/files/file_aliases.rb', line 17 def self.set_file_aliases( i = :default ) case i when :default, nil if is_on_roebe? and File.exist?('/Depot/aliases.yml') i = '/Depot/aliases.yml' else i = "#{project_yaml_dir?}aliases.yml" end end @file_aliases = i end |
.set_file_ls_colours(i = :default) ⇒ Object
#
Rcfiles.set_file_ls_colours
#
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rcfiles/files/file_ls_colours.rb', line 17 def self.set_file_ls_colours( i = :default ) case i when :default, nil if is_on_roebe? and File.exist?('/Depot/ls_colours.yml') i = '/Depot/ls_colours.yml' else i = "#{project_yaml_dir?}ls_colours.yml" end end @file_ls_colours = i end |
.set_file_path_variable(i = :default) ⇒ Object
#
Rcfiles.set_file_path_variable
#
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rcfiles/files/file_path_variable.rb', line 17 def self.set_file_path_variable( i = :default ) case i when :default, nil if is_on_roebe? and File.exist?('/Depot/path_variable.yml') i = '/Depot/path_variable.yml' else i = "#{project_yaml_dir?}path_variable.yml" end end @file_path_variable = i end |
.set_file_pkgconfig(i = :default) ⇒ Object
#
Rcfiles.set_file_pkgconfig
#
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rcfiles/files/file_pkgconfig.rb', line 17 def self.set_file_pkgconfig( i = :default ) case i when :default, nil if is_on_roebe? and File.exist?('/Depot/pkgconfig.yml') i = '/Depot/pkgconfig.yml' else i = "#{project_yaml_dir?}pkgconfig.yml" end end @file_pkgconfig = i end |
.set_file_ps1(i = :default) ⇒ Object
#
Rcfiles.set_file_ps1
#
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rcfiles/files/file_ps1.rb', line 19 def self.set_file_ps1( i = :default ) case i when :default, nil if is_on_roebe? and File.exist?('/Depot/ps1.yml') i = '/Depot/ps1.yml' else i = "#{project_yaml_dir?}ps1.yml" end end @file_ps1 = i end |
.set_programs_aliases(i = :default) ⇒ Object
#
Rcfiles.set_programs_aliases
#
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rcfiles/files/file_programs_aliases.rb', line 17 def self.set_programs_aliases( i = :default ) case i when :default, nil if is_on_roebe? and File.exist?('/Depot/programs_aliases.yml') i = '/Depot/programs_aliases.yml' else i = "#{project_yaml_dir?}programs_aliases.yml" end end @file_programs_aliases = i end |
.set_project_base_directory(i = :default) ⇒ Object
#
Rcfiles.set_project_base_directory
#
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rcfiles/project/project.rb', line 12 def self.set_project_base_directory( i = :default ) case i when :default i = File.absolute_path("#{__dir__}/..") end unless i.end_with? '/' i = i.dup if i.frozen? i << '/' end # ======================================================================= # # === Rcfiles::@project_base_directory # ======================================================================= # @project_base_directory = i end |
.set_store_into_this_directory(i = :pwd, save_into_file = true) ⇒ Object
#
Rcfiles.set_store_into_this_directory
If the second argument to this method is true then we will also save this information into a local file.
#
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rcfiles/toplevel_methods/main_directory.rb', line 71 def self.set_store_into_this_directory( i = :pwd, save_into_file = true ) case i when 'pwd', 'Dir.pwd', :pwd i = Dir.pwd end i << '/' unless i.end_with? '/' self.store_at = i what = i into = FILE_STORE_INTO_THIS_DIRECTORY if save_into_file e "We will store into the directory `#{sdir(what.to_s)}` from now on." e "This will be saved into the file `#{sfile(into)}`." write_what_into(what, into) end # ======================================================================= # # Also save it on my home system. # ======================================================================= # this_dir = "#{RUBY_SRC_DIR_AT_HOME}rcfiles/lib/rcfiles/yaml/" if (ENV['IS_ROEBE'].to_s == '1') and File.directory?(this_dir) and save_into_file into = "#{this_dir}store_into_this_directory.yml" # <- Save into this file here. e "And also into the file `#{sfile(into)}`." write_what_into(what, into) end end |
.set_system_settings(i = :default) ⇒ Object
#
Rcfiles.set_system_settings
On my home system the file system_settings.yml can be found here:
$RUBY_SRC/rcfiles/lib/rcfiles/yaml/system_settings.yml
#
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rcfiles/files/file_system_settings.rb', line 22 def self.set_system_settings( i = :default ) case i # ======================================================================= # # === :default # ======================================================================= # when :default, nil if is_on_roebe? and File.exist?('/Depot/system_settings.yml') i = '/Depot/system_settings.yml' else i = "#{project_yaml_dir?}system_settings.yml" end end @file_system_settings = i.to_s end |
.set_use_this_encoding(i = MAIN_ENCODING_TO_USE) ⇒ Object
#
Rcfiles.set_use_this_encoding
This toplevel-method can be used to assign to another encoding set that is to be used.
#
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/rcfiles/constants/constants.rb', line 177 def self.set_use_this_encoding( i = MAIN_ENCODING_TO_USE ) case i when :default i = MAIN_ENCODING_TO_USE when :utf, :utf8 i = UTF8_ENCODING end @use_this_encoding = i end |
.sfancy(i = '') ⇒ Object
#
Rcfiles.sfancy
#
70 71 72 73 74 75 |
# File 'lib/rcfiles/colours/colours.rb', line 70 def self.sfancy(i = '') if @use_colours and Object.const_defined?(:Colours) return ::Colours.sfancy(i) end i end |
.sfile(i = '') ⇒ Object
#
Rcfiles.sfile
#
104 105 106 107 108 109 110 111 |
# File 'lib/rcfiles/colours/colours.rb', line 104 def self.sfile(i = '') if @use_colours and Object.const_defined?(:Colours) and Colours.respond_to?(:sfile) return ::Colours.sfile(i) else i end end |
.show_help ⇒ Object
#
Rcfiles.show_help (help tag)
To invoke this help method, do this:
rcfiles --help
#
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rcfiles/help/help.rb', line 20 def self.show_help result = <<EOF #{rev}The following options are available for the #{steelblue('Rcfiles namespace')}: #{lightgreen('--directory?')} # display which directory will be used to # keep the generated rc-files #{lightgreen('--set or --directory')} # generate the rc-files into this directory #{lightgreen('--no-quotes')} # generate the files without any "" quotes #{lightgreen('--utf8')} # generate UTF8-conforming yaml files #{lightgreen('--copy-rcfiles')} # copies the rcfiles into the current working directory # (note that --copy or just --cp would also work) #{lightgreen('--windows-cd-aliases')} # create a .bat file for the cd-aliases on the # windows platform #{lightgreen('--sitelibdir')} # show where the sitelibdir is located #{lightgreen('--n_aliases?')} # return how many aliases are registered in the # rcfiles project Note that if you do not pass any options then the rc-files will be generated into the default directory. If you pass a .yml file as input, then we will generate rc-files based on the entries found within that yaml file. EOF e result end |
.show_how_many_aliases_are_registered_in_this_project_in_total ⇒ Object
#
Rcfiles.show_how_many_aliases_are_registered_in_this_project_in_total
To run this method, try:
rcfiles --n_aliases?
#
181 182 183 184 185 186 187 188 |
# File 'lib/rcfiles/commandline/commandline.rb', line 181 def self.show_how_many_aliases_are_registered_in_this_project_in_total n_aliases = 0 n_aliases += YAML.load_file(file_aliases?).keys.size n_aliases += YAML.load_file(file_cd_aliases?).keys.size n_aliases += YAML.load_file(file_programs_aliases?).keys.size e "#{::Colours.sfancy(n_aliases)} #{::Colours.rev}aliases "\ "are available in this project." end |
.simp(i = '', use_colours = @use_colours) ⇒ Object
#
Rcfiles.simp
#
80 81 82 83 84 85 86 87 |
# File 'lib/rcfiles/colours/colours.rb', line 80 def self.simp( i = '', use_colours = @use_colours ) if use_colours and Object.const_defined?(:Colours) return ::Colours.simp(i) end i end |
.steelblue(i = '') ⇒ Object
#
Rcfiles.steelblue
#
116 117 118 119 120 121 122 123 |
# File 'lib/rcfiles/colours/colours.rb', line 116 def self.steelblue(i = '') if @use_colours and Object.const_defined?(:Colours) and Colours.respond_to?(:steelblue) return ::Colours.steelblue(i) else i end end |
.store_at=(i) ⇒ Object
#
Rcfiles.store_at=
#
57 58 59 60 61 62 63 |
# File 'lib/rcfiles/toplevel_methods/main_directory.rb', line 57 def self.store_at=(i) unless i.end_with? '/' i = i.dup if i.frozen? i << '/' end @store_into_this_directory = i end |
.teal(i = '') ⇒ Object
#
Rcfiles.teal
#
92 93 94 95 96 97 98 99 |
# File 'lib/rcfiles/colours/colours.rb', line 92 def self.teal(i = '') if @use_colours and Object.const_defined?(:Colours) and Colours.respond_to?(:teal) return ::Colours.teal(i) else i end end |
.toggle_quotes ⇒ Object
#
Rcfiles.toggle_quotes
This method can be used to toggle the use-quotes behaviour of the rcfiles project.
#
44 45 46 47 48 49 50 |
# File 'lib/rcfiles/toplevel_methods/use_quotes.rb', line 44 def self.toggle_quotes if @use_quotes == true @use_quotes = false else @use_quotes = true end end |
.use_colours? ⇒ Boolean
#
Rcfiles.use_colours?
#
37 38 39 |
# File 'lib/rcfiles/colours/colours.rb', line 37 def self.use_colours? @use_colours end |
.use_psych_or_syck=(i = :psych) ⇒ Object
#
Rcfiles.use_psych_or_syck=
#
39 40 41 |
# File 'lib/rcfiles/toplevel_methods/use_psych_or_syck.rb', line 39 def self.use_psych_or_syck=(i = :psych) @use_psych_or_syck = i.to_sym end |
.use_psych_or_syck? ⇒ Boolean
#
Rcfiles.use_psych_or_syck?
#
32 33 34 |
# File 'lib/rcfiles/toplevel_methods/use_psych_or_syck.rb', line 32 def self.use_psych_or_syck? @use_psych_or_syck end |
.use_quotes=(i) ⇒ Object
#
Rcfiles.use_quotes=
#
34 35 36 |
# File 'lib/rcfiles/toplevel_methods/use_quotes.rb', line 34 def self.use_quotes=(i) @use_quotes = i end |
.use_quotes? ⇒ Boolean
#
Rcfiles.use_quotes?
#
27 28 29 |
# File 'lib/rcfiles/toplevel_methods/use_quotes.rb', line 27 def self.use_quotes? @use_quotes end |
.use_this_encoding? ⇒ Boolean
#
Rcfiles.use_this_encoding?
#
197 198 199 |
# File 'lib/rcfiles/constants/constants.rb', line 197 def self.use_this_encoding? @use_this_encoding end |
.version? ⇒ Boolean
#
Rcfiles.version?
#
22 23 24 |
# File 'lib/rcfiles/version/version.rb', line 22 def self.version? VERSION end |
.write_what_into(what = '', into = '') ⇒ Object
#
Rcfiles.write_what_into
This method can be used to save data into a file.
#
17 18 19 20 21 22 23 24 25 |
# File 'lib/rcfiles/toplevel_methods/save_file.rb', line 17 def self.write_what_into( what = '', into = '' ) unless File.directory? File.dirname(into) FileUtils.mkdir_p(File.dirname(into)) end File.open(into, 'w') { |file| file.write(what) } end |