Skip to content

Instantly share code, notes, and snippets.

@mrrbrilliant
Last active February 8, 2023 14:17
Show Gist options
  • Save mrrbrilliant/9525555874a5fc2f5ce90a4947a1ccbb to your computer and use it in GitHub Desktop.
Save mrrbrilliant/9525555874a5fc2f5ce90a4947a1ccbb to your computer and use it in GitHub Desktop.
Bash aliases for working with Rust.
# Basic Rust
alias cgi='cargo init'
alias cgn='cargo new --bin'
alias cgnl='cargo new --lib'
alias cgr='cargo run'
alias cgre='cargo run --example'
alias cgc='cargo clean'
alias cgb='cargo build'
alias cgbr='cargo build --release'
# Running workspace member
alias cgrb='cargo run --bin'
alias cgrrb='cargo run --release --bin'
# Builing workspace member
alias cgbb='cargo build --bin'
alias cgbrb='cargo build --release --bin'
# Create new Cargo workspace with pre-defined members
function cgwn() {
if [[ -f $(pwd)/Cargo.toml ]]; then
echo -e "Cargo.toml existed.\nPlease make sure you running this in a clean directory.\nAborting..."
else
echo -e "Please list your members using the format below.\n"
echo -e "Format: [member_name]:[project_type]\n"
echo -e "bin_project_name:bin lib_project_name:lib\n"
read mems;
members=($mems)
echo -e '[workspace]' >> Cargo.toml
echo -e 'members = [' >> Cargo.toml
for((i=0;i<${#members[@]};i++)){
info=(${members[$i]//:/ })
if [[ i -eq $((${#members[@]} - 1)) ]]; then
echo -e "\t\"${info[0]}\"" >> Cargo.toml
else
echo -e "\t\"${info[0]}\", " >> Cargo.toml
fi
}
echo -e ']' >> Cargo.toml
for((i=0;i<${#members[@]};i++)){
info=(${members[$i]//:/ })
cargo new "--${info[1]}" "${info[0]}"
}
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment