class RBT::GenerateShellCompletion

Constants

ARRAY_USE_THESE_ALIASES
DEFAULT_COMPLETION
#

DEFAULT_COMPLETION

#

Public Class Methods

new( generate_shell_completion_for_this_shell = DEFAULT_COMPLETION, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/generate_files/generate_shell_completion.rb, line 54
def initialize(
    generate_shell_completion_for_this_shell = DEFAULT_COMPLETION,
    run_already                              = true
  )
  reset
  set_generate_shell_completion_for_this_shell(
    generate_shell_completion_for_this_shell
  )
  run if run_already
end

Public Instance Methods

add_all_cookbook_aliases() click to toggle source
#

add_all_cookbook_aliases

This method must return all available aliases of the RBT project.

#
# File lib/rbt/generate_files/generate_shell_completion.rb, line 232
def add_all_cookbook_aliases
  require_the_rbt_aliases
  RBT.cookbook_aliases?
end
do_generate_a_completion_file_for_this_shell(i) click to toggle source
#

do_generate_a_completion_file_for_this_shell

This is the main method when we want to create a tab-completion file for a specific shell, such as “bash” or “zsh” or “fish”.

#
# File lib/rbt/generate_files/generate_shell_completion.rb, line 149
  def do_generate_a_completion_file_for_this_shell(i)
    array = available_programs? # <- Obtain the available programs.
    # ======================================================================= #
    # Next, add aliases to that list.
    # ======================================================================= #
    array << add_all_cookbook_aliases
    array.flatten!
    _ = ::GenerateShellCompletion::GenerateShellCompletion.new(ARGV, :dont_run_yet)
    _.set_name_of_the_shell_function 'completion_for_ry'
    _.set_dataset(array)
    #_.remove_old_file
    # ======================================================================= #
    # === Determine the aliases
    #
    # Which aliases to use here.
    # ======================================================================= #
    _.set_aliases(ARRAY_USE_THESE_ALIASES)
    case i # case tag
    # ======================================================================= #
    # === Bash
    #
    # Generate the file for bash-completion.
    # ======================================================================= #
    when :bash
      _.store_here "#{@use_this_as_base_directory}bash_completion.sh"
    # ======================================================================= #
    # === Zsh                                                       (zsh tag)
    #
    # We can also generate the zsh-completion.
    # ======================================================================= #
    when :zsh
      _.store_here "#{@use_this_as_base_directory}zsh_completion.sh"
      _.prepend_this_string '
autoload bashcompinit
bashcompinit
'
    _.run
      # ===================================================================== #
      # _ = "compdef 'compadd "+all_programs.join(' ')+" ' ry"+N
      # ^^^ this can be used for zsh perhaps.
      # ===================================================================== #
    when :fish
      _.store_here "#{@use_this_as_base_directory}fish_completion.sh"
    end
    # ======================================================================= #
    # Notify the user what we will do.
    # ======================================================================= #
    opne "Now generating the shell script (completion file) "\
         "`#{lightgreen(i)}`."
    report_store_into_where(_.store_where?)
    _.run
    if is_on_roebe?
      # ===================================================================== #
      # On roebe, we will also generate more files. Note that storing into
      # the directory called /home/x/DATA/PC/OS/LINUX/SHELL/SCRIPTS/ is
      # no longer an active setting.
      # ===================================================================== #
      case i
      # ===================================================================== #
      # === :bash
      # ===================================================================== #
      when :bash
        # _.store_here "/home/x/DATA/PC/OS/LINUX/SHELL/SCRIPTS/bash_completion.sh"
        # _.run
        _.store_here "#{HOME_DIRECTORY_FOR_USER_X}programming/ruby/src/rbt/lib/rbt/shell/bash_completion.sh"
        _.run
      # ===================================================================== #
      # === .:zsh
      # ===================================================================== #
      when :zsh
        # _.store_here "#{HOME_DIRECTORY_FOR_USER_X}DATA/PC/OS/LINUX/SHELL/SCRIPTS/zsh_completion.sh"
        # _.run
        _.store_here "#{HOME_DIRECTORY_FOR_USER_X}programming/ruby/src/rbt/lib/rbt/shell/zsh_completion.sh"
        _.run
      end
    end
  end
generate_completion_for_bash() click to toggle source
#

generate_completion_for_bash (bash tag)

This method will generate the completion file for the bash shell.

#
# File lib/rbt/generate_files/generate_shell_completion.rb, line 107
def generate_completion_for_bash
  do_generate_a_completion_file_for_this_shell(:bash)
end
generate_completion_for_zsh() click to toggle source
#

generate_completion_for_zsh (zsh tag)

This method will generate the completion file for the zsh shell.

#
# File lib/rbt/generate_files/generate_shell_completion.rb, line 116
def generate_completion_for_zsh
  do_generate_a_completion_file_for_this_shell(:zsh)
end
report_store_into_where(i) click to toggle source
#

report_store_into_where

#
# File lib/rbt/generate_files/generate_shell_completion.rb, line 123
def report_store_into_where(i)
  opne "Storing into #{sfile(i)}"
  opne 'To source this file, do issue:'
  e
  e "  . #{sfile(i)}"
  e
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/generate_files/generate_shell_completion.rb, line 68
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @generate_shell_completion_for_this_shell
  # ======================================================================= #
  @generate_shell_completion_for_this_shell = nil
  # ======================================================================= #
  # === @use_this_as_base_directory
  #
  # Next, we will store into the directory "shell_completion/".
  # ======================================================================= #
  @use_this_as_base_directory = "#{rbt_log_dir?}shell_completion/"
  unless File.directory? @use_this_as_base_directory
   mkdir(@use_this_as_base_directory) # <- Create this directory too.
  end
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/generate_files/generate_shell_completion.rb, line 240
def run
  run_everything
end
run_everything() click to toggle source
#

run_everything

#
# File lib/rbt/generate_files/generate_shell_completion.rb, line 134
def run_everything
  # ======================================================================= #
  # Bach-process the given input at hand:
  # ======================================================================= #
  @generate_shell_completion_for_this_shell.each {|this_shell|
    do_generate_a_completion_file_for_this_shell(this_shell)
  }
end
set_generate_shell_completion_for_this_shell( i = :all ) click to toggle source
#

set_generate_shell_completion_for_this_shell

#
# File lib/rbt/generate_files/generate_shell_completion.rb, line 89
def set_generate_shell_completion_for_this_shell(
    i = :all
  )
  case i
  when nil
    i = DEFAULT_COMPLETION
  when :all # <- This means to generate tab-completion for all shells.
    i = [:bash, :zsh, :fish]
  end
  i = [i].flatten.compact # <- Must always be an Array.
  @generate_shell_completion_for_this_shell = i
end