Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rename script #544

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions rename.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

#
# ./rename.sh 'Your_Plugin_Name'
# github.com/tarkusdev
# not liable for this
#

(( $# < 1 )) && echo "Usage: ./rename.sh 'Your_Plugin_Name'" && exit 1
[[ ! -d 'plugin-name' ]] && echo "Missing 'plugin-name' directory." && exit 1

plugin_name="${@//[- ]/_}" # Replace hyphens and spaces with underscores
lowercase="${plugin_name,,}"
uppercase="${plugin_name^^}"
hyphenated="${lowercase//_/-}"

for f in $(find . -type f -not -name 'class-plugin-name.php' -not -path '*/\.*')
do
# Replace plugin-name text to user input
sed -i \
-e "s/plugin-name/$hyphenated/g" \
-e "s/plugin_name/$lowercase/g" \
-e "s/Plugin_Name/$plugin_name/g" \
-e "s/PLUGIN_NAME_/${uppercase}_/g" \
"$f"

# Rename files from plugin-name to user input
n="${f/#*\//}" # Get filename from file path
n="${n//plugin-name/$hyphenated}" # Replace plugin-name with user input

# Skip the files that do not need to be renamed
[[ "$n" == *"$hyphenated"* ]] && mv "$f" "${f%/*}/$n"
done

mv ./plugin-name "./$hyphenated"