Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import os import getpass class GlobalPath: SELF_PATH = __file__[:__file__.rfind('\\')] visible_path = '' def ls(path: str = 'DEFAULT') -> str: if path != 'DEFAULT': files = os.listdir(path) else: files = os.listdir(GlobalPath.SELF_PATH) res = '' for offset, file in enumerate(files): res += file + '\t' if offset % 6 == 0 and offset != 0: res += '\n' return res def cat(*files) -> str: res = '' for file in files: with open(file=f'{GlobalPath.SELF_PATH}\\{file}', mode='r', encoding='utf-8') as f: for line in f: res += line return res def pwd() -> str: return GlobalPath.SELF_PATH def cd(path: str): if path == '..': GlobalPath.SELF_PATH = generate_new_path(GlobalPath.SELF_PATH) path = generate_new_path(GlobalPath.visible_path).replace('\\\\', '') GlobalPath.visible_path = path else: if os.path.exists(GlobalPath.SELF_PATH + f'\\{path}'): GlobalPath.SELF_PATH += f'\\{path}' GlobalPath.visible_path += f'\\{path}' def convert_path_to_list(visible_path: str) -> list: return visible_path.split('\\') def generate_new_path(path): tmp = convert_path_to_list(path) tmp.pop() path = '' for offset, file in enumerate(tmp): if offset != 0: path += f'\\{file}' else: path += f'{file}' return path def run(): commands = { 'ls': ls, 'cat': cat, 'pwd': pwd, 'cd': cd, } while True: user_name = f'{getpass.getuser()}@ubuntu:{GlobalPath.visible_path if GlobalPath.visible_path else "~"}$ ' enter_command = input(user_name).split(' ') command, args = enter_command[0], enter_command[1:] if not commands.get(command): continue try: res = commands[command](*args) except Exception as e: print(e) continue if res: print(res) if __name__ == '__main__': run()
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)