eggsh 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
 - data/eggsh.gemspec +2 -2
 - data/lib/runner.rb +1 -1
 - data/lib/shell.rb +23 -12
 - data/lib/util.rb +14 -1
 - metadata +4 -4
 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.1. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.1.2
         
     | 
    
        data/eggsh.gemspec
    CHANGED
    
    | 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{eggsh}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.1. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.1.2"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["Andrew Liu"]
         
     | 
| 
       12 
     | 
    
         
            -
              s.date = %q{2011-01- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = %q{2011-01-24}
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.default_executable = %q{eggsh}
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.description = %q{Use Ruby expressions instead of unfriendly shell script}
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.email = %q{andrewliu33@gmail.com}
         
     | 
    
        data/lib/runner.rb
    CHANGED
    
    
    
        data/lib/shell.rb
    CHANGED
    
    | 
         @@ -5,7 +5,8 @@ $alias_hash = {'ls' => 'ls --color=auto'} 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            module Eggsh
         
     | 
| 
       7 
7 
     | 
    
         
             
              class Shell
         
     | 
| 
       8 
     | 
    
         
            -
                SHELL_CMD = {'cd' => :cd, 'pwd' => :pwd, 'fullpwd' => :full_pwd 
     | 
| 
      
 8 
     | 
    
         
            +
                SHELL_CMD = {'cd' => :cd, 'pwd' => :pwd, 'fullpwd' => :full_pwd,
         
     | 
| 
      
 9 
     | 
    
         
            +
                             'quit' => :quit, 'exit' => :quit}
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
11 
     | 
    
         
             
                def initialize
         
     | 
| 
       11 
12 
     | 
    
         
             
                  @env = ENV.to_hash
         
     | 
| 
         @@ -17,6 +18,10 @@ module Eggsh 
     | 
|
| 
       17 
18 
     | 
    
         
             
                  @env
         
     | 
| 
       18 
19 
     | 
    
         
             
                end
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
      
 21 
     | 
    
         
            +
                def prompt
         
     | 
| 
      
 22 
     | 
    
         
            +
                  "#{pwd.to_color(:bold_green)}$ "
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       20 
25 
     | 
    
         
             
                def exec line
         
     | 
| 
       21 
26 
     | 
    
         
             
                  begin
         
     | 
| 
       22 
27 
     | 
    
         
             
                    # alias first
         
     | 
| 
         @@ -25,40 +30,46 @@ module Eggsh 
     | 
|
| 
       25 
30 
     | 
    
         
             
                      splitted[0] = $alias_hash[splitted[0]]
         
     | 
| 
       26 
31 
     | 
    
         
             
                      line = splitted.join ' '
         
     | 
| 
       27 
32 
     | 
    
         
             
                    end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                    if line  
     | 
| 
       30 
     | 
    
         
            -
                      send(SHELL_CMD[line.split(' ')[0]], line)
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    if !line.empty? && SHELL_CMD.has_key?(line.split(' ')[0])
         
     | 
| 
      
 35 
     | 
    
         
            +
                      msg = send(SHELL_CMD[line.split(' ')[0]], line)
         
     | 
| 
      
 36 
     | 
    
         
            +
                      puts msg if msg
         
     | 
| 
      
 37 
     | 
    
         
            +
                    elsif line.empty?
         
     | 
| 
       31 
38 
     | 
    
         
             
                    else
         
     | 
| 
       32 
39 
     | 
    
         
             
                      begin
         
     | 
| 
       33 
40 
     | 
    
         
             
                        spawn(@env, @translator.translate(line).gsub("\n", ' '), :chdir => @pwd)
         
     | 
| 
      
 41 
     | 
    
         
            +
                        Process.wait
         
     | 
| 
       34 
42 
     | 
    
         
             
                      rescue Errno::ENOENT => e
         
     | 
| 
       35 
43 
     | 
    
         
             
                        puts e.display
         
     | 
| 
       36 
44 
     | 
    
         
             
                      end
         
     | 
| 
       37 
45 
     | 
    
         
             
                    end
         
     | 
| 
       38 
     | 
    
         
            -
                  #rescue
         
     | 
| 
       39 
     | 
    
         
            -
                  #  puts 'Syntax error'
         
     | 
| 
       40 
46 
     | 
    
         
             
                  end
         
     | 
| 
       41 
47 
     | 
    
         
             
                end
         
     | 
| 
       42 
48 
     | 
    
         | 
| 
       43 
49 
     | 
    
         
             
              private
         
     | 
| 
       44 
     | 
    
         
            -
                def pwd arg
         
     | 
| 
      
 50 
     | 
    
         
            +
                def pwd arg = ''
         
     | 
| 
       45 
51 
     | 
    
         
             
                  short = @pwd.split '/'
         
     | 
| 
       46 
52 
     | 
    
         
             
                  (0...(short.size - 1)).each {|i| short[i] = short[i][0]}
         
     | 
| 
       47 
     | 
    
         
            -
                   
     | 
| 
      
 53 
     | 
    
         
            +
                  short.join '/'
         
     | 
| 
       48 
54 
     | 
    
         
             
                end
         
     | 
| 
       49 
55 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                def full_pwd arg
         
     | 
| 
       51 
     | 
    
         
            -
                   
     | 
| 
      
 56 
     | 
    
         
            +
                def full_pwd arg = ''
         
     | 
| 
      
 57 
     | 
    
         
            +
                  @pwd
         
     | 
| 
       52 
58 
     | 
    
         
             
                end
         
     | 
| 
       53 
59 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
                def cd arg
         
     | 
| 
      
 60 
     | 
    
         
            +
                def cd arg = '.'
         
     | 
| 
       55 
61 
     | 
    
         
             
                  new_path = File.expand_path arg.split(' ')[1], @pwd
         
     | 
| 
       56 
62 
     | 
    
         
             
                  if File.directory? new_path
         
     | 
| 
       57 
63 
     | 
    
         
             
                    @pwd = new_path
         
     | 
| 
      
 64 
     | 
    
         
            +
                    return nil
         
     | 
| 
       58 
65 
     | 
    
         
             
                  else
         
     | 
| 
       59 
     | 
    
         
            -
                     
     | 
| 
      
 66 
     | 
    
         
            +
                    return "cd: Invalid path #{arg.split(' ')[1]}"
         
     | 
| 
       60 
67 
     | 
    
         
             
                  end
         
     | 
| 
       61 
68 
     | 
    
         
             
                end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                def quit arg = ''
         
     | 
| 
      
 71 
     | 
    
         
            +
                  exit
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
       62 
73 
     | 
    
         
             
              end
         
     | 
| 
       63 
74 
     | 
    
         
             
            end
         
     | 
| 
       64 
75 
     | 
    
         | 
    
        data/lib/util.rb
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # define to_cmd for every object
         
     | 
| 
       2 
1 
     | 
    
         
             
            class Object
         
     | 
| 
      
 2 
     | 
    
         
            +
              # define to_cmd for every object
         
     | 
| 
       3 
3 
     | 
    
         
             
              def to_cmd
         
     | 
| 
       4 
4 
     | 
    
         
             
                if self.kind_of? Array
         
     | 
| 
       5 
5 
     | 
    
         
             
                  return self.join ' '
         
     | 
| 
         @@ -7,5 +7,18 @@ class Object 
     | 
|
| 
       7 
7 
     | 
    
         
             
                  return self.to_s
         
     | 
| 
       8 
8 
     | 
    
         
             
                end
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              # define to_color for terminal output
         
     | 
| 
      
 12 
     | 
    
         
            +
              COLOR_CODE = {
         
     | 
| 
      
 13 
     | 
    
         
            +
                :black => '30', :red => '31', :green => '32', :yellow => '33', :blue => '34',
         
     | 
| 
      
 14 
     | 
    
         
            +
                :purple => '35', :cyan => '36', :white => '37', :bold_black => '1;30',
         
     | 
| 
      
 15 
     | 
    
         
            +
                :bold_red => '1;31', :bold_green => '1;32', :bold_yellow => '1;33',
         
     | 
| 
      
 16 
     | 
    
         
            +
                :bold_blue => '1;34', :bold_purple => '1;35', :bold_cyan => '1;36',
         
     | 
| 
      
 17 
     | 
    
         
            +
                :bold_white => '1;37'
         
     | 
| 
      
 18 
     | 
    
         
            +
              }
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              def to_color color
         
     | 
| 
      
 21 
     | 
    
         
            +
                "\x1b[#{COLOR_CODE[color]}m#{to_s}\x1b[m"
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
       10 
23 
     | 
    
         
             
            end
         
     | 
| 
       11 
24 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version 
     | 
|
| 
       5 
5 
     | 
    
         
             
              segments: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              - 0
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 1
         
     | 
| 
       8 
     | 
    
         
            -
              -  
     | 
| 
       9 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 8 
     | 
    
         
            +
              - 2
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: 0.1.2
         
     | 
| 
       10 
10 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       11 
11 
     | 
    
         
             
            authors: 
         
     | 
| 
       12 
12 
     | 
    
         
             
            - Andrew Liu
         
     | 
| 
         @@ -14,7 +14,7 @@ autorequire: 
     | 
|
| 
       14 
14 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       15 
15 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
            date: 2011-01- 
     | 
| 
      
 17 
     | 
    
         
            +
            date: 2011-01-24 00:00:00 +08:00
         
     | 
| 
       18 
18 
     | 
    
         
             
            default_executable: eggsh
         
     | 
| 
       19 
19 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       126 
126 
     | 
    
         
             
              requirements: 
         
     | 
| 
       127 
127 
     | 
    
         
             
              - - ">="
         
     | 
| 
       128 
128 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       129 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 129 
     | 
    
         
            +
                  hash: -1614003115125705715
         
     | 
| 
       130 
130 
     | 
    
         
             
                  segments: 
         
     | 
| 
       131 
131 
     | 
    
         
             
                  - 0
         
     | 
| 
       132 
132 
     | 
    
         
             
                  version: "0"
         
     |