Skip to content

CodeShady/cs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

cs - CodeShady's 42 Tool

42 Helper Script!

Setup

⚠️ First, ensure you have the following Python packages installed:

$ pip3 install c_formatter_42

To start using this tool, grab the main csverify.py file and run the program to automatically create your config.json file. By default, a csdata folder will be created and placed in your ~/Documents/csdata/ folder. These generated files are used by the program later.

Find the config.json file generated by the program and edit the variables to your preferences.

{
    "USER":  "myusername",
    "EMAIL":  "[email protected]",
}

(Optional 🤷) For quick and easy usage, create an alias in your .zshrc or .bashrc file depending on which shell you're using. Point the alias to the location of the csverifiy.py file you downloaded from this GitHub repository.

(~/.zshrc)

alias cs="python3 ~/path/to/csverify.py"

Open a new shell or run source ~/.zshrc to update the changes to your shell session.

👀 Using cs

Run cs in your terminal to get a list of cool tools you can use.

usage: csverify.py [-h] {...} ...

options:
  -h, --help            show this help message and exit
  --banner              Show the banner
  --note, -n            Access your personal notes
  --clear               Clear the screen before displaying the output
  ...

Sub-Commands:
  ...

📖 Guide

👉 C Tools

Help

Use the c mode to select "C programming mode".

$ cs c --help

C File Template (with 42 Header)

Create a new C program with the required 42 header.

$ cs c --new my_new_program.c

Compile & Run your code

Compile and run your C code with the recommended compiler flags: -Wall -Wextra -Werror

$ cs c --run my_code.c

C File Template (with 42 Header)

Compile your C code into a.out with the recommended compiler flags: -Wall -Wextra -Werror

$ cs c --compile my_code.c

Norminette Check

Check your code with the norminette

😎 Don't worry, the flag -R CheckForbiddenSourceHeader is used by default!

$ cs c --norm my_code.c

Norminette Auto Formatter

Format your C code automatically for the norminette

$ cs c --format my_code.c

Simulate Moulinette Code Grading

If you have C code that prints the correct output that has successfully passed the Moulinette, use the grade mode to check whether the output of your code matches the correct output.

Use --answer followed by a C program to specify the code previously graded by the Moulinette.

$ cs grade my_own_code.c --answer test.c

👉 Preservation & Restoration

Preserve files

Similar to what git does, you can preserve a file for whatever reason. I find myself running this before I delete valuable comments in my C code before formatting for the Norminette.

$ cs preserve my_code.c
✅ OK!

Restoring & viewing files

Once you've preserved a file or two, run the command below followed by the file you'd like to view the history of.

$ cs history my_code.c
📄 my_code.c (2023/09/14 09:57:05) [f7d468b...]
📄 my_code.c (2023/09/14 10:20:59) [3a30f16...]

To view the latest version of a preserved file, use --latest or -l

$ cs history my_code.c --latest

Use --pretty or -p to pretty-print your code 💃

$ cs history my_code.c --latest --pretty

To view the specific version of a preserved file, use --hash or -s (hash)

⚠️ You don't have to type the whole hash, just the first few characters works!

$ cs history my_code.c --hash f7d
...
$ cs history my_code.c --hash f7d468b

😎 Pro tip! Use the command below to save a specific version of your file into a new file so you can make changes to it again!

$ cs history my_code_v1.c --latest > my_code_v2.c

👉 Git

Add, commit, push (all-in-one)

The tool below adds all changed files, commits them, and then pushes them to your git repository.

$ cs git --push

Just Commit

To add all changed files and commit them automatically without pushing to your repository, use the following:

$ cs git --commit

Log

Log your git history

$ cs git --log