1+ import os , animation , termcolor
2+ import socket
3+ from rich import print
4+ from rich .console import Console
5+ import time
6+ import datetime
7+ from colorama import Fore
8+ from rich .table import Table
9+ from rich .syntax import Syntax
10+
11+ console = Console ()
12+ commands = ["touch" , "mkdir" , "ls" , "cat" ]
13+ path = os .getcwd ()
14+ name = socket .gethostname ()
15+ user = os .getlogin ()
16+ path = path .replace ("\\ " , "/" )
17+ path = path .removeprefix ("C:/Users/DEBARKA NASKAR/" )
18+ now = datetime .datetime .now ()
19+ day = now .strftime ("%d" )
20+ month = now .strftime ("%m" )
21+ year = now .strftime ("%Y" )
22+ date = day + "-" + month + "-" + year
23+ time = datetime .datetime .now ().strftime ("%H:%M" )
24+ animation .animate ()
25+ while True :
26+ console .print (f"[bold][chartreuse1]{ user } @{ name } [/] [magenta2]UNIX[/] [gold1]~{ '/' + path } [/]\n $[/]" , end = '' )
27+ command = input (" " )
28+ if command .startswith ("touch" ):
29+ file = command .split ()
30+ try :
31+ with open (file [1 ], "w" ) as f :
32+ f .write ("" )
33+ length = os .stat (file [1 ]).st_size
34+ table = Table (title = f"Directory: { os .getcwd ()} " )
35+ table .add_column ("Mode" , style = "chartreuse1" )
36+ table .add_column ("LastWriteTime" , style = "light_green" )
37+ table .add_column ("Length" , style = "aquamarine1" )
38+ table .add_column ("Name" , style = "dark_slate_gray1" )
39+ table .add_row ("-a----" , f"{ str (date )} \t { str (time )} " , str (length ), file [1 ])
40+ console .print (table )
41+ except IndexError :
42+ print (f"{ file [0 ]} : missing file operand" )
43+ if command .startswith ("mkdir" ):
44+ file = command .split ()
45+ nPath = os .path .join (os .getcwd (), file [1 ])
46+ os .mkdir (nPath )
47+ name = file [1 ]
48+ table = Table (title = f"Directory: { os .getcwd ()} " )
49+ table .add_column ("Mode" , style = "chartreuse1" )
50+ table .add_column ("LastWriteTime" , style = "light_green" )
51+ table .add_column ("Length" , style = "aquamarine1" )
52+ table .add_column ("Name" , style = "dark_slate_gray1" )
53+ table .add_row ("-a----" , f"{ str (date )} \t { str (time )} " , "" , file [1 ])
54+ console .print (table )
55+
56+ if command == commands [2 ]:
57+ listDir = os .listdir ()
58+ for i in listDir :
59+ ifDir = os .path .isdir (i )
60+ if ifDir :
61+ index = listDir .index (i )
62+ listDir [index ] = termcolor .colored (f"{ listDir [index ]} /" , "green" )
63+ else : console .print ("unix: mkdir: file doesn't exist" )
64+ print (' ' .join (listDir ))
65+
66+ if command .startswith ("cat" ):
67+ file = command .split ()
68+ with open (file [1 ], "r" ) as f :
69+ syntax = Syntax .from_path (file [1 ], line_numbers = True )
70+ console .print (syntax )
71+
72+ if command .startswith ("cp" ):
73+ file = command .split ()
74+ length = file .__len__ ()
75+ if length == 1 : console .print ("[magenta2]unix: [gold1]cp: missing file operand" )
76+ if length == 2 : console .print ("[magenta2]unix: [gold1]cp: missing file to copy content" )
77+ else :
78+ with open (file [1 ], "r" ) as f :
79+ content = f .read ()
80+ with open (file [2 ], 'a' ) as q :
81+ q .write (f"\n { content } " )
82+
83+ if command .startswith ("del" ):
84+ file = command .split ()
85+ length = file .__len__ ()
86+ if length == 1 : console .print ("[magenta2]unix: [gold1]del: missing file operand" )
87+ else : os .remove (file [1 ])
88+
89+ if command .startswith ('mv' ):
90+ file = command .split ()
91+ length = file .__len__ ()
92+ if length == 1 : console .print ("[magenta2]unix: [gold1]mv: missing file operand" )
93+ if length == 2 : console .print ("[magenta2]unix: [gold1]mv: missing file to move content" )
94+ else :
95+ try :
96+ with open (file [1 ], "r" ) as f :
97+ content = f .read ()
98+ with open (file [2 ], 'a' ) as q :
99+ q .write (f"\n { content } " )
100+ os .remove (file [1 ])
101+ except : ...
0 commit comments