""" smash_dwim:

     SmaSh do-what-i-mean plugin allows "execution" of directories by
     changing directory to them.  In fact 'pushd' is used, so you can
     use 'popd' to get back to where you came from.

"""

import os
import commands

from IPython.ipapi import TryNext
from smashlib.smash_plugin import SmashPlugin
from smashlib.util import report
from smashlib.python import isdir

EDITABLE_FILE_SIZE_THRESH = 32768

def is_executable(fpath):
    return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

def executable_dirs_hook(cmd):
    """ """
    cmd = cmd.strip()
    if cmd and cmd[0] in './' and isdir(cmd):
        report.plugin_dwim("entering: "+ cmd)
        return __IPYTHON__.magic_pushd(cmd)
    raise TryNext()

def is_small(fname):
    return os.path.getsize(fname) < EDITABLE_FILE_SIZE_THRESH

def editable_file_hook(cmd):
    report('yo trying')
    cmd = cmd.strip()
    if cmd and cmd[0] in './' and os.path.isfile(cmd):
        report('still')
        if not is_executable(cmd):
            report('still2')
            report.smash_dwim("file is not executable; attempting edit")
            if not is_small(cmd):
                report.smash_dwim("file too large, refusing to edit")
            else:
                return __IPYTHON__.magic_ed(cmd)
        else:
            pass #
    raise TryNext()

class Plugin(SmashPlugin):
    def install(self):
        self.add_hook('shell_hook', executable_dirs_hook, 0)
        self.add_hook('shell_hook', editable_file_hook, 0)

@@ -53,71 +53,66 @@
 lows
- %22execution%22 of directories by%0A     changing directory to them.
+:%0A%0A      *  directory-execution: (by cd'ing there)%0A       
   In
@@ -148,17 +148,27 @@
  can
+ always use
 %0A     
-use
+  
  'po
@@ -208,16 +208,98 @@
  from.%0A%0A
+      * auto-edit for filenames:%0A        if you type in the name of a file which%0A%0A
 %22%22%22%0A%0Aimp
@@ -374,72 +374,72 @@
 lib.
-smash_plugin import SmashPlugin%0Afrom smashlib.util import report
+util import report%0Afrom smashlib.smash_plugin import SmashPlugin
 %0Afro
@@ -934,32 +934,8 @@
 d):%0A
-    report('yo trying')%0A
     
@@ -1011,32 +1011,8 @@
 d):%0A
-        report('still')%0A
     
@@ -1046,37 +1046,8 @@
 d):%0A
-            report('still2')%0A
     
@@ -1292,32 +1292,216 @@
 )%0A        else:%0A
+            # this file is executable.  the user might want to%0A            # edit it, but we can't assume that because they%0A            # might want to execute it.  so, we do nothing.%0A
             pass
@@ -1500,18 +1500,16 @@
     pass
- #
 %0A    rai

fix DWIM behaviour for file-edit