-
Notifications
You must be signed in to change notification settings - Fork 2
/
cpycat.py
65 lines (54 loc) · 1.18 KB
/
cpycat.py
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
import sys
import pyperclip
import msvcrt as m
import time
def help():
print('''
| cpycat
|
/\_/\ | /\_/\
( -.o ) | ( -.o )
> ^ < | > ^ <
Copy to clipboard from pipe
default : Copy line by line
-a : To copy all, not line by line
-h : To print this
timeout : Automatic coping after timeout(sec)
cat urls.txt | cpycat 5
''')
sys.exit(0)
def sp():
time.sleep(timeout)
def copyallinput():
copytext = ''
for line in lines:
line = line.strip()
line = line.strip('\r')
copytext+=line+'\n'
pyperclip.copy(copytext)
def runit(func):
for line in lines:
line = line.strip()
if line != "":
print(line)
pyperclip.copy(line)
func()
timeout = 0
copyall = False
if len(sys.argv) > 1:
if sys.argv[1] == "-a":
copyall = True
elif sys.argv[1]=="-h":
help()
else:
timeout = int(sys.argv[1])
lines = []
for line in sys.stdin:
lines.append(line)
if not copyall:
if timeout == 0:
runit(m.getch)
else:
runit(sp)
else:
copyallinput()