pshell 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. import sys
  3. import os
  4. import readline
  5. import subprocess
  6. from plumbum import local
  7. def vi():
  8. subprocess.call('vi')
  9. def ll(*args):
  10. print local['ls']['-la']()
  11. # is a builtin
  12. def cd(*args):
  13. # TODO: no param, go to home
  14. # param is - : go back
  15. print args
  16. if len(args) == 0:
  17. args = '/home/woelper'
  18. else:
  19. args = args[0]
  20. print 'cd to', args[0]
  21. local.cwd.chdir(args[0])
  22. def exec_if_builtin(string):
  23. print 'STR', string
  24. string = string.split()
  25. command = string[0]
  26. parameters = string[1:]
  27. possibles = globals().copy()
  28. possibles.update(locals())
  29. method = possibles.get(command)
  30. if method:
  31. method(parameters)
  32. return True
  33. print 'Did not detect a function by that name'
  34. def as_plumbum(string):
  35. print 'Running cmd through plumbum'
  36. # TODO: until pipe or special char
  37. # split the string
  38. string = string.split()
  39. #print string
  40. command = string[0]
  41. parameters = string[1:]
  42. print command, parameters
  43. print local[command][parameters]()
  44. # line for line
  45. while True:
  46. """
  47. input_string = raw_input(local.cwd + ' >> ')
  48. # was the string a regular line of python?
  49. if exec_if_builtin(input_string) is not True:
  50. try:
  51. exec(input_string)
  52. except:
  53. try:
  54. as_plumbum(input_string)
  55. except:
  56. print 'command not found:', input_string
  57. """