Commits

seydar committed 86b6b8b

fixed issues with procs in pipes. proc#[] is no longer viable. updated sample.txt. updated announcement

  • Participants
  • Parent commits 4b0ac99

Comments (0)

Files changed (10)

File ANNOUNCEMENT

+chitin
+========================
+by Ari Brown
+http://bitbucket.org/seydar/chitin
+
 Hai everybahdy
 
-Let's talk about the shell you're using real quick. It's most likely bash. Or
-at least it's bash-esque. There are a few hipsters among us who are using fish
-or zsh or whatever. A few of the older persuasion are into csh and tcsh.
-But that's not the point. The point is you're on a Ruby mailing list but you're
-not using a Ruby shell. It's time to upgrade. It's time to upgrade your shell
-to Chitin. I hope you all get the joke. I made it myself. The joke and the shell.
-
 == So what IS Chitin?
 
 * Chitin is a Ruby interpreter
 * Turned into a shell.
 
+I hope you all get the joke. I made it myself. The joke and the shell.
+
 Everything you type is Ruby -- remember that. So let's look at it in action:
 
-  ari: ~/src/chitin % 4 + 5
+  % 4 + 5
    => 9
 
 Boom. "Show me more!" Ok, but only because you asked so nicely:
 
-  ari: ~/src/chitin % ls
+  % ls
   ANNOUNCEMENT  README    TODO    bin   chitin-1.0.gem  chitin.gemspec
   chitinrc      lib       sample.txt
-  ari: ~/src/chitin % hg.stat | wc | proc {|i| i.read.size } > '/tmp/test.out'
-  ari: ~/src/chitin %
-
-Holy Batman! Yeah, waddap, git on mah level. I don't even know why you'd want
-to run that last command, but thar ya go.
-
-It's supposed to replace your current shell. Now OBVIOUSLY, you're not going
-to replace the entirety of the bash infrastructure that exists in computing and
-has existed for like 40 years since the dinosaurs first walked the Earth, but
-it's a start. It's just supposed to be for personal use.
+  % hg.stat | wc | proc {|i| i.read.size } > '/tmp/test.out'
+  %
 
 == Why use it?
 
   * The command utility of a shell in Ruby
   * No underlying shell usage
   * A much more programmatic shell
+  * Sweet tab completion
+  * You can set key bindings to arbitrary keys
   * Prevents against accidental `rm -rf /usr /local/bin` like that one thing
     we all saw on Reddit.
   * Makes for a great Christmas present
 Rules of the road:
 
   * Everything you enter is pure Ruby. When you type, you are typing pure Ruby.
-  * When in doubt of what something is: use #inspect by doing obj[:inspect]
+  * When in doubt of what something is: use #inspect by doing command[:inspect]
   * #[] allows you to run methods of Executables, Pipes, and StringMethods
     without accidentally running them.
 
 *   output silencing
     -> learn to fake being an IO
     -> shit won't work until then
-*   get consistent on what methods needs #[] and what methods don't
 
 FAILURES:
 *   cursor display issues with the menu
 *   Are there any ANSI codes for deleting part of a line? Yes. Duh. But what
     are they?
 
+RELEASE
+*   get NULLIN, NULLOUT, and NULLERR working
+*   figure out what doesn't work with STDERR
+

File lib/chitin/commands/executable.rb

       @args = process_args(args)
     end
   
+    def |(other)
+      Pipe.new self, other
+    end
+    alias_method :<=>, :|
+  
+    # EVERYTHING will be sent to the command. ERRTHANG!!!!
+    def method_missing(name, *arr, &blk)
+      setup name.to_s, *process_args(arr)
+      self
+    end
+
+    private
+
+    attr_accessor :args
+    attr_accessor :path
+    attr_accessor :pid
+  
     def process_args(args)
       processed = args.map do |arg|
         if arg.is_a? Hash
   
       processed.flatten
     end
-  
-    # EVERYTHING will be sent to the command. ERRTHANG!!!!
-    def method_missing(name, *arr, &blk)
-      setup name.to_s, *process_args(arr)
-      self
-    end
-  
-    def |(other)
-      Pipe.new self, other
-    end
-    alias_method :<=>, :|
-  
-    private
-  
-    attr_accessor :args
-    attr_accessor :path
-  
+
     def args
       @args ||= []
     end
-  
-    attr_reader :pid
-  
+
     # prep the executable to run with the arguments +subc+ and +args+
     def setup(subc, *arr)
       # we have to use +@args+ here because otherwise we'd have to use the +=

File lib/chitin/commands/pipe.rb

       r, w = IO.pipe
   
       # since left will want to write to STDOUT, we have to give it
-      # something it can write to.
+      # something else it can write to.
       left > w
+
       # same thing for right, but with reading
       r > right
   
-  
       # right will try to read from r until w is closed.
       # when w is closed, right will finish processing.
       # if we don't close this, right will never return

File lib/chitin/commands/ruby.rb

     def |(other)
       Pipe.new self, other
     end
-  
+
+    def method_missing(*arr, &block)
+      latest  = [*arr]
+      latest << block if block
+      @chains << latest
+      self # chainable
+    end
+
+    private
+
     def result
       val = self[:in].read
       @chains.each do |arr|
       val
     end
   
-    def method_missing(*arr, &block)
-      latest  = [*arr]
-      latest << block if block
-      @chains << latest
-      self # chainable
-    end
-  
     # this is runs the method on the input
     # and then writes the output to self.out
     # used in piping
 end
 
 class Proc
+  # So let's quick chat about what including Runnable to a proc means.
+  # It means that it can be chained with pipes.
+  # It also means that you can run private methods with #[].
+  # The important thing isn't that you can run private methods. You could
+  # do that since the beginning of time.
+  # The take-away is that it OVERRIDES #[]. In the words of Joe Biden,
+  # this is a big fucking deal.
+  #
+  # whatdo.jpg
+  #
+  # This means that you cannot, in the environment of Chitin, use
+  # Proc#[] for anything other than accessing private methods. This
+  # means it does not play well with others. This is what we in the biz
+  # call bad.
+  undef_method :[]
   include Chitin::Runnable
 
+  # # access private methods
+  # def [](*args)
+  #   if method(args.first)
+  #     method(args.first).call *args[1..-1]
+  #   else
+  #     raise NoMethodError.new("undefined method" +
+  #                             "`#{args.first}' for #{self}:#{self.class}")
+  #   end
+  # end
+
   def |(other)
     Pipe.new self, other
   end
 
+  private
+
   def run
     child = fork do
       self.out.puts call(self.in)

File lib/chitin/commands/runnable.rb

 module Chitin
   module Runnable
 
-    attr_accessor :bg
-    attr_accessor :in
-    attr_accessor :out
-    attr_accessor :err
-
     def >(io)
       case io
       when IO, File
     end
   
     private
+
+    attr_accessor :bg
+    attr_accessor :in
+    attr_accessor :out
+    attr_accessor :err
   
     # Generally the same as +run+, except for the ruby commands
     # they return real ruby that can be given back to the user.

File lib/chitin/session.rb

           res = evaluate val
           display res unless val.lstrip[0, 1] == '#'
         rescue StandardError, ScriptError, Interrupt => e
-          @config.post_processing[e.class][e, val]
+          @config.post_processing[e.class].call e, val
   
           print e.backtrace.first, ': '
           puts "#{e.message} (#{e.class})"
   
         unless res.is_a? Pipe
           # RUBY values pass through here
-          txt = @config.post_processing[:color][res.inspect]
+          txt = @config.post_processing[:color].call res.inspect
           puts " => #{txt}"
         else
           # set up the inputs and outputs
           # Thus, we have to use #stat (or, more lamely, #inspect).
           if res[:out].stat == STDOUT.stat
             val = res[:raw_run]
-            txt = @config.post_processing[:color][val.inspect]
+            txt = @config.post_processing[:color].call val.inspect
             puts " => #{txt}"
           else
             res[:run]

File lib/chitin/version.rb

 module Chitin
-  VERSION = 1.0
+  VERSION = '1.0.1'
 end
 
   val = val.strip == '..' ? 'cd ".."' : val
 end
 
-pre_process do |val|
-  # if there is an unclosed string, close it and run it again.
-  # smart compilers are bad... but this ain't a compiler
-  #
-  # option: make it ask for confirmation first
-  # settable in chitinrc, perjaps?
-  if (e = syntax_error_for(val)) &&
-     e.message =~ /unterminated string meets end of file/
-
-    if syntax_error_for(val + '\'')
-      unless syntax_error_for(val + '"')
-        val << '"'
-      end
-    else
-      val << '\''
-    end
-
-  end
-
-  val
-end
-
-# You can use error classes as a name and if the error comes up,
-# block of code will be run.
-#
-# post_process SyntaxError do |e, val|
-#   # sample
-# end
-
-post_process :color do |val|
-  Wirble::Colorize.colorize val
-end
-
 ari: ~/src/chitin (... # I've got a shortcut there that allows me to do this:
 ari: ~/src/chitin (... ..
  => "/Users/ari/src"