<commit_before>require_relative 'translator'

# temprerary put here
$alias_hash = {'ls' => 'ls --color=auto'}

module Eggsh
  class Shell
    SHELL_CMD = {'cd' => :cd, 'pwd' => :pwd, 'fullpwd' => :full_pwd,
                 'quit' => :quit, 'exit' => :quit}

    def initialize
      @env = ENV.to_hash
      @pwd = ENV['<PASSWORD>']
      @translator = Eggsh::Translator.new
    end

    def env
      @env
    end

    def exec line
      begin
        # alias first
        if line != '' && $alias_hash.has_key?(line.split(' ')[0])
          splitted = line.split(' ')
          splitted[0] = $alias_hash[splitted[0]]
          line = splitted.join ' '
        end
        #puts line
        if line != '' && SHELL_CMD.has_key?(line.split(' ')[0])
          send(SHELL_CMD[line.split(' ')[0]], line)
        else
          begin
            spawn(@env, @translator.translate(line).gsub("\n", ' '), :chdir => @pwd)
          rescue Errno::ENOENT => e
            puts e.display
          end
        end
      #rescue
      #  puts 'Syntax error'
      end
    end

  private
    def pwd arg
      short = @pwd.split '/'
      (0...(short.size - 1)).each {|i| short[i] = short[i][0]}
      puts short.join '/'
    end

    def full_pwd arg
      puts @pwd
    end

    def cd arg
      new_path = File.expand_path arg.split(' ')[1], @pwd
      if File.directory? new_path
        @pwd = new_path<commit_msg>Fix the prompt behavior and empty line<commit_after>require_relative 'translator'

# temprerary put here
$alias_hash = {'ls' => 'ls --color=auto'}

module Eggsh
  class Shell
    SHELL_CMD = {'cd' => :cd, 'pwd' => :pwd, 'fullpwd' => :full_pwd,
                 'quit' => :quit, 'exit' => :quit}

    def initialize
      @env = ENV.to_hash
      @pwd = ENV['<PASSWORD>']
      @translator = Eggsh::Translator.new
    end

    def env
      @env
    end

    def exec line
      begin
        # alias first
        if line != '' && $alias_hash.has_key?(line.split(' ')[0])
          splitted = line.split(' ')
          splitted[0] = $alias_hash[splitted[0]]
          line = splitted.join ' '
        end
        #puts line
        if !line.empty? && SHELL_CMD.has_key?(line.split(' ')[0])
          send(SHELL_CMD[line.split(' ')[0]], line)
        elsif line.empty?
        else
          begin
            spawn(@env, @translator.translate(line).gsub("\n", ' '), :chdir => @pwd)
            Process.wait
          rescue Errno::ENOENT => e
            puts e.display
          end
        end
      #rescue
      #  puts 'Syntax error'
      end
    end

  private
    def pwd arg
      short = @pwd.split '/'
      (0...(short.size - 1)).each {|i| short[i] = short[i][0]}
      puts short.join '/'
    end

    def full_pwd arg
      puts @pwd
    end

    def cd arg
      new_path = File.expand_path arg.split(' ')[1], @pwd
      if File.directory? new_path
        @pwd = new_path
{'fraction_non_alphanumeric': 0.1477900552486188, 'fraction_numerical': 0.006215469613259668, 'mean_word_length': 1.815354713313897, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5058779', 'n_tokens_mistral': 1022, 'n_tokens_neox': 1009, 'n_words': 238}