using python at the bash shell?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cga2000

    #16
    Re: using python at the bash shell?

    On Tue, Aug 15, 2006 at 06:45:33PM EDT, Simon Forman wrote:
    cga2000 wrote:
    [..]
    Why do you write "most commands" .. what type of command might not be
    run by "putting '!' before them?"
    >
    Well, I wrote that just to hedge my bets, but here's an example: I set
    up lesspipe and source-highlight to add syntax highlighting to various
    file types when viewed through less. But using "!less neat.py" in
    Ipython doesn't work because (I'm guessing here) Ipython doesn't handle
    the color escape codes. It winds up looking like this:
    >
    ESC[31m#!/usr/local/bin/python2.5ESC[m
    ESC[01;34mfromESC[m random ESC[01;34mimportESC[m random as f
    >
    >
    ESC[01;34mdefESC[m
    ESC[01;30mgESC[mESC[31m(ESC[mESC[31m)ESC[mESC[31m:ESC[m
    n1 ESC[31m=ESC[m ESC[01;30mfESC[mESC[31m(ESC[mESC[31m)ESC[m
    ESC[01;34mwhileESC[m TrueESC[31m:ESC[m
    n2 ESC[31m=ESC[m ESC[01;30mfESC[mESC[31m(ESC[mESC[31m)ESC[m
    yield n1 ESC[31m-ESC[m n2
    n1 ESC[31m=ESC[m n2
    >
    Ew.
    >
    So in this case I'd have to "!bash" then "less neat.py"...
    you could use "vim -R" -- or its alter ego "view" ..

    "!view neat.py"

    I tried that just now under ipython and I end up with the exact same
    syntax highlighting that I have when I run vim from the bash prompt.

    The problems I am having are mainly due to my bash customization --
    aliases, functions .. all that stuff is no longer being recognized ..
    and also some bash built-ins such as "cd" do not do anything .. maybe
    ipython starts a subprocess that switches and then immediately exits ..
    so when I get the prompt back I'm back where I started.

    I guess reading the ipython manual and trying to understand what I'm
    doing before going any further wouldn't hurt..

    :-)
    >
    In the linux world it would be rather interesting if a distro was
    available that uses nothing but python.

    The installer .. the startup scripts .. utilities .. etc.

    Maybe there is such a thing and I'm just not aware of it?
    >
    IMHO it would be neat, but it'd be kind of a "stunt". There's a ton
    of excellent code in most any linux distro *not* written in python.
    >
    quite a large project, I would imagine.
    Since it would be byt-code being executed it would be faster than
    regular shell stuff and a lot easier to customize/maintain.
    >
    Mmmm... I bet it'd be hard to beat, say, grep... Or any of the
    small, custom-purpose C-coded tools. (then there's make... gcc...
    not easy to rewrite those.. just off the top of my head...)
    >
    Sorry .. couldn't think of a better word .. but by "utilities" I meant
    all those shell scripts in /usr/bin that come with gnu/linux distros and
    mostly appear to front-end "real" programs.

    I guess a python "system shell" could invoke all the C-coded stuff the
    same way bash does, no..?

    'nuff [OT] for now..

    Thanks,

    cga

    Comment

    • Marc 'BlackJack' Rintsch

      #17
      Re: using python at the bash shell?

      In <mailman.9403.1 155709688.27775 .python-list@python.org >, cga2000 wrote:
      and also some bash built-ins such as "cd" do not do anything .. maybe
      ipython starts a subprocess that switches and then immediately exits ..
      so when I get the prompt back I'm back where I started.
      If you put a ``!`` in front of ``cd`` this is what happens. Just leave
      out the ``!``. IPython has it's own built-in ``cd`` command.

      Ciao,
      Marc 'BlackJack' Rintsch

      Comment

      Working...