X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=lib%2Fpython%2Finit.py;h=cc3b66be214e070336213d0d703fd40305b40fe4;hb=a35652e9895040987c1b13831c58afbaf652c8a2;hp=26692bbf3a77fd8ac1ec1c0ae7f5b95d8f485b62;hpb=10cf29fedbe60ef31c8917a08c6634f9a5bf45c8;p=dotfiles.git diff --git a/lib/python/init.py b/lib/python/init.py index 26692bb..cc3b66b 100644 --- a/lib/python/init.py +++ b/lib/python/init.py @@ -59,40 +59,42 @@ def init(): # From Randall Hopper - if _term in term: - if background == 'dark': - ps1_color = '3' # yellow - stdout_color = '7' # bold white - else: - ps1_color = '4' # blue - stdout_color = '0' # bold black for _term in ['linux', 'rxvt', 'screen', 'term', 'vt100']: + if _term not in term: + continue + + if background == 'dark': + ps1_color = '3' # yellow + stdout_color = '7' # bold white + else: + ps1_color = '4' # blue + stdout_color = '0' # bold black - sys.ps1 = '\001\033[3%sm\002>>>\001\033[0m\002 ' % ps1_color - sys.ps2 = '\001\033[1;32m\002...\001\033[0m\002 ' # bold green + sys.ps1 = '\001\033[3%sm\002>>>\001\033[0m\002 ' % ps1_color + sys.ps2 = '\001\033[1;32m\002...\001\033[0m\002 ' # bold green - # From Denis Otkidach + # From Denis Otkidach - class ColoredFile: - def __init__(self, fp, begin, end='\033[0m'): # reset all attributes - self.__fp = fp - self.__begin = begin - self.__end = end + class ColoredFile: + def __init__(self, fp, begin, end='\033[0m'): # reset all attributes + self.__fp = fp + self.__begin = begin + self.__end = end - def write(self, s): - self.__fp.write(self.__begin+s+self.__end) + def write(self, s): + self.__fp.write(self.__begin+s+self.__end) - def writelines(self, lines): - map(self.write, lines) + def writelines(self, lines): + map(self.write, lines) - def __getattr__(self, attr): - return getattr(self.__fp, attr) + def __getattr__(self, attr): + return getattr(self.__fp, attr) - sys.stdout = ColoredFile(sys.stdout, '\033[1;3%sm' % stdout_color) - sys.stderr = ColoredFile(sys.stderr, '\033[31m') # red + sys.stdout = ColoredFile(sys.stdout, '\033[1;3%sm' % stdout_color) + sys.stderr = ColoredFile(sys.stderr, '\033[31m') # red - break + break try: import locale @@ -181,5 +183,51 @@ def init(): __builtin__.exit = __builtin__.quit = x + class _Cat: + def __repr__(self): + return "Usage: cat('filename')" + + def __call__(self, filename): + fp = open(filename, 'rU') + text = fp.read() + fp.close() + print text + + __builtin__.cat = _Cat() + + + class _Sh: + def __repr__(self): + os.system(os.environ["SHELL"]) + return '' + + def __call__(self, cmdline): + os.system(cmdline) + + __builtin__.sh = _Sh() + + + class _Pager: + def __repr__(self): + return "Usage: pager('filename')" + + def __call__(self, filename): + pager = os.environ.get("PAGER") or 'more' + os.system("%s '%s'" % (pager, filename.replace("'", '"\'"'))) + + __builtin__.pager = _Pager() + + + class _Editor: + def __repr__(self): + return "Usage: edit('filename')" + + def __call__(self, filename): + editor = os.environ.get("VISUAL") or os.environ.get("EDITOR") or 'vi' + os.system("%s '%s'" % (editor, filename.replace("'", '"\'"'))) + + __builtin__.edit = __builtin__.editor = _Editor() + + init() del init