-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeid
executable file
·42 lines (33 loc) · 988 Bytes
/
makeid
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
#!/usr/bin/python3
import datetime
import os.path
import random
import string
import subprocess
import sys
HOME = os.path.expanduser('~')
DEFAULT_LENGTH = 20
def makeid(len):
if '-h' in sys.argv:
return ''.join(
random.choice('abcdef' + string.digits) for i in range(len)
)
return ''.join(random.choice(
string.ascii_lowercase + string.digits) for i in range(len))
if __name__ == "__main__":
length = DEFAULT_LENGTH
for i in sys.argv:
try:
if type(int(i)) == int:
length = int(i)
except Exception:
pass
this_id = makeid(length)
print(this_id)
proc = subprocess.Popen(
["xclip", "-i", "-selection", "clipboard"], stdin=subprocess.PIPE
)
proc.communicate(this_id.encode("ascii"))
with open(HOME + '/.makeid_history', 'a') as f:
f.write('[{}] ({}) {}\n'.format(
datetime.datetime.now().isoformat(), sys.argv[1], this_id))