Skip to content

Commit 3804323

Browse files
committed
add pbpaste, pbcopy, delclip, showip command.
1 parent ef39d5f commit 3804323

File tree

1 file changed

+115
-13
lines changed

1 file changed

+115
-13
lines changed

pipTerminal.py

Lines changed: 115 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
"""Pythonista3 Console Terminal"""
44

5-
import code, console, os, re, shutil, socket, sys, urllib.request, time, tarfile, zipfile, urllib.parse, ssl, requests
5+
import code, console, clipboard, concurrent.futures, os, objc_util, re, shutil, socket, sys, urllib.request, time, tarfile, zipfile, urllib.parse, ssl, socket, requests, ui
66
from console import set_color as setColor
77
from lib2to3.main import main as _2to3_main
88
from io import BytesIO
99
from platform import python_version
1010
from platform import node as hostname
1111
from urllib.error import URLError
12+
from io import StringIO
1213

1314
ssl._create_default_https_context = ssl._create_unverified_context
1415

@@ -39,7 +40,7 @@ def __init__():
3940
def SystemLogo():
4041
clear()
4142
setColor(255, 0, 0) # red
42-
return "{}\n| - pyTerminal v2.0.7 on Python {}\t\t\t|\n| - Author: DarkRix.\t\t\t\t\t\t|\n| - Show All Command: help\t\t\t\t\t|\n{}\n\n".format("-"*41, python_version(), "-"*41)
43+
return "{}\n| - pyTerminal v2.0.8 on Python {}\t\t\t|\n| - Author: DarkRix.\t\t\t\t\t\t|\n| - Show All Command: help\t\t\t\t\t|\n{}\n\n".format("-"*41, python_version(), "-"*41)
4344

4445
def Argument_Paser(Args):
4546
setColor()
@@ -53,6 +54,10 @@ def Argument_Paser(Args):
5354
print("Usage: cp [-h] source [source ...] dest")
5455
if Args[1] == '-h' and Args[0] == 'echo':
5556
print("Usage: echo [-h]\n\nPrint All arguments to stdout, separated by space")
57+
if Args[1] == '-h' and Args[0] == 'delclip':
58+
print('Delete Clipboard')
59+
if Args[1] == '-h' and Args[0] == 'showip':
60+
print('Show you are Local iP Adress')
5661
if Args[1] == '-h' and Args[0] == 'git':
5762
print('Usage: git clone <url> [path] - clone a remote repository')
5863
if Args[1] == '-h' and Args[0] == 'la':
@@ -83,7 +88,7 @@ def Argument_Paser(Args):
8388
pass
8489
try:
8590
if Args[0] == 'help':
86-
print('[Default commands]:\nhelp, 2to3, cat, cd, echo, env, git(clone only), la, ls, ln, mkdir, open, ping, rm, tar, uznip, wget, zip, python, python3, exit\n\n[Third Party commands]:\n' + list_other_cmd() + '\n\n[Stash Extensions Commands]:\n' + list_stash_bin())
91+
print('[Default commands]:\nhelp, 2to3, cat, cd, echo, env, git(clone only), la, ls, ln, mkdir, open, ping, rm, tar, uznip, wget, zip, python, python3, pbcopy, pbpaste, delclip, showip, exit\n\n[Third Party commands]:\n' + list_other_cmd() + '\n\n[Stash Extensions Commands]:\n' + list_stash_bin())
8792
elif Args[0] == 'cat':
8893
try:
8994
if not Args[1] == '-h':
@@ -95,8 +100,34 @@ def Argument_Paser(Args):
95100
_2to3(Args[1:])
96101
except:
97102
pass
103+
elif Args[0] == 'pbcopy':
104+
try:
105+
try:
106+
clipboard.set(b'\x00\x00')
107+
except:
108+
pass
109+
concurrent.futures.ThreadPoolExecutor().submit(clipboard.set, str(Args[1]))
110+
except:
111+
pass
112+
elif Args[0] == 'pbpaste':
113+
try:
114+
print(clipboard.get())
115+
except:
116+
pass
117+
elif Args[0] == 'delclip':
118+
concurrent.futures.ThreadPoolExecutor().submit(clipboard.set, '')
119+
elif Args[0] == 'showip':
120+
try:
121+
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
122+
s.connect(('8.8.8.8', 80))
123+
print('You are Local iP: {}'.format(s.getsockname()[0]))
124+
except:
125+
pass
98126
elif Args[0] == 'cd':
99127
try:
128+
if '$' in Args[1] and '/' in Args[1]:
129+
Arg1 = Args[1].replace('$', os.getenv(Args[1].split('$')[1].split('/')[0]))
130+
Args[1] = Args.replace(Args[1].split('$')[1].split('/')[0], '')
100131
if not Args[1] == '-h':
101132
try:
102133
try:
@@ -155,9 +186,9 @@ def Argument_Paser(Args):
155186
except IndexError:
156187
try:
157188
if not Args[1] == '':
158-
print(Args[1])
189+
pass
159190
except IndexError:
160-
print()
191+
pass
161192
except:
162193
pass
163194
elif Args[0] == 'env':
@@ -193,7 +224,8 @@ def Argument_Paser(Args):
193224
listdir('long', os.getcwd())
194225
except IndexError:
195226
listdir(None, None)
196-
except:
227+
except Exception as R:
228+
print(R)
197229
pass
198230
elif Args[0] == 'ln':
199231
try:
@@ -288,6 +320,9 @@ def Argument_Paser(Args):
288320
pass
289321
elif Args[0] == 'rm':
290322
try:
323+
if '$' in Args[1] and '/' in Args[1]:
324+
Arg1 = Args[1].replace('$', os.getenv(Args[1].split('$')[1].split('/')[0]))
325+
Args[1] = Args.replace(Args[1].split('$')[1].split('/')[0], '')
291326
if not Args[1] == '-h':
292327
if Args[1][0:] == './':
293328
try:
@@ -328,7 +363,7 @@ def Argument_Paser(Args):
328363
file_path = Args[1]
329364
py_file = open(file_path, 'r', encoding='utf-8').read()
330365
try:
331-
exec(py_file)
366+
exec(py_file, globals())
332367
except SystemExit:
333368
pass
334369
except:
@@ -338,6 +373,11 @@ def Argument_Paser(Args):
338373
code.interact()
339374
except SystemExit:
340375
pass
376+
except IndexError:
377+
try:
378+
code.interact()
379+
except SystemExit:
380+
pass
341381
except:
342382
pass
343383
elif Args[0] == 'python3':
@@ -350,14 +390,19 @@ def Argument_Paser(Args):
350390
file_path = Args[1]
351391
py_file = open(file_path, 'r', encoding='utf-8').read()
352392
try:
353-
exec(py_file)
393+
exec(py_file, globals())
354394
except:
355395
pass
356396
except:
357397
try:
358398
code.interact()
359399
except SystemExit:
360400
pass
401+
except IndexError:
402+
try:
403+
code.interact()
404+
except SystemExit:
405+
pass
361406
except:
362407
pass
363408
elif Args[0] == 'wget':
@@ -697,10 +742,16 @@ def listdir(arg, pwd):
697742
len_dir_lists = len(listdirs)
698743
for lis in range(len_dir_lists):
699744
if os.path.islink(os.path.join(pwd, listdirs[lis])):
700-
print('[%s] %s -> %s' % (time.strftime("%Y-%m-%d", time.localtime(os.stat(os.path.join(pwd, listdirs[lis])).st_mtime)),detect_file(listdirs[lis]), os.path.realpath(os.path.join(pwd, listdirs[lis])).replace(hOME, '~')))
745+
try:
746+
print('[%s] %s -> %s' % (time.strftime("%Y-%m-%d", time.localtime(os.stat(os.path.join(pwd, listdirs[lis])).st_mtime)),detect_file(listdirs[lis]), os.path.realpath(os.path.join(pwd, listdirs[lis])).replace(hOME, '~')))
747+
except:
748+
continue
701749
setColor()
702750
else:
703-
print('[%s] %s' % (time.strftime("%Y-%m-%d", time.localtime(os.stat(os.path.join(pwd, listdirs[lis])).st_mtime)),detect_file(listdirs[lis])))
751+
try:
752+
print('[%s] %s' % (time.strftime("%Y-%m-%d", time.localtime(os.stat(os.path.join(pwd, listdirs[lis])).st_mtime)),detect_file(listdirs[lis])))
753+
except:
754+
continue
704755
setColor()
705756
elif arg == None:
706757
try:
@@ -975,6 +1026,7 @@ def ZipArchiveCreate(ziPFilename, IPath):
9751026
ARCHIVE_NAME = os.path.join(TH_RELROOT, _Fi)
9761027
OutPutsZip.write(Fi_Name, arcname=ARCHIVE_NAME)
9771028

1029+
@ui.in_background
9781030
def main():
9791031
__init__()
9801032
print(SystemLogo())
@@ -998,15 +1050,65 @@ def main():
9981050
sys.exit(0)
9991051
print(Command_DIRNAME[2], end='', flush=True)
10001052
setColor()
1001-
INPUT_Argument = input('$ ').split(' ')
1002-
Argument_Paser(INPUT_Argument)
1053+
sys.stdout = BackupSTDOUT
1054+
INPUT_Argument = input('$ ')
1055+
if '|' in INPUT_Argument:
1056+
with StringIO() as St:
1057+
sys.stdout = St
1058+
Argument_Paser(INPUT_Argument.split('|')[0].split(' '))
1059+
INPUT_Arguments = [INPUT_Argument.replace(' ','').split('|')[1], St.getvalue().replace('\r', '').replace('\n', '')]
1060+
sys.stdout = BackupSTDOUT
1061+
concurrent.futures.ThreadPoolExecutor().submit(Argument_Paser, INPUT_Arguments)
1062+
elif '>>' in INPUT_Argument:
1063+
with StringIO() as St:
1064+
sys.stdout = St
1065+
INPUT_Arguments = INPUT_Argument.split('>')[0].split(' ')
1066+
concurrent.futures.ThreadPoolExecutor().submit(delelemnts, INPUT_Arguments).result()
1067+
Argument_Paser(INPUT_Arguments)
1068+
ArgV = St.getvalue()
1069+
sys.stdout = BackupSTDOUT
1070+
if '$' in INPUT_Argument.replace(' ', '').split('>>')[1]:
1071+
FileName = INPUT_Argument.replace(' ', '').split('>>')[1].replace('$', os.getenv(INPUT_Argument.replace(' ', '').split('>>')[1].split('$')[1].split('/')[0])).replace(INPUT_Argument.replace(' ', '').split('>>')[1].split('$')[1].split('/')[0], '')
1072+
else:
1073+
FileName = INPUT_Argument.replace(' ', '').split('>>')[1]
1074+
with open(FileName, 'a', encoding='utf-8') as text:
1075+
text.write(ArgV)
1076+
elif '>' in INPUT_Argument:
1077+
with StringIO() as St:
1078+
sys.stdout = St
1079+
INPUT_Arguments = INPUT_Argument.split('>')[0].split(' ')
1080+
concurrent.futures.ThreadPoolExecutor().submit(delelemnts, INPUT_Arguments).result()
1081+
Argument_Paser(INPUT_Arguments)
1082+
ArgV = St.getvalue()
1083+
sys.stdout = BackupSTDOUT
1084+
if '$' in INPUT_Argument.replace(' ', '').split('>')[1]:
1085+
FileName = INPUT_Argument.replace(' ', '').split('>')[1].replace('$', os.getenv(INPUT_Argument.replace(' ', '').split('>')[1].split('$')[1].split('/')[0])).replace(INPUT_Argument.replace(' ', '').split('>')[1].split('$')[1].split('/')[0], '')
1086+
else:
1087+
FileName = INPUT_Argument.replace(' ', '').split('>')[1]
1088+
with open(FileName, 'w', encoding='utf-8') as text:
1089+
text.write(ArgV)
1090+
else:
1091+
Argument_Paser(INPUT_Argument.split(' '))
10031092
except KeyboardInterrupt:
10041093
sys.exit(0)
10051094
if not is_Exits:
10061095
break
10071096

1097+
def delelemnts(element):
1098+
while True:
1099+
try:
1100+
if '' in element:
1101+
element.remove('')
1102+
else:
1103+
break
1104+
except:
1105+
break
1106+
return element
1107+
BackupSTDOUT = sys.stdout
10081108
if __name__ == '__main__':
10091109
try:
10101110
main()
10111111
except KeyboardInterrupt:
1012-
pass
1112+
pass
1113+
1114+
sys.stdout = BackupSTDOUT

0 commit comments

Comments
 (0)