From a563bacb95d856813e36021f3eb694e62eb4c6cc Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 11 Nov 2023 20:28:29 +0000 Subject: [PATCH] Updates Rust aliases, and adds docs to readme --- .github/README.md | 55 +++++++++++++++++++++++++++++++++ config/zsh/aliases/rust.zsh | 61 +++++++++++++++++++++++++++++++++++-- 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/.github/README.md b/.github/README.md index 6fe387e..29c98e8 100644 --- a/.github/README.md +++ b/.github/README.md @@ -402,6 +402,61 @@ Alias | Description +Rust / Cargo Aliases + +> [`zsh/aliases/rust.zsh`](https://github.com/Lissy93/dotfiles/blob/master/config/zsh/aliases/rust.zsh) + +### Rust Development Aliases and Helper Functions Documentation + +#### Cargo Basic Commands + +Alias | Description +---|--- +`cr` | `cargo run` - Compiles and runs the current project +`cb` | `cargo build` - Compiles the current project +`ct` | `cargo test` - Runs tests for the current project + +#### Extended Cargo Commands + +Alias | Description +---|--- +`carc` | `cargo clean` - Removes the target directory +`caru` | `cargo update` - Updates dependencies as recorded in the local lock file +`carch` | `cargo check` - Checks the current project to see if it compiles without producing an executable +`carcl` | `cargo clippy` - Lints the project with Clippy +`card` | `cargo doc` - Builds documentation for the current project +`carbr` | `cargo build --release` - Compiles the project with optimizations +`carrr` | `cargo run --release` - Runs the project with optimizations +`carws` | `cargo workspace` - Manages workspace-level tasks +`carwsl` | `cargo workspace list` - Lists all members of the current workspace +`carad` | `cargo add` - Adds a dependency to a Cargo.toml manifest file +`carrm` | `cargo rm` - Removes a dependency from a Cargo.toml manifest file +`carp` | `cargo publish` - Packages and uploads the project to crates.io +`carau` | `cargo audit` - Audits Cargo.lock for crates with security vulnerabilities +`cargen` | `cargo generate --git` - Generates a new project from a Git repository template +`carfmt` | `cargo fmt` - Formats the code in the current project + +#### Rustup Commands + +Alias | Description +---|--- +`ru-update` | `rustup update` - Updates the Rust toolchain +`ru-default` | `rustup default` - Sets a default Rust toolchain + +#### Helper Functions and Other Aliases + +Function / Alias | Description +---|--- +`new_rust_project` | Function to create a new Rust project with the specified name +`search_crates` | Function to search crates.io for a given query +`rustdoc` | Opens the Rust documentation in the default web browser +`rustbook` | Opens 'The Rust Programming Language' book in the default web browser +`update_rust` | Updates the Rust toolchain and all installed components +`rvalgrind` | Runs Rust programs with Valgrind for memory leak analysis (if Valgrind is installed) +`clean_rust_workspace` | Cleans up the target directory in all workspaces + + +
diff --git a/config/zsh/aliases/rust.zsh b/config/zsh/aliases/rust.zsh index 80c4c97..8127bcd 100644 --- a/config/zsh/aliases/rust.zsh +++ b/config/zsh/aliases/rust.zsh @@ -1,6 +1,63 @@ +###################################################################### +# ZSH aliases and helper functions for Rust development with Cargo # +# Licensed under MIT (C) Alicia Sykes 2022 # +###################################################################### + +# Cargo Basic Commands alias cr='cargo run' alias cb='cargo build' alias ct='cargo test' -alias cc='cargo clean' -alias cu='cargo update' + +alias carc='cargo clean' +alias caru='cargo update' +alias carch='cargo check' +alias carcl='cargo clippy' +alias card='cargo doc' + +alias carbr='cargo build --release' +alias carrr='cargo run --release' +alias carws='cargo workspace' +alias carwsl='cargo workspace list' +alias carad='cargo add' +alias carrm='cargo rm' +alias carp='cargo publish' +alias carau='cargo audit' +alias cargen='cargo generate --git' +alias carfmt='cargo fmt' + +# Rustup Commands +alias ru-update='rustup update' +alias ru-default='rustup default' + +# Helper function to create a new Rust project +new_rust_project() { + cargo new $1 --bin && cd $1 +} + +# Helper function to search crates.io +search_crates() { + open "https://crates.io/search?q=$1" +} + +# Alias for opening Rust documentation +alias rustdoc='open https://doc.rust-lang.org' + +# Alias for opening The Rust Programming Language book +alias rustbook='open https://doc.rust-lang.org/book/' + +# Helper to update Rust toolchain and all installed components +update_rust() { + rustup update + rustup self update + cargo install-update -a +} + +# Alias for running Rust programs with Valgrind (if installed) +alias rvalgrind='valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes' + +# Helper to clean up target directory in all workspaces +clean_rust_workspace() { + find . -name "target" -type d -exec rm -rf {} + + echo "Cleaned target directories in Rust workspace" +}