|
@@ -5,7 +5,10 @@ import readline
|
|
|
import subprocess
|
|
|
from plumbum import local
|
|
|
|
|
|
-def vi():
|
|
|
+
|
|
|
+readline.parse_and_bind('tab:complete')
|
|
|
+
|
|
|
+def vi(*args):
|
|
|
subprocess.call('vi')
|
|
|
|
|
|
def ll(*args):
|
|
@@ -16,18 +19,17 @@ def cd(*args):
|
|
|
# TODO: no param, go to home
|
|
|
# param is - : go back
|
|
|
print args
|
|
|
- if len(args) == 0:
|
|
|
+ if len(args[0]) == 0:
|
|
|
args = '/home/woelper'
|
|
|
else:
|
|
|
args = args[0]
|
|
|
print 'cd to', args[0]
|
|
|
local.cwd.chdir(args[0])
|
|
|
|
|
|
-def exec_if_builtin(string):
|
|
|
- print 'STR', string
|
|
|
- string = string.split()
|
|
|
- command = string[0]
|
|
|
- parameters = string[1:]
|
|
|
+def exec_if_builtin(strlist):
|
|
|
+ print 'STR', strlist
|
|
|
+ command = strlist[0]
|
|
|
+ parameters = strlist[1:]
|
|
|
possibles = globals().copy()
|
|
|
possibles.update(locals())
|
|
|
method = possibles.get(command)
|
|
@@ -37,32 +39,71 @@ def exec_if_builtin(string):
|
|
|
print 'Did not detect a function by that name'
|
|
|
|
|
|
|
|
|
-def as_plumbum(string):
|
|
|
+def as_plumbum(strlist):
|
|
|
print 'Running cmd through plumbum'
|
|
|
# TODO: until pipe or special char
|
|
|
# split the string
|
|
|
- string = string.split()
|
|
|
#print string
|
|
|
- command = string[0]
|
|
|
- parameters = string[1:]
|
|
|
- print command, parameters
|
|
|
- print local[command][parameters]()
|
|
|
+ command = strlist[0]
|
|
|
+ parameters = strlist[1:]
|
|
|
+ #print command, parameters
|
|
|
+ try:
|
|
|
+ print local[command][parameters]()
|
|
|
+ except:
|
|
|
+ print 'Could not execute command'
|
|
|
|
|
|
-# line for line
|
|
|
-while True:
|
|
|
-
|
|
|
-
|
|
|
+def as_python(string):
|
|
|
+ print 'running native python code'
|
|
|
+ exec(string)
|
|
|
+ try:
|
|
|
+ exec(string)
|
|
|
+ except:
|
|
|
+ print 'error in command'
|
|
|
+
|
|
|
+def get_exec_method(string):
|
|
|
+ # native : assignments
|
|
|
+ # '=' is in first command or equals second
|
|
|
+ exec(input_string)
|
|
|
"""
|
|
|
+ strlist = string.split()
|
|
|
+ if '=' in strlist[0]:
|
|
|
+ exec(string)
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ if len(strlist) > 1:
|
|
|
+ if '=' in strlist[1]:
|
|
|
+ exec(string)
|
|
|
+ return
|
|
|
|
|
|
- input_string = raw_input(local.cwd + ' >> ')
|
|
|
-
|
|
|
- # was the string a regular line of python?
|
|
|
- if exec_if_builtin(input_string) is not True:
|
|
|
+ if not exec_if_builtin(strlist):
|
|
|
+ exec(string)
|
|
|
try:
|
|
|
- exec(input_string)
|
|
|
+ exec(string)
|
|
|
except:
|
|
|
+ print 'probably NOT native code.'
|
|
|
+ """
|
|
|
+
|
|
|
+def is_assignment(strlist):
|
|
|
+ if '=' in strlist[0]:
|
|
|
+ return True
|
|
|
+ if len(strlist) > 1:
|
|
|
+ if '=' in strlist[1]:
|
|
|
+ return True
|
|
|
+
|
|
|
+# line for line
|
|
|
+while True:
|
|
|
+ # we need to exec here so definitions stay global
|
|
|
+ input_string = raw_input(local.cwd + ' $ ')
|
|
|
+
|
|
|
+ #if get_exec_method(input_string)
|
|
|
+ strlist = input_string.split()
|
|
|
+ if is_assignment(strlist):
|
|
|
+ exec(input_string)
|
|
|
+
|
|
|
+ else:
|
|
|
+ if not exec_if_builtin(strlist):
|
|
|
try:
|
|
|
- as_plumbum(input_string)
|
|
|
+ exec(input_string)
|
|
|
except:
|
|
|
- print 'command not found:', input_string
|
|
|
- """
|
|
|
+ print 'probably NOT native code.'
|
|
|
+ as_plumbum(strlist)
|