2
2
3
3
"""Pythonista3 Console Terminal"""
4
4
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
6
6
from console import set_color as setColor
7
7
from lib2to3 .main import main as _2to3_main
8
8
from io import BytesIO
9
9
from platform import python_version
10
10
from platform import node as hostname
11
11
from urllib .error import URLError
12
+ from io import StringIO
12
13
13
14
ssl ._create_default_https_context = ssl ._create_unverified_context
14
15
@@ -39,7 +40,7 @@ def __init__():
39
40
def SystemLogo ():
40
41
clear ()
41
42
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 )
43
44
44
45
def Argument_Paser (Args ):
45
46
setColor ()
@@ -53,6 +54,10 @@ def Argument_Paser(Args):
53
54
print ("Usage: cp [-h] source [source ...] dest" )
54
55
if Args [1 ] == '-h' and Args [0 ] == 'echo' :
55
56
print ("Usage: echo [-h]\n \n Print 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' )
56
61
if Args [1 ] == '-h' and Args [0 ] == 'git' :
57
62
print ('Usage: git clone <url> [path] - clone a remote repository' )
58
63
if Args [1 ] == '-h' and Args [0 ] == 'la' :
@@ -83,7 +88,7 @@ def Argument_Paser(Args):
83
88
pass
84
89
try :
85
90
if Args [0 ] == 'help' :
86
- print ('[Default commands]:\n help, 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]:\n help, 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 ())
87
92
elif Args [0 ] == 'cat' :
88
93
try :
89
94
if not Args [1 ] == '-h' :
@@ -95,8 +100,34 @@ def Argument_Paser(Args):
95
100
_2to3 (Args [1 :])
96
101
except :
97
102
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
98
126
elif Args [0 ] == 'cd' :
99
127
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 ], '' )
100
131
if not Args [1 ] == '-h' :
101
132
try :
102
133
try :
@@ -155,9 +186,9 @@ def Argument_Paser(Args):
155
186
except IndexError :
156
187
try :
157
188
if not Args [1 ] == '' :
158
- print ( Args [ 1 ])
189
+ pass
159
190
except IndexError :
160
- print ()
191
+ pass
161
192
except :
162
193
pass
163
194
elif Args [0 ] == 'env' :
@@ -193,7 +224,8 @@ def Argument_Paser(Args):
193
224
listdir ('long' , os .getcwd ())
194
225
except IndexError :
195
226
listdir (None , None )
196
- except :
227
+ except Exception as R :
228
+ print (R )
197
229
pass
198
230
elif Args [0 ] == 'ln' :
199
231
try :
@@ -288,6 +320,9 @@ def Argument_Paser(Args):
288
320
pass
289
321
elif Args [0 ] == 'rm' :
290
322
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 ], '' )
291
326
if not Args [1 ] == '-h' :
292
327
if Args [1 ][0 :] == './' :
293
328
try :
@@ -328,7 +363,7 @@ def Argument_Paser(Args):
328
363
file_path = Args [1 ]
329
364
py_file = open (file_path , 'r' , encoding = 'utf-8' ).read ()
330
365
try :
331
- exec (py_file )
366
+ exec (py_file , globals () )
332
367
except SystemExit :
333
368
pass
334
369
except :
@@ -338,6 +373,11 @@ def Argument_Paser(Args):
338
373
code .interact ()
339
374
except SystemExit :
340
375
pass
376
+ except IndexError :
377
+ try :
378
+ code .interact ()
379
+ except SystemExit :
380
+ pass
341
381
except :
342
382
pass
343
383
elif Args [0 ] == 'python3' :
@@ -350,14 +390,19 @@ def Argument_Paser(Args):
350
390
file_path = Args [1 ]
351
391
py_file = open (file_path , 'r' , encoding = 'utf-8' ).read ()
352
392
try :
353
- exec (py_file )
393
+ exec (py_file , globals () )
354
394
except :
355
395
pass
356
396
except :
357
397
try :
358
398
code .interact ()
359
399
except SystemExit :
360
400
pass
401
+ except IndexError :
402
+ try :
403
+ code .interact ()
404
+ except SystemExit :
405
+ pass
361
406
except :
362
407
pass
363
408
elif Args [0 ] == 'wget' :
@@ -697,10 +742,16 @@ def listdir(arg, pwd):
697
742
len_dir_lists = len (listdirs )
698
743
for lis in range (len_dir_lists ):
699
744
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
701
749
setColor ()
702
750
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
704
755
setColor ()
705
756
elif arg == None :
706
757
try :
@@ -975,6 +1026,7 @@ def ZipArchiveCreate(ziPFilename, IPath):
975
1026
ARCHIVE_NAME = os .path .join (TH_RELROOT , _Fi )
976
1027
OutPutsZip .write (Fi_Name , arcname = ARCHIVE_NAME )
977
1028
1029
+ @ui .in_background
978
1030
def main ():
979
1031
__init__ ()
980
1032
print (SystemLogo ())
@@ -998,15 +1050,65 @@ def main():
998
1050
sys .exit (0 )
999
1051
print (Command_DIRNAME [2 ], end = '' , flush = True )
1000
1052
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 (' ' ))
1003
1092
except KeyboardInterrupt :
1004
1093
sys .exit (0 )
1005
1094
if not is_Exits :
1006
1095
break
1007
1096
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
1008
1108
if __name__ == '__main__' :
1009
1109
try :
1010
1110
main ()
1011
1111
except KeyboardInterrupt :
1012
- pass
1112
+ pass
1113
+
1114
+ sys .stdout = BackupSTDOUT
0 commit comments