123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #!/usr/bin/env python
- import sys
- import os
- import readline
- import subprocess
- from plumbum import local
- readline.parse_and_bind('tab:complete')
- def vi(*args):
- subprocess.call('vi')
- 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]) == 0:
- args = '/home/woelper'
- else:
- args = args[0]
- print 'cd to', args[0]
- local.cwd.chdir(args[0])
- def exec_if_builtin(strlist):
- print 'STR', strlist
- command = strlist[0]
- parameters = strlist[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(strlist):
- print 'Running cmd through plumbum'
- # TODO: until pipe or special char
- # split the string
- #print string
- command = strlist[0]
- parameters = strlist[1:]
- #print command, parameters
- try:
- print local[command][parameters]()
- except:
- print 'Could not execute command'
- 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
-
- if not exec_if_builtin(strlist):
- exec(string)
- try:
- 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:
- exec(input_string)
- except:
- print 'probably NOT native code.'
- as_plumbum(strlist)
|