forked from pixelb/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinpy
More file actions
executable file
·83 lines (73 loc) · 2.4 KB
/
inpy
File metadata and controls
executable file
·83 lines (73 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python -i
# Enhance introspection at the python interactive prompt.
# This is a very simple alternative to ipython
# whose default settings I don't like.
# License: LGPLv2
# Notes:
# You can run it directly, or call it like:
# PYTHONSTARTUP=~/path/to/inpy python
# Changes:
# V0.1 09 Sep 2008 Initial release
# V0.4 22 Sep 2016
# http://github.com/pixelb/scripts/commits/master/scripts/inpy
import errno, os, sys
class _readline:
history=os.path.join(os.environ['HOME'],'.inpy_history')
import readline
# turn on tab completion
if 'libedit' in readline.__doc__: # OSX
readline.parse_and_bind ("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
import rlcompleter
def __init__(self):
try:
self.readline.read_history_file(self.history)
except (IOError, OSError), value:
if value.errno == errno.ENOENT:
pass
else:
raise
def __del__(self):
self.readline.write_history_file(self.history)
_rl=_readline()
# The following exits on Ctrl-C
def _std_exceptions(etype, value, tb):
sys.excepthook=sys.__excepthook__
if issubclass(etype, KeyboardInterrupt):
sys.exit(0)
else:
sys.__excepthook__(etype, value, tb)
sys.excepthook=_std_exceptions
#try to import dire() and ls()
#See http://www.pixelbeat.org/libs/dir_patt.py
# Note if $PYTHONPATH is not set then you can
# import from arbitrary locations like:
# import sys,os
# sys.path.append(os.environ['HOME']+'/libs/')
try:
from dir_patt import *
except:
pass
#pprint.pprint() doesn't put an item on each line
#even if width is small? See also:
#http://code.activestate.com/recipes/327142/
#also from reddit:
# ppdict = lambda d:"\n".join(map("%s: %s".__mod__, d.items()))
def ppdict(d):
"""Pretty Print for Dicts"""
print '{'
keys=d.keys()
keys.sort()
for k in keys:
spacing=" " * (16-(len(repr(k))+1))
print "%s:%s%s," % (repr(k),spacing,repr(d[k]))
print '}'
#From Ned Batchelder. Support pasting of multiline code
#Ctrl-d to end input
def paste():
exec(sys.stdin.read(), globals())
if 0: # Show info on startup
sys.stderr.write("Python %s\n" % sys.version.split('\n')[0])
sys.stderr.write("Tab completion on. Available items: %s\n" %
sorted(filter(lambda n: not n.startswith('_'), locals())))