X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=lib%2Fpython%2Finit.py;h=cc3b66be214e070336213d0d703fd40305b40fe4;hb=e991ec16828b262c0e90677d6ba9f258d81b6b9c;hp=d835c1c9a39b78edc9946c54dc31f688a3fb4b4b;hpb=dc16915c13154ea56c4700c3cf2366788e202bd9;p=dotfiles.git diff --git a/lib/python/init.py b/lib/python/init.py index d835c1c..cc3b66b 100644 --- a/lib/python/init.py +++ b/lib/python/init.py @@ -183,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