Class: Yarsh::Shell

Inherits:
Object
  • Object
show all
Includes:
Yarsh, InstanceMethods
Defined in:
lib/yarsh/shell.rb

Constant Summary collapse

SHELL_BUILTINS =
%w[alias bg bind break builtin command echo eval exec exit
export false fc fg getopts hash help history jobs kill let
local logout mapfile popd printf pushd pwd read readonly
return set shift shopt source suspend test times trap true
type typeset ulimit umask unalias unset wait].freeze

Constants included from InstanceMethods

InstanceMethods::SEVERITIES

Constants included from Yarsh

CONFIG_FILE, HISTORY_FILE, VERSION, YARSH_DIR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InstanceMethods

#__sh__, #__yarsh__, #configure, #sh_alias, #source

Methods included from Yarsh

console, current_shell, current_shell=, execute_system_command, expand_aliases, #shell_path?

Constructor Details

#initialize(bind) ⇒ Shell

Returns a new instance of Shell.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/yarsh/shell.rb', line 16

def initialize(bind)
  @bind = bind
  @core = Reline.core
  @history_file = File.expand_path(HISTORY_FILE)
  @config_file = File.expand_path(CONFIG_FILE)
  @cf = Yarsh::AnsiColorFormatter.new
  Yarsh.current_shell = self
  setup_reline_history
  setup_reline_completion
  setup_reline_prompt
end

Instance Attribute Details

#bindObject

Returns the value of attribute bind.



8
9
10
# File 'lib/yarsh/shell.rb', line 8

def bind
  @bind
end

Instance Method Details

#shellObject



28
29
30
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
# File 'lib/yarsh/shell.rb', line 28

def shell
  # TODO: defined method in the config file should be availabel in the shell
  load @config_file, InstanceMethods if File.exist? @config_file
  loop do
    input = begin
      read_input
    rescue Interrupt
      next
    end
    if input.nil? or input == 'exit'
      puts 'Bye...'
      break
    end

    append_history(input, @history_file)

    begin
      fp execute_multiline(input)
    rescue Interrupt
      next
    rescue SystemExit
      raise
    rescue Exception => e
      $rber = e
      puts @cf.fg_red("Error: #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}")
    end
  end
end