Skip to content

Creating Your Own Shell Commands

Mohamed Dief edited this page Feb 2, 2021 · 1 revision

Creating Your Own Shell Commands

  • EasyShell Allows You To Add Your Own Commands And Scripts Into The Shell. So You Can Execute It And Pass User Inputs To It With an Easy Way. Instead Of Running Your Python Scripts With Long Commands. You Can Link Your Python Script Into EasyShell Them Execute It Every Time With a Single Command.

Let's Create a Script To base64 Encode User Inputs.

  • The Basics Of Creating a Shell Command Is Based On Creating a Python Script With The Main Function On It Named Run() And Takes On Argument That's The User Input. Then You Can Whatever You Want On The Code. Even Outside It. While Importing The Code. Every Code Outside The Run Function Is Executed Too. Let's Start With The Basic Stuff:
# filename="base-encoder.py"
import base64

def Run(Input):
    BInput = Input.encode('UTF-8')
    Encoded = base64.b64encode(BInput)

    Encoded = Encoded.decode('UTF-8')
    print("Base64:" , Encoded)
  • Now, To Link This Script We Should Put It Into scripts Folder. Then We Should Go To data/Commands.easy And Add a New Line. We Should Add Some Content With This Format Command="script-name-without-dot-py". Our Script Name, In This Case, Is base-encoder.py So We Will Add This Line.
base64="base-encoder"
  • Then Comming Back To Our Shell. We Will Run EasyShell With python3 shell.py Then We Will Write That On The Shell base64 - something. And The Output Will Be Base64: c29tZXRoaW5n. Really Easy.