1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 22:57:46 +00:00

Add helpers folder and add script for running C/C++ quickly (#241)

This commit is contained in:
Dan-Gamin 2022-06-04 01:26:19 +03:00 committed by GitHub
parent 4ab39c0d09
commit 0f9d10d78d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

13
helpers/README.md Normal file
View file

@ -0,0 +1,13 @@
# Helpers
Commands to make your life easier.
## How to use
Execute following snippet at any time to be able to run the commands in the scripts:
```zsh
source './path/to/script.nu'
```
With `./path/to/...` being the path to the script you want to utilize.

27
helpers/run-c-cpp.nu Normal file
View file

@ -0,0 +1,27 @@
# Runs C code via GCC without leaving a file behind
def rcc [
file: path # The file to run
] {
# Remove exe if still exists
rm $"($file).exe" --permanent --force
# Compile code to exe
^gcc ("." | path join $file | path expand) -o ("." | path join $"($file).exe" | path expand)
# Execute exe
^$"($file).exe"
# Remove exe
rm $"($file).exe" --permanent --force
}
# Runs C++ code via g++ without leaving a file behind
def r++ [
file: path # The file to run
] {
# Remove exe if still exists
rm $"($file).exe" --permanent --force
# Compile code to exe
^g++ ("." | path join $file | path expand) -o ("." | path join $"($file).exe" | path expand)
# Execute exe
^$"($file).exe"
# Remove exe
rm $"($file).exe" --permanent --force
}