Skip to content

Commit

Permalink
fix: renaming files before replacing doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
krsche committed Apr 21, 2022
1 parent 17c53e4 commit 9933818
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ CURRENT_NAME=`find $ABS -maxdepth 1 -name *.kicad_pro -exec basename {} \; | cut
NEW_NAME=${1:-$FOLDER}

# Determine what to do
FILES_TO_RENAME=`find $ABS -maxdepth 1 -name "$CURRENT_NAME.*"`
echo -e "Files to rename: \n$FILES_TO_RENAME"

FILES_FOR_TEXT_REPLACE_WITH_CODE=`grep -IRH --exclude-dir=.git --exclude-dir=kicad-library --exclude=README.md "$CURRENT_NAME" $ABS`
echo
echo -e "Replacing '$CURRENT_NAME' --> '$NEW_NAME' in files: \n$FILES_FOR_TEXT_REPLACE_WITH_CODE"

FILES_TO_RENAME=`find $ABS -maxdepth 1 -name "$CURRENT_NAME.*"`
echo
echo -e "Files to rename: \n$FILES_TO_RENAME"

# Ask permission
echo
read -p "Updating name to '$NEW_NAME'. Continue? [Y/n]: " -r
Expand All @@ -27,14 +27,14 @@ else
fi

# Do It!
# Rename files
for file in $FILES_TO_RENAME; do
FILE_EXTENTION=${file##*.}
mv $file $ABS/$NEW_NAME.$FILE_EXTENTION
done

# Replace text in files
while IFS= read -r line; do
file=`echo $line | cut -f1 -d ':'`
sed -i "s/$CURRENT_NAME/$NEW_NAME/g" $file
done <<< "$FILES_FOR_TEXT_REPLACE_WITH_CODE"

# Rename files
for file in $FILES_TO_RENAME; do
FILE_EXTENTION=${file##*.}
mv $file $ABS/$NEW_NAME.$FILE_EXTENTION
done

0 comments on commit 9933818

Please sign in to comment.