class GenerateRcFile
#¶ ↑
require 'generate_rc_file/constants.rb'
#¶ ↑
#¶ ↑
require 'generate_rc_file/version/version.rb'
#¶ ↑
Constants
- ARRAY_ALL_FILES
#¶ ↑
ARRAY_ALL_FILES
¶ ↑#¶ ↑
- ARRAY_WHICH_FILES_TO_ALIAS
#¶ ↑
ARRAY_WHICH_FILES_TO_ALIAS
¶ ↑#¶ ↑
- ARRAY_WHICH_FILES_TO_EXPORT
#¶ ↑
ARRAY_WHICH_FILES_TO_EXPORT
¶ ↑#¶ ↑
- BASE_DIR
#¶ ↑
BASE_DIR
¶ ↑Where to store. The base directory. We need to keep in mind that on some systems this directory does not exist but also can not be created, due to lack of permissions, for instance.
#¶ ↑
- HEADER1
#¶ ↑
HEADER1
¶ ↑#¶ ↑
- HEADER2
- ISO_ENCODING
#¶ ↑
ISO_ENCODING
¶ ↑#¶ ↑
- LINUX_YAML
- N
- RCFILE_GENERATOR_YAML_DIRECTORY
#¶ ↑
RCFILE_GENERATOR_YAML_DIRECTORY
¶ ↑Hardcoded path for now.
#¶ ↑
- VERSION
#¶ ↑
GenerateRcFile::VERSION
¶ ↑#¶ ↑
Attributes
use_putty_style_aliases[RW]
Public Class Methods
Public Instance Methods
add_header_for(this_file)
click to toggle source
base_directory?()
click to toggle source
#¶ ↑
base_directory?¶ ↑
#¶ ↑
# File lib/generate_rc_file/generate_rc_file.rb, line 40 def base_directory? @base_dir end
Also aliased as: base_dir?
do_generate_the_rc_file(use_this_input = @commandline)
click to toggle source
#¶ ↑
do_generate_the_rc_file
¶ ↑
#¶ ↑
# File lib/generate_rc_file/generate_rc_file.rb, line 160 def do_generate_the_rc_file(use_this_input = @commandline) if use_this_input.is_a? Array if use_this_input.empty? use_this_input << ARRAY_ALL_FILES # Add all possible rc files here. else case use_this_input when 'all',:all use_this_input << ARRAY_ALL_FILES when 'cd',:cd use_this_input << 'cd_aliases' end end end use_this_input.flatten.each {|generate_this_file| generate_this_file = generate_this_file.to_s # We need a String. full_path_to_the_file = LINUX_YAML+generate_this_file+'.yml' # ===================================================================== # # Next, add some exceptions: # ===================================================================== # if full_path_to_the_file.include? 'aliases.yml' full_path_to_the_file = RCFILE_GENERATOR_YAML_DIRECTORY+'aliases.yml' elsif full_path_to_the_file.include? 'cd_aliases.yml' full_path_to_the_file = RCFILE_GENERATOR_YAML_DIRECTORY+'cd_aliases.yml' elsif full_path_to_the_file.include? 'programs_aliases.yml' full_path_to_the_file = RCFILE_GENERATOR_YAML_DIRECTORY+'programs_aliases.yml' end hash_dataset = load_yaml(full_path_to_the_file) _ = ''.dup _ << add_header_for(generate_this_file) # Add the default header here. # ===================================================================== # # We have to find out whether we will use alias-style or export-style # next. For alias-style, we also may have to use putty-style or # normal-style. # ===================================================================== # if ARRAY_WHICH_FILES_TO_ALIAS.include? generate_this_file # =================================================================== # # Ok, alias-style comes here. # =================================================================== # hash_dataset.each_pair {|key, value| key = ensure_main_encoding(key.to_s) value = ensure_main_encoding(value.to_s).strip if @use_putty_style_aliases _ << "alias "+key.to_s+'="'+value+'"'+N else if value.include? "'" # Need to use another syntax for included ' characters. _ << "alias '#{key}'=\"#{value}\"#{N}" else _ << "alias '#{key}'='#{value}'#{N}" end end } else # =================================================================== # # Ok, in this case we assume export-style. # =================================================================== # hash_dataset.each_pair {|key, value| value = value.to_s _ << "export "+key.to_s+'="'+value+'"'+N } end set_store_here(@base_dir+generate_this_file+'_rc') store_what_where(_, @store_here) } end
enable_putty_style()
click to toggle source
ensure_main_encoding( i, use_this_encoding = ISO_ENCODING )
click to toggle source
load_yaml(i)
click to toggle source
parse_commandline(i = @commandline)
click to toggle source
#¶ ↑
parse_commandline
¶ ↑
#¶ ↑
# File lib/generate_rc_file/generate_rc_file.rb, line 91 def parse_commandline(i = @commandline) @commandline.each {|entry| case entry # case tag # ===================================================================== # # === gcfile --dir=~/AUTOGENERATED # ===================================================================== # when /-?-?dir=(.+)/ # See: http://rubular.com/r/kF3uKcOoL9 set_base_dir($1.to_s.dup) try_to_create_the_base_directory_if_it_does_not_exist(base_dir?) # Also ensure that the directory exists. # ===================================================================== # # === --help # ===================================================================== # when /-?-?help/i show_help exit end } purge_entries_with_two_hyphens end
Also aliased as: menu
purge_entries_with_two_hyphens()
click to toggle source
reset()
click to toggle source
run()
click to toggle source
set_base_dir(i = BASE_DIR)
click to toggle source
#¶ ↑
set_base_dir
¶ ↑
#¶ ↑
# File lib/generate_rc_file/generate_rc_file.rb, line 228 def set_base_dir(i = BASE_DIR) i = i.to_s.dup # Work on a "fresh" copy. # ======================================================================= # # Must check if the input contains a ~ character, which is then assumed # to refer to the home dir of the user. # ======================================================================= # if i.include? '~' i = File.expand_path(i) end i << '/' unless i.end_with? '/' @base_dir = i end
set_commandline(i)
click to toggle source
set_store_here(i)
click to toggle source
show_help()
click to toggle source
store_what_where( what = @_, where = base_directory?+'aliases_rc' )
click to toggle source
try_to_create_the_base_directory_if_it_does_not_exist(i = @base_dir)
click to toggle source