Module: SRBC_cli
- Included in:
- SRBC
- Defined in:
- lib/srbc/srbc_cli.rb
Instance Method Summary collapse
-
#run ⇒ Object
and detect SRBC command execute, file or system programm.
Instance Method Details
#run ⇒ Object
and detect SRBC command execute, file or system programm
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/srbc/srbc_cli.rb', line 7 def run() if @settings[@executor].nil? puts "\n Executor not defined. Run srbc with -add:<executor> options " self.runed = false else @ext = @settings[@executor] end while self.lunched do #get current path path = Dir.pwd #wait command and realise history of command command = Readline.readline("#{@executor.chr.upcase}# #{path.gsub "/", "\\"}~ ", true) command = nil if command.nil? if command =~ /^\s*$/ or Readline::HISTORY.to_a[-2] == command Readline::HISTORY.pop end cmd = command.gsub("#{path}~ ", '') #if user type command start with @ - run srbc command if cmd =~ /^@/ self.srbc_command cmd.gsub "@", "" elsif cmd == '' cmd = ' ' else case cmd.downcase # command cd - SRBC change current work dir when /cd/ if cmd =~ /\.\.$/ || cmd =~/^cd$/ temp_path = Dir.pwd.split '/' if temp_path.length > 1 temp_path.delete_at temp_path.length-1 if temp_path.length > 1 path = temp_path.join "\\" Dir.chdir path else Dir.chdir "#{temp_path[0]}\\" end end elsif cmd =~ /\.\.\/.*|\.\.\\.*/ temp_path = Dir.pwd.split '/' if temp_path.length > 1 temp_path.delete_at temp_path.length-1 if temp_path.length > 1 path = temp_path.join "\\" Dir.chdir path+cmd.gsub('cd ..','') else Dir.chdir "#{temp_path[0]}\\"+cmd.gsub('cd ..','') end end else begin Dir.chdir cmd.gsub 'cd ', '' rescue puts 'Wrong path' end end # command X: change current work dir if user whant change volume when /^\w:$/ begin Dir.chdir cmd rescue puts "Path not found" end #run with skip executor. # Use when you whant execute system command ping and have ping.rb un current folder when /^\!/ run_program cmd.gsub '!','' # run app or other program when /^$|^ *$/ #skip when empty command else file_list = self.get_file_list cmd #run file if find only one if file_list.length == 1 file_list.each do |name, args| run_file name, args end # не найдено фалов - значит команда elsif file_list.length == 0 run_program cmd # в остальных случаях файлов > 1 else puts 'We find, more than one file:' i = 0 numbered_files = {} puts " 0 | Cancel " file_list.each do |file| i += 1 puts " #{i} | #{file[0]}" numbered_files[i] = file[0] end num_file = -1 while num_file < 0 puts "Choose file to run (type @ and number of file)" num_file = gets.chomp.gsub("@", "").to_i if num_file > 0 run_file numbered_files[num_file], file_list[numbered_files[num_file]] end end end end end end end |