From d666330b677a794c1107b08139e4a1eb5eb86f41 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Sat, 18 May 2019 13:00:05 +0200 Subject: [PATCH] cratefmt alias --- zsh/aliases.zsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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