1
0

me.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #-*- coding: UTF-8 -*-
  2. import sys, os, readline
  3. # https://git.io/me.py
  4. # Windows Usage: python -m pip install pyreadline
  5. # define Color
  6. Green = '\033[32m'; Red = '\033[31m'; GreenBG = '\033[42;37m'; RedBG = '\033[41;37m'
  7. Yellow = '\033[0;33m'; SkyBlue = '\033[0;36m'; Font = '\033[0m'
  8. sys.ps1 = Red + '>' + Yellow + '>' + SkyBlue + '> ' + Font
  9. sys.ps2 = SkyBlue + '... ' + Font
  10. if (os.sep != '/'): # Is Not Linux
  11. Green = Red = GreenBG = RedBG = Yellow = SkyBlue = Font = ''
  12. def cls():
  13. if (os.sep == '/'): os.system('clear')
  14. else: os.system('cls')
  15. def pwd():
  16. print( SkyBlue + os.getcwd(), end = ' ')
  17. def ls():
  18. cur_path = os.getcwd()
  19. if (os.sep == '/'): os.system('ls -l ' + cur_path)
  20. else: os.system('dir ' + cur_path)
  21. pwd()
  22. def cd(path = '.'):
  23. os.chdir(path); pwd()
  24. def cat(file = 'me.py'):
  25. with open(file, 'r') as f:
  26. print(f.read())
  27. def bash():
  28. os.system('bash')
  29. def history():
  30. for i in range(readline.get_current_history_length()):
  31. print(readline.get_history_item(i + 1))
  32. print( Yellow + ':: Clear_History: readline.clear_history() ')
  33. def info():
  34. print( SkyBlue + ':: Usage: ' + Green + 'python -i me.py' + Yellow + ' or [import me] , import the module me.py')
  35. print( Green + ':: Function: cls() ls() cd(path) cat(file) pwd() bash() info() history()')
  36. pwd()
  37. cls(); info(); c = cls; h = history