]> git.phdru.name Git - dotfiles.git/blobdiff - lib/python/init.py
init.py: restore links to the origin of borrowed code
[dotfiles.git] / lib / python / init.py
index d835c1c9a39b78edc9946c54dc31f688a3fb4b4b..44aebe49725066875ba2aa146f619a3e973f7c02 100644 (file)
@@ -18,7 +18,8 @@ def init():
         execfile(pyreadlinew32_startup)
 
     else:
-        # From Bruce Edge
+        # From Bruce Edge:
+        # https://mail.python.org/pipermail/python-list/2001-March/062888.html
 
         try:
             import rlcompleter, readline
@@ -57,7 +58,8 @@ def init():
     else:
         background = os.environ.get('BACKGROUND', 'light').lower()
 
-    # From Randall Hopper
+    # From Randall Hopper:
+    # https://mail.python.org/pipermail/python-list/2001-March/112696.html
 
     for _term in ['linux', 'rxvt', 'screen', 'term', 'vt100']:
         if _term not in term:
@@ -117,7 +119,9 @@ def init():
             pass # no locale support or unsupported locale
 
 
-    # From: Paul Magwene with a lot of my fixes
+    # From: Paul Magwene:
+    # https://mail.python.org/pipermail/python-list/2001-March/086191.html
+    # With a lot of my fixes:
 
     class DirLister:
         def __getitem__(self, key):
@@ -150,6 +154,8 @@ def init():
     __builtin__.ls = DirLister()
     __builtin__.cd = DirChanger()
 
+    # From Thomas Heller:
+    # https://mail.python.org/pipermail/python-list/2001-April/099020.html
 
     # From Thomas Heller
     #
@@ -183,5 +189,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