|
@@ -1,31 +1,63 @@
|
|
|
|
|
+#!/usr/bin/env python
|
|
|
import sys
|
|
import sys
|
|
|
import os
|
|
import os
|
|
|
import readline
|
|
import readline
|
|
|
import subprocess
|
|
import subprocess
|
|
|
|
|
+from plumbum import local
|
|
|
|
|
|
|
|
def vi():
|
|
def vi():
|
|
|
subprocess.call('vi')
|
|
subprocess.call('vi')
|
|
|
|
|
|
|
|
-possibles = globals().copy()
|
|
|
|
|
-possibles.update(locals())
|
|
|
|
|
|
|
+def ll(*args):
|
|
|
|
|
+ print local['ls']['-la']()
|
|
|
|
|
+
|
|
|
|
|
+# is a builtin
|
|
|
|
|
+def cd(*args):
|
|
|
|
|
+ # TODO: no param, go to home
|
|
|
|
|
+ # param is - : go back
|
|
|
|
|
+ print args
|
|
|
|
|
+ if len(args) == 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:]
|
|
|
|
|
+ possibles = globals().copy()
|
|
|
|
|
+ possibles.update(locals())
|
|
|
|
|
+ method = possibles.get(command)
|
|
|
|
|
+ if method:
|
|
|
|
|
+ method(parameters)
|
|
|
|
|
+ return True
|
|
|
|
|
+ print 'Did not detect a function by that name'
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def as_plumbum(string):
|
|
|
|
|
+ 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]()
|
|
|
|
|
|
|
|
while True:
|
|
while True:
|
|
|
- input_string = raw_input('$ ')
|
|
|
|
|
- method = possibles.get(input_string)
|
|
|
|
|
- if not method:
|
|
|
|
|
|
|
+ input_string = raw_input(local.cwd + ' >> ')
|
|
|
|
|
+
|
|
|
|
|
+ # was the string a regular line of python?
|
|
|
|
|
+ if exec_if_builtin(input_string) is not True:
|
|
|
try:
|
|
try:
|
|
|
-
|
|
|
|
|
- print subprocess.check_output(input_string)
|
|
|
|
|
|
|
+ exec(input_string)
|
|
|
except:
|
|
except:
|
|
|
- print "Method was not implemented, tryed built-in"
|
|
|
|
|
- print 'Exec failed:', input_string
|
|
|
|
|
-
|
|
|
|
|
- else:
|
|
|
|
|
- method()
|
|
|
|
|
-
|
|
|
|
|
- try:
|
|
|
|
|
- pass
|
|
|
|
|
- #exec(test)
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ as_plumbum(input_string)
|
|
|
|
|
+ except:
|
|
|
|
|
+ print 'command not found:', input_string
|
|
|
|
|
|
|
|
- except:
|
|
|
|
|
- print 'Execution error'
|
|
|