-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathds
executable file
·80 lines (66 loc) · 2.33 KB
/
ds
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
#!/usr/bin/env python
# Program to draw separators between commands
# I made this because I often type commands which have many pages of
# output. The separators make it easy to see where the command started.
# Pass -n as the first argument to print a banner and not actually
# execute the command.
# Dependencies:
# ansicolors (https://pypi.org/project/ansicolors)
# Author: David McClosky
# Homepage: http://zorglish.org
# Code: http://github.com/dmcc
import sys, os
import colors
# lifted from http://pdos.csail.mit.edu/~cblake/cls/cls.py
# --------------------------------------------------------
env = os.environ
def ioctl_GWINSZ(fd): #### TABULATION FUNCTIONS
try: ### Discover terminal width
import fcntl, termios, struct, os
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
except:
return None
return cr
def terminal_size(): ### decide on *some* terminal size
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) # try open fds
if not cr: # ...then ctty
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr: # env vars or finally defaults
try:
cr = (env['LINES'], env['COLUMNS'])
except:
cr = (25, 80)
return int(cr[1]), int(cr[0]) # reverse rows, cols
# --------------------------------------------------------
termwidth, termheight = terminal_size()
symbol = '#'
# Very basic option parsing.
args = sys.argv[1:]
if args and args[0] == '-n':
run_command = False
args.pop(0)
else:
run_command = True
command = ' ' + ' '.join(args) + ' '
if not command.strip():
command = ''
command_len = len(command)
remaining = termwidth - command_len
bar = colors.color(symbol * termwidth, fg='red')
left = symbol * (remaining // 2)
right = left
# if odd number of characters, put the extra # on the right
if remaining % 2 == 1:
right += symbol
print(bar)
print(''.join((colors.color(left, fg='red'),
colors.color(command, style='bold'),
colors.color(right, fg='red'))))
print(bar)
if command and run_command:
sys.exit(os.system(command))