diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index 6059a56..a11a242 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -69,4 +69,23 @@ _cdg() { _arguments "1: :($( cat $GCLONE_PATH/.cdgcache | rev | cut -d '/' -f 1 | rev))" } +cratefmt() { + local current_dir=$PWD + + # Find cargo.toml + while [ ! -f Cargo.toml ] && [ $PWD != "/" ]; do + cd .. + done + + if [ -f Cargo.toml ]; then + rustfmt --edition 2018 `find src -name "*.rs"` + else + echo -e "\033[1;31merror:\033[0m\033[1m can't find Cargo.toml\033[0m" + cd $current_dir + return 1 + fi + + cd $current_dir +} + compdef _cdg cdg