class RBT::GenerateShellCompletion

Constants

ARRAY_USE_THESE_ALIASES
#

ARRAY_USE_THESE_ALIASES

This constant specifies which aliases we will use, for completion in a shell such as bash or zsh.

#
DEFAULT_COMPLETION
#

DEFAULT_COMPLETION

#
NAMESPACE
#

NAMESPACE

#

Public Class Methods

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

initialize

#
# File lib/rbt/utility_scripts/generate_shell_completion.rb, line 51
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

#
# File lib/rbt/utility_scripts/generate_shell_completion.rb, line 97
def add_all_cookbook_aliases
  RBT.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/utility_scripts/generate_shell_completion.rb, line 148
  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
    # ======================================================================= #
    # === 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.
    # ======================================================================= #
    opnn; e '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 /Users/x/DATA/PC/OS/LINUX/SHELL/SCRIPTS/ is
      # no longer an active setting.
      # ===================================================================== #
      case i
      when :bash
        # _.store_here "/Users/x/DATA/PC/OS/LINUX/SHELL/SCRIPTS/bash_completion.sh"
        # _.run
        _.store_here "/Users/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/rbt/lib/rbt/shell/bash_completion.sh"
        _.run
      when :zsh
        # _.store_here "/Users/x/DATA/PC/OS/LINUX/SHELL/SCRIPTS/zsh_completion.sh"
        # _.run
        _.store_here "/Users/x/DATA/PROGRAMMING_LANGUAGES/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/utility_scripts/generate_shell_completion.rb, line 106
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/utility_scripts/generate_shell_completion.rb, line 115
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/utility_scripts/generate_shell_completion.rb, line 122
def report_store_into_where(i)
  opnn; e "Storing into #{sfile(i)}"
  opnn; e 'To source this file, do issue:'
  e
  e "  . #{sfile(i)}"
  e
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/generate_shell_completion.rb, line 65
def reset
  super()
  @generate_shell_completion_for_this_shell = nil
  # ======================================================================= #
  # 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
  @namespace = NAMESPACE
end
run() click to toggle source
#

run (run tag)

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

run_everything

#
# File lib/rbt/utility_scripts/generate_shell_completion.rb, line 133
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/utility_scripts/generate_shell_completion.rb, line 81
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