-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyrc
68 lines (50 loc) · 1.34 KB
/
pyrc
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
#! /usr/bin/python3
'''
Python boilerplate imports and definition in order
to start the python interpreter console with basic
cmd definitions
'''
# Usage: launch python shell with `/usr/bin/python3 -i ~/.pyrc`
import os
import sys
import re
class clear(object):
'''
something to clear the python interpreter console
usage: >>> clear
'''
def __repr__(self):
os.system('cls' if os.name == 'nt' else 'clear')
#clear = lambda: os.system('cls' if os.name == 'nt' else 'clear')
return ''
c = clear = clear()
class exit(object):
'''
something to exit the python interpreter console
usage: >>> exit
'''
exit = exit # original object
def __repr__(self):
self.exit() # call original
return ''
quit = q = exit = exit()
class Prompt:
'''
define python shell prompt
'''
def __str__(self):
pwd_text = os.getcwd()
short_pwd_text = re.search(r"/[^/]+/[^/]+/[^/]+$", pwd_text)
if short_pwd_text:
short_pwd_text = short_pwd_text.group(0)
if not short_pwd_text:
pass
elif len(pwd_text) > len(short_pwd_text) + 3:
pwd_text = '...' + short_pwd_text
else:
pass
return '%s> ' % pwd_text
prompt = Prompt()
sys.ps1 = '\x1b[33m' + str(prompt) + '\x1b[0m'
del sys
del Prompt