+ # In Python 2.5+ exit and quit are objects
+ if isinstance(__builtin__.exit, str):
+ __builtin__.exit = __builtin__.quit = x # noqa: x is defined as _Exit
+
+ # print conten of a file
+
+ 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()
+
+ # call shell
+
+ class _Sh:
+ def __repr__(self):
+ os.system(os.environ["SHELL"])
+ return ''
+
+ def __call__(self, cmdline):
+ os.system(cmdline)
+
+ __builtin__.sh = _Sh()
+
+ # paginate a file
+
+ 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()
+
+ # edit a file
+
+ 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()