This Bash script provides a convenient way to compile, run, and optionally delete a Rust executable. It supports various options, including running in a temporary directory, watching for file changes, sending desktop notifications, and installing the script to the user's local ~/bin directory.
The script compiles and runs a given Rust file. If the compilation and execution are successful, it deletes the generated executable.
Example:
./compile_and_run_rust.sh intro2.rsThe -t or --temp option allows the script to compile and run the Rust file in a temporary directory. This is useful to avoid cluttering your working directory with executables.
Example:
./compile_and_run_rust.sh -t intro2.rsThe -w or --watch option enables a watch mode. In this mode, the script monitors the specified Rust file for changes. If the file is modified, the script will re-compile, run, and optionally delete the executable. The script uses inotifywait for efficient file monitoring, and falls back to sleep and checksum if inotifywait is not available.
Example:
./compile_and_run_rust.sh -w intro2.rsThe -n or --notify option enables desktop notifications. A notification with low urgency is sent upon successful compilation, and a notification with critical urgency is sent upon compilation failure.
Example:
./compile_and_run_rust.sh -n intro2.rsThe --install option installs the script to the ~/bin directory. If ~/bin is not in your PATH, the script provides instructions to add it.
Example:
./compile_and_run_rust.sh --installThe -h or --help option displays a help text that explains how to use the script and its options. The help text is colorized for better readability.
Example:
./compile_and_run_rust.sh -hYou can pipe a Rust file into the script. This is useful when you want to quickly run a Rust file without specifying its name.
Example:
cat intro2.rs | ./compile_and_run_rust.shHere's the full script:
See compile_and_run_rust.sh file.
curl -O https://gist.githubusercontent.com/abhisekp/c4625eb8f324991957520c8a7c1e15cb/raw/497cca2d7bc310821bccc55e86880369f7013648/compile_and_run_rust.sh && chmod +x compile_and_run_rust.sh && ./compile_and_run_rust.sh
- Bash
inotifywaitfor watch mode (optional)notify-sendfor notifications (optional)
- Save the script into a file, for example,
compile_and_run_rust.sh. - Make the script executable:
chmod +x compile_and_run_rust.sh.
Run the script with the desired options and the Rust file as an argument. For example, to compile, run, and clean intro2.rs in a temporary directory while watching for changes and sending notifications:
./compile_and_run_rust.sh -t -w -n intro2.rs