From dac93c7e7c046beffa048d5775774f0a33b3b660 Mon Sep 17 00:00:00 2001 From: jadedctrl Date: Tue, 28 Mar 2017 07:09:23 -0500 Subject: [PATCH] Basic move support --- move.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/move.sh b/move.sh index cd39b37..eee4ede 100644 --- a/move.sh +++ b/move.sh @@ -7,5 +7,54 @@ # Desc: Move your bloody pieces! ##################### -file=$1 +na=0 +algebraic_notation=0 +force=0 +for argument in $@ +do + case $argument in + -a) + na=1 + algebraic_notation=1 + ;; + -f) + force=1 + ;; + *) + if [ $na -eq 1 ] + then + move=$argument + na=0 + else + if echo $argument | grep "," > /dev/null + then + algebraic_notation=0 + move=$argument + else + file=$argument + fi + fi + ;; + esac +done + +if [ $algebraic_notation -eq 0 ] +then + origin=$(echo $move | awk -F\- '{print $1}') + dest=$(echo $move | awk -F\- '{print $2}') + if grep $origin $file > /dev/null + then + if [ $force -eq 1 ] + then + sed 's/'"$origin"'/'"$dest"'/' $file > $file.new + mv $file.new $file + else + sed 's/'"$dest"'/0,0/g' $file > $file.new + mv $file.new $file + fi + else + echo moving + sed 's/'"$origin"'/'"$dest"'/' $file > $file.new + fi +fi