Class: Eggsh::Shell
Constant Summary collapse
- SHELL_CMD =
mapping from shell commands to member function
{'cd' => :cd, 'pwd' => :pwd, 'fullpwd' => :full_pwd, 'quit' => :quit, 'exit' => :quit}
- ALIAS =
alias hash for command alias
{'ls' => 'ls --color=auto'}
Instance Method Summary collapse
-
#exec(line) ⇒ Object
handling a single line.
-
#initialize ⇒ Shell
constructor
A new instance of Shell.
-
#prompt ⇒ Object
generating prompt.
Constructor Details
#initialize ⇒ Shell
Returns a new instance of Shell.
14 15 16 17 18 |
# File 'lib/shell.rb', line 14 def initialize @env = ENV.to_hash @pwd = ENV['PWD'] @translator = Eggsh::Translator.new end |
Instance Method Details
#exec(line) ⇒ Object
handling a single line
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/shell.rb', line 26 def exec line begin # alias first if line != '' && ALIAS.has_key?(line.split(' ')[0]) splitted = line.split(' ') splitted[0] = ALIAS[splitted[0]] line = splitted.join ' ' end if !line.empty? && SHELL_CMD.has_key?(line.split(' ')[0]) msg = send(SHELL_CMD[line.split(' ')[0]], line) puts msg if msg elsif line.empty? else begin shell_line = @translator.translate(line) unless shell_line.empty? Kernel.spawn(@env, shell_line, :chdir => @pwd) Process.wait end rescue Exception => e puts e.display end end end end |
#prompt ⇒ Object
generating prompt
21 22 23 |
# File 'lib/shell.rb', line 21 def prompt "#{pwd.to_color(:bold_green)}$ " end |