Class: Irsh::Shell
- Inherits:
-
Object
- Object
- Irsh::Shell
- Defined in:
- lib/shell.rb
Instance Method Summary collapse
- #exittime ⇒ Object
- #handleliteral(cmd) ⇒ Object
- #handleoop(cmd) ⇒ Object
- #init ⇒ Object
- #runliteral ⇒ Object
- #runoop ⇒ Object
Instance Method Details
#exittime ⇒ Object
34 35 36 37 |
# File 'lib/shell.rb', line 34 def exittime #write stuff to file maybe? exit end |
#handleliteral(cmd) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/shell.rb', line 39 def handleliteral(cmd) rawcmd = cmd.split(' ')[0] args = cmd.split(' ')[1..-1].join(' ') case rawcmd when "$irsh" runoop when "cd" Dir.chdir(args) else iserrored = system(cmd) puts 'Command not found' if iserrored == nil end end |
#handleoop(cmd) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/shell.rb', line 53 def handleoop(cmd) runliteral if cmd.split(' ')[0] == "$irsh" res = eval(cmd, @binding) $last_res = res eval("_ = $last_res", @binding) puts res rescue ::Exception => e puts "Exception #{e.class} -> #{e.}" e.backtrace.each do |t| puts " #{::File.(t)}" end end |
#init ⇒ Object
29 30 31 32 |
# File 'lib/shell.rb', line 29 def init @binding = binding runliteral end |
#runliteral ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/shell.rb', line 8 def runliteral loop do currdir = Dir.pwd.split('/').last cmd = Readline.readline("ir$h (#{currdir})> ") exittime if cmd.nil? or cmd == "exit" next if cmd == "" Readline::HISTORY.push(cmd) handleliteral(cmd) end end |
#runoop ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/shell.rb', line 19 def runoop loop do cmd = Readline.readline("iRsh> ") exittime if cmd.nil? or cmd == "exit" next if cmd == "" Readline::HISTORY.push(cmd) handleoop(cmd) end end |